Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 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));
     }
 }
Ejemplo n.º 4
0
        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);
            }
        }