コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public void PostAttachmentTestBadRequest()
        {
            var attachmentFormModel = new AttachmentFormModel();

            _tester.TestControllerWithMockData()
            .Calling(c => c.PostAttachment(_tester.TopicOne.Id, attachmentFormModel))
            .ShouldReturn()
            .BadRequest();
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 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"
     };
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
 public TopicAttachment(AttachmentFormModel model)
 {
     Title = model.Title;
 }