コード例 #1
0
        public ActionResult GetAttachmentId(AttachmentKeyModel model)
        {
            try
            {
                model.CheckArgumentIsNull(nameof(model));
                model.FieldName.CheckArgumentIsNullOrEmpty(nameof(model.FieldName));
                model.EntityName.CheckArgumentIsNullOrEmpty(nameof(model.EntityName));

                if (model.EntityId.HasValue())
                {
                    var attachmentId = attachmentBusiness.GetAttachmentId(model);//check read permission
                    if (attachmentId == null)
                    {
                        return(Ok(attachmentBusiness.CreateAttachment(model)));//check create permission
                    }
                    return(Ok(attachmentId));
                }
                else
                {
                    var token = tokenProvider.GetAttachmentToken();
                    if (!token.HasValue())
                    {
                        token = tokenProvider.SetAttachmentToken();
                    }
                    var tempAttachmentKeyModel = new TemporaryAttachmentKeyModel {
                        EntityName = model.EntityName, FieldName = model.FieldName, Token = token
                    };
                    return(Ok(attachmentBusiness.CreateAttachmentTemporarily(tempAttachmentKeyModel)));//check create permission
                }
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #2
0
 //create
 public AttachmentModel CreateAttachmentTemporarily(TemporaryAttachmentKeyModel model)
 {
     if (!_authorization.Create(new AttachmentKeyModel {
         EntityName = model.EntityName, FieldName = model.FieldName
     }))
     {
         throw new UnauthorizedAccessException();
     }
     return(_business.CreateAttachmentTemporarily(model));
 }
コード例 #3
0
        public AttachmentModel CreateAttachmentTemporarily(TemporaryAttachmentKeyModel model)
        {
            if (!model.EntityName.HasValue() || !model.FieldName.HasValue() || !model.Token.HasValue())
            {
                throw new ArgumentNullException();
            }
            var attachment = new Context.Attachment()
            {
                EntityName = model.EntityName,
                FieldName  = model.FieldName,
                Token      = model.Token
            };

            _DbContext.Attachments.Add(attachment).State = EntityState.Added;
            _DbContext.SaveChanges();
            return(new AttachmentModel
            {
                AttachmentId = attachment.Id,
                TotalCount = 0
            });
        }