public void UploadAttachmentItem(UploadAttachmentItemModel model)
        {
            var attachment = _DbContext.Attachments.SingleOrDefault(x => x.Id == model.AttachmentId &&
                                                                    x.EntityName == model.EntityName &&
                                                                    x.FieldName == model.FieldName &&
                                                                    x.EntityId == model.EntityId);

            foreach (var item in model.FileContent)
            {
                var attachmentItem = new Context.AttachmentItem
                {
                    AttachmentId = attachment.Id,
                    Description  = model.Description,
                    UploadDate   = DateTime.Now,
                };
                using (var attachmentBytes = item.OpenReadStream())
                    using (var memoryStream = new MemoryStream())
                    {
                        attachmentBytes.CopyTo(memoryStream);
                        attachmentItem.FileContent = memoryStream.ToArray();

                        attachmentItem.FileExtension = item.ContentType;
                        attachmentItem.FileName      = item.FileName;
                        attachmentItem.FileSize      = (int)memoryStream.Length;
                    }
                _DbContext.AttachmentItems.Add(attachmentItem).State = EntityState.Added;
            }

            _DbContext.SaveChanges();
        }
Beispiel #2
0
 //upload
 public void UploadAttachmentItem(UploadAttachmentItemModel model)
 {
     if (!_authorization.Upload(model))
     {
         throw new UnauthorizedAccessException();
     }
     _business.UploadAttachmentItem(model);
 }
 public ActionResult Upload([FromForm] UploadAttachmentItemModel attachmentItemViewModel)
 {
     try
     {
         attachmentBusiness.UploadAttachmentItem(attachmentItemViewModel);//check upload permission
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
 public bool Upload(UploadAttachmentItemModel model)
 {
     throw new NotImplementedException();
 }