Now can change forum data

This commit is contained in:
Arti Zirk 2017-06-12 15:46:53 +03:00
parent 44c733b582
commit 3707a8dce2
5 changed files with 35 additions and 4 deletions

View File

@ -42,5 +42,14 @@ namespace BL.Factories
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;
}
}
}

View File

@ -12,7 +12,7 @@ namespace BL.Interfaces
IEnumerable<FoorumDTO> GetAll();
FoorumDTO Get(int id);
FoorumDTO Add(FoorumDTO foorum);
void Update(FoorumDTO foorum);
FoorumDTO Update(FoorumDTO foorum);
void Hide(int id);
void Delete(int id);
void AddPost(int id, PostDTO post);

View File

@ -72,9 +72,13 @@ namespace BL.Services
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);
}
}
}

View File

@ -51,8 +51,10 @@ namespace WebApi.Controllers
}
// 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

View File

@ -4,6 +4,8 @@
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
<button onclick="getForums()">GetAllForums</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>
<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) {
fetch("/api/search?author="+author).then(resp => {
return resp.json();