public IHttpActionResult PostTopic([FromBody] PostTopic topic) { var currentUserId = User.Identity.GetId(); var insertedTopic = topicLogic.InsertOrUpdateTopic(topic, currentUserId); return(Created(location: $"api/topics/{insertedTopic.TopicId}", content: insertedTopic)); }
public void UpdateFields(PostTopic updatedTopic) { Name = updatedTopic.Name; Description = updatedTopic.Description; ParentTopicId = updatedTopic.ParentTopicId; ChangeByUserId = updatedTopic.ChangeByUserId.Value; // Can never be null at this point }
public Topic InsertTopic(PostTopic topic) { using (var db = new DbContext()) { var insertedId = (int)db.Connection.Insert(topic); return(SelectById(insertedId)); } }
public Topic InsertOrUpdateTopic(PostTopic topic, int changeByUserId, int?topicId = null) { topic.ChangeByUserId = changeByUserId; if (topicId == null) { return(topicsDao.InsertTopic(topic)); } var topicToUpdate = topicsDao.SelectById(topicId.Value); if (topicToUpdate == null) { return(topicsDao.InsertTopic(topic)); } else { topicToUpdate.UpdateFields(topic); topicsDao.UpdateTopic(topicToUpdate); return(topicToUpdate); } }