diff --git a/BL/BL.csproj b/BL/BL.csproj index 04bce3d..e5ce51e 100644 --- a/BL/BL.csproj +++ b/BL/BL.csproj @@ -40,7 +40,6 @@ - diff --git a/BL/Class1.cs b/BL/Class1.cs deleted file mode 100644 index 2b9e1f9..0000000 --- a/BL/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BL -{ - public class Class1 - { - } -} diff --git a/BL/DTOs/FoorumDTO.cs b/BL/DTOs/FoorumDTO.cs index 19307df..5022ad4 100644 --- a/BL/DTOs/FoorumDTO.cs +++ b/BL/DTOs/FoorumDTO.cs @@ -10,6 +10,13 @@ namespace BL.DTOs { public int FoorumId { get; set; } public string Title { get; set; } + public string Description { get; set; } + public string Body { get; set; } + public DateTime CreationTime { get; set; } + public string Author { get; set; } + public bool Visible { get; set; } + + public List Posts { get; set; } } } diff --git a/BL/Interfaces/IFoorumService.cs b/BL/Interfaces/IFoorumService.cs index d13dbc1..afa71c2 100644 --- a/BL/Interfaces/IFoorumService.cs +++ b/BL/Interfaces/IFoorumService.cs @@ -11,7 +11,7 @@ namespace BL.Interfaces { IEnumerable GetAll(); FoorumDTO Get(int id); - void Add(FoorumDTO foorum); + FoorumDTO Add(FoorumDTO foorum); void Update(FoorumDTO foorum); void Hide(int id); void Delete(int id); diff --git a/BL/Services/FoorumService.cs b/BL/Services/FoorumService.cs index b62a85b..364c62e 100644 --- a/BL/Services/FoorumService.cs +++ b/BL/Services/FoorumService.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using BL.DTOs; using BL.Interfaces; +using DAL.Domain; using DAL.Interfaces; namespace BL.Services @@ -16,9 +18,27 @@ namespace BL.Services { _foorumRepository = foorumRepository; } - public void Add(FoorumDTO foorum) + public FoorumDTO Add(FoorumDTO foorum) { - throw new NotImplementedException(); + var foorumDomain = new Foorum() + { + Author = foorum.Author, + Body = foorum.Body, + CreationTime = DateTime.Now, + Description = foorum.Description, + Title = foorum.Title + }; + var f = _foorumRepository.Add(foorumDomain); + return new FoorumDTO() + { + FoorumId = f.FoorumId, + Title = f.Title, + Author = f.Author, + Body = f.Body, + CreationTime = f.CreationTime, + Description = f.Description, + Visible = f.Visible + }; } public void AddPost(int id, PostDTO post) @@ -43,7 +63,12 @@ namespace BL.Services yield return new FoorumDTO() { FoorumId = f.FoorumId, - Title = f.Title + Title = f.Title, + Author = f.Author, + Body = f.Body, + CreationTime = f.CreationTime, + Description = f.Description, + Visible = f.Visible }; } diff --git a/WebApi/App_Start/WebApiConfig.cs b/WebApi/App_Start/WebApiConfig.cs index d937c7f..b988e8f 100644 --- a/WebApi/App_Start/WebApiConfig.cs +++ b/WebApi/App_Start/WebApiConfig.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -42,8 +43,11 @@ namespace WebApi defaults: new { id = RouteParameter.Optional } ); + // Dont include properties with null values + config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; + // Force always json response - var jsonFormatter = new JsonMediaTypeFormatter(); + //var jsonFormatter = new JsonMediaTypeFormatter(); //optional: set serializer settings here //config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter)); } diff --git a/WebApi/Controllers/FoorumController.cs b/WebApi/Controllers/FoorumController.cs index 3ce5bb5..514bd73 100644 --- a/WebApi/Controllers/FoorumController.cs +++ b/WebApi/Controllers/FoorumController.cs @@ -29,8 +29,19 @@ namespace WebApi.Controllers } // POST api/ - public void Post([FromBody]string value) + public IHttpActionResult Post([FromBody]FoorumDTO foorum) { + if (foorum == null) + { + return BadRequest(); + } + + var ret = _foorumService.Add(foorum); + if (ret != null) + { + return CreatedAtRoute("DefaultApi", new {controller = "Foorum", id = ret.FoorumId}, ret); + } + return BadRequest(); } // PUT api//5 diff --git a/WebApi/index.html b/WebApi/index.html index 3f49133..5e879ae 100644 --- a/WebApi/index.html +++ b/WebApi/index.html @@ -1,11 +1,13 @@

api

foorum - + +
\ No newline at end of file