From 3707a8dce232a757109a0535071518409d32b232 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Mon, 12 Jun 2017 15:46:53 +0300 Subject: [PATCH] Now can change forum data --- BL/Factories/FoorumFactory.cs | 9 +++++++++ BL/Interfaces/IFoorumService.cs | 2 +- BL/Services/FoorumService.cs | 8 ++++++-- WebApi/Controllers/FoorumController.cs | 4 +++- WebApi/index.html | 16 ++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/BL/Factories/FoorumFactory.cs b/BL/Factories/FoorumFactory.cs index eaab66a..acbbd98 100644 --- a/BL/Factories/FoorumFactory.cs +++ b/BL/Factories/FoorumFactory.cs @@ -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; + } } } diff --git a/BL/Interfaces/IFoorumService.cs b/BL/Interfaces/IFoorumService.cs index afa71c2..3f06df6 100644 --- a/BL/Interfaces/IFoorumService.cs +++ b/BL/Interfaces/IFoorumService.cs @@ -12,7 +12,7 @@ namespace BL.Interfaces IEnumerable 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); diff --git a/BL/Services/FoorumService.cs b/BL/Services/FoorumService.cs index cb0e74f..dd5a60e 100644 --- a/BL/Services/FoorumService.cs +++ b/BL/Services/FoorumService.cs @@ -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); } } } diff --git a/WebApi/Controllers/FoorumController.cs b/WebApi/Controllers/FoorumController.cs index 2686db3..44c5316 100644 --- a/WebApi/Controllers/FoorumController.cs +++ b/WebApi/Controllers/FoorumController.cs @@ -51,8 +51,10 @@ namespace WebApi.Controllers } // PUT api//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//5 diff --git a/WebApi/index.html b/WebApi/index.html index f54eafd..8b1cd7c 100644 --- a/WebApi/index.html +++ b/WebApi/index.html @@ -4,6 +4,8 @@ + +
@@ -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();