Now can change forum data
This commit is contained in:
parent
44c733b582
commit
3707a8dce2
@ -42,5 +42,14 @@ namespace BL.Factories
|
|||||||
Title = f.Title
|
Title = f.Title
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Foorum Update(Foorum domain, FoorumDTO dto)
|
||||||
|
{
|
||||||
|
|
||||||
|
domain.Title = dto.Title ?? domain.Title;
|
||||||
|
domain.Body = dto.Body ?? domain.Body;
|
||||||
|
domain.Description = dto.Description ?? domain.Description;
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ namespace BL.Interfaces
|
|||||||
IEnumerable<FoorumDTO> GetAll();
|
IEnumerable<FoorumDTO> GetAll();
|
||||||
FoorumDTO Get(int id);
|
FoorumDTO Get(int id);
|
||||||
FoorumDTO Add(FoorumDTO foorum);
|
FoorumDTO Add(FoorumDTO foorum);
|
||||||
void Update(FoorumDTO foorum);
|
FoorumDTO Update(FoorumDTO foorum);
|
||||||
void Hide(int id);
|
void Hide(int id);
|
||||||
void Delete(int id);
|
void Delete(int id);
|
||||||
void AddPost(int id, PostDTO post);
|
void AddPost(int id, PostDTO post);
|
||||||
|
@ -72,9 +72,13 @@ namespace BL.Services
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(FoorumDTO foorum)
|
public FoorumDTO Update(FoorumDTO foorum)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var domain = _foorumRepository.GetById(foorum.FoorumId);
|
||||||
|
domain = _factory.Update(domain, foorum);
|
||||||
|
_foorumRepository.Update(domain);
|
||||||
|
_foorumRepository.SaveChanges();
|
||||||
|
return _factory.Create(domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,10 @@ namespace WebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
public void Put(int id, [FromBody]string value)
|
public IHttpActionResult Put(int id, [FromBody]FoorumDTO foorum)
|
||||||
{
|
{
|
||||||
|
foorum.FoorumId = id;
|
||||||
|
return Ok(_foorumService.Update(foorum));
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
|
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
|
||||||
<button onclick="getForums()">GetAllForums</button>
|
<button onclick="getForums()">GetAllForums</button>
|
||||||
<button onclick="addForum()">AddForum</button>
|
<button onclick="addForum()">AddForum</button>
|
||||||
|
<button onclick="changeForumTitle(prompt('ForumId: ', '1'), prompt('ForumTitle: ', 'Muudetud'))">ChangeForumTitle</button>
|
||||||
|
<br/>
|
||||||
<button onclick="searchForumAuthor(prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
|
<button onclick="searchForumAuthor(prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
|
||||||
<code><pre id="output"></pre></code>
|
<code><pre id="output"></pre></code>
|
||||||
|
|
||||||
@ -45,6 +47,20 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeForumTitle(id, title) {
|
||||||
|
var dto = {
|
||||||
|
Title: title
|
||||||
|
}
|
||||||
|
fetch("/api/foorum/"+id,
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dto)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function searchForumAuthor(author) {
|
function searchForumAuthor(author) {
|
||||||
fetch("/api/search?author="+author).then(resp => {
|
fetch("/api/search?author="+author).then(resp => {
|
||||||
return resp.json();
|
return resp.json();
|
||||||
|
Loading…
Reference in New Issue
Block a user