示例#1
0
        public EntityResult CreateAttachment(int topicId, int userId, AttatchmentFormModel model)
        {
            try
            {
                DbContext.Topics.Include(t => t.TopicUsers).Single(t => t.Id == topicId);
            }
            catch (InvalidOperationException)
            {
                return(EntityResult.Error("Unknown Topic"));
            }

            try
            {
                var attatchment = new TopicAttatchment(model)
                {
                    UserId  = userId,
                    TopicId = topicId,
                    Type    = "TODO"
                };

                DbContext.TopicAttatchments.Add(attatchment);
                DbContext.SaveChanges();

                return(EntityResult.Successfull(attatchment.Id));
            }
            catch (Exception e)
            {
                return(EntityResult.Error(e.Message));
            }
        }
 public TopicAttachmentResult(TopicAttatchment att)
 {
     Id          = att.Id;
     Name        = att.Name;
     Description = att.Description;
     if (att.Legal != null)
     {
         Legal = new LegalResult(att.Legal);
     }
     Type = att.Type;
     if (att.User != null)
     {
         User = new UserResult(att.User);
     }
     CreatedAt = att.UpdatedAt;
 }