public JsonResult CreateTopic([FromBody] TopicRequestModel request) { using (ApplicationContext db = new ApplicationContext()) { var NewTopic = request as Topic; db.Topics.Add(NewTopic); db.SaveChanges(); return(new JsonResult(new { ID = NewTopic.Id })); } }
public IHttpActionResult Post(TopicRequestModel model) { if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var topic = this.mapper.Map <Topic>(model); topic.AuthorId = User.Identity.GetUserId(); topic.WordsCount = 0; var added = this.unitOfWork.Topics.Insert(topic); this.unitOfWork.Commit(); return(Ok(this.mapper.Map <DetailsTopicResponseModel>(added))); }