public EntityResult CreateAttachment(int topicId, string identity, AttachmentFormModel model) { if (!DbContext.Topics.Include(t => t.TopicUsers).Any(t => t.Id == topicId)) { return(EntityResult.Error("Unknown Topic")); } try { var user = GetUserByIdentity(identity); var attatchment = new TopicAttachment(model) { UserId = user.Id, TopicId = topicId, Type = "TODO" }; DbContext.TopicAttachments.Add(attatchment); DbContext.SaveChanges(); return(EntityResult.Successfull(attatchment.Id)); } catch (Exception e) { return(EntityResult.Error(e.Message)); } }
public TopicAttachmentResult(TopicAttachment att) { Id = att.Id; Title = att.Title; if (att.Metadata != null) { Metadata = new Metadata(att.Metadata); } Type = att.Type; if (att.User != null) { User = new UserResult(att.User); } CreatedAt = att.UpdatedAt; }
public TopicsControllerAttachmentsTest() { _tester = new ControllerTester <TopicsController>(); TopicAttachment = new TopicAttachment { Id = 1, Title = "Dom", TopicId = _tester.TopicOne.Id, Path = "C:\\Source" }; AttachmentFormModel = new AttachmentFormModel { Title = "Dom" }; }
public TopicsControllerMetadataTest() { _tester = new ControllerTester <TopicsController>(); TopicAttachment = new TopicAttachment { Id = 1, Title = "Dom", TopicId = _tester.TopicOne.Id, Path = "C:\\Source" }; Metadata = new Metadata { Title = "Dom features", Type = "Info" }; }