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 ActionResult Add(int sourceType, int sourceId, AttachmentFormModel model) { var attachment = AttachmentService.AttachmentNew((SourceType)sourceType, sourceId); Csla.Data.DataMapper.Map(model, attachment, true); var fs = model.FileData.InputStream; var fileData = new byte[model.FileData.ContentLength]; fs.Read(fileData, 0, model.FileData.ContentLength); attachment.FileData = fileData; attachment.Name = Path.GetFileName(model.FileData.FileName); attachment.FileType = model.FileData.ContentType; attachment = AttachmentService.AttachmentSave(attachment); if (attachment.IsValid) { attachment = AttachmentService.AttachmentFetch(attachment.AttachmentId); this.Map(attachment, model, true); } return(PartialView("AttachmentUserControl", model)); }
public void PostAttachmentTestBadRequest() { var attachmentFormModel = new AttachmentFormModel(); _tester.TestControllerWithMockData() .Calling(c => c.PostAttachment(_tester.TopicOne.Id, attachmentFormModel)) .ShouldReturn() .BadRequest(); }
public ActionResult Edit(int id) { var model = new AttachmentFormModel(); var attachment = AttachmentRepository.AttachmentFetch(id); model.Title = "Attachment Edit"; model.Attachment = attachment; return(this.View(model)); }
public ActionResult Create(int noteId) { var model = new AttachmentFormModel(); var attachment = AttachmentRepository.AttachmentNew(noteId, SourceType.Note); model.Title = "Attachment Create"; model.Attachment = attachment; return(this.View(model)); }
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 AttachmentFormModel Map(Attachment attachment, AttachmentFormModel model, bool ignoreBrokenRules) { Csla.Data.DataMapper.Map(attachment, model, true); model.Tab = "Task"; model.IsNew = attachment.IsNew; model.IsValid = attachment.IsValid; if (!ignoreBrokenRules) { foreach (var brokenRule in attachment.BrokenRulesCollection) { this.ModelState.AddModelError(string.Empty, brokenRule.Description); } } return(model); }
public IActionResult PostAttachment([FromRoute] int topicId, [FromBody] AttachmentFormModel model) { if (!_topicPermissions.IsAssociatedTo(User.Identity.GetUserIdentity(), topicId)) { return(Forbidden()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _attachmentsManager.CreateAttachment(topicId, User.Identity.GetUserIdentity(), model); if (result.Success) { return(Ok(result)); } return(NotFoundError(result)); }
public ActionResult Edit(int id, FormCollection collection) { var model = new AttachmentFormModel(); var attachment = AttachmentRepository.AttachmentFetch(id); var note = NoteRepository.NoteFetch(attachment.SourceId); this.Map(collection, attachment); attachment = AttachmentRepository.AttachmentSave(attachment); if (attachment.IsValid) { return(this.RedirectToAction("Details", note.SourceTypeName, new { id = note.SourceId })); } model.Title = "Attachment Edit"; model.Attachment = attachment; ModelHelper.MapBrokenRules(this.ModelState, attachment); return(this.View(model)); }
public TopicAttachment(AttachmentFormModel model) { Title = model.Title; }