public Common.Models.AttachmentItemModels.AttachmentItem GetAttachmentItem(AttachmentItemKeyModel model) { var query = _DbContext.AttachmentItems .Where(x => x.Id == model.AttachmentItemId && x.Attachment.EntityName == model.EntityName && x.Attachment.FieldName == model.FieldName && x.Attachment.EntityId == model.EntityId) .Include(x => x.Attachment); return(query.Select(x => new Common.Models.AttachmentItemModels.AttachmentItem { Id = x.Id, AttachmentId = x.AttachmentId, Description = x.Description, FileExtension = x.FileExtension, FileName = x.FileName, FileSize = x.FileSize, UploadDate = x.UploadDate, Owner = x.Owner, Attachment = new Common.Models.AttachmentModels.Attachment { Id = x.Attachment.Id, EntityId = x.Attachment.EntityId, EntityName = x.Attachment.EntityName, FieldName = x.Attachment.FieldName, } }) .FirstOrDefault()); }
//details public AttachmentItem GetAttachmentItem(AttachmentItemKeyModel model) { if (!_authorization.Details(model)) { throw new UnauthorizedAccessException(); } return(_business.GetAttachmentItem(model)); }
//download public AttachmentItemDownloadModel DownloadAttachmentItem(AttachmentItemKeyModel model) { if (!_authorization.Download(model)) { throw new UnauthorizedAccessException(); } return(_business.DownloadAttachmentItem(model)); }
public AttachmentItemDownloadModel DownloadAttachmentItem(AttachmentItemKeyModel model) { var query = _DbContext.AttachmentItems .Where(x => x.Id == model.AttachmentItemId && x.Attachment.EntityName == model.EntityName && x.Attachment.FieldName == model.FieldName && x.Attachment.EntityId == model.EntityId); return(query.Select(x => new AttachmentItemDownloadModel { FileContent = new MemoryStream(x.FileContent), FileExtension = x.FileExtension, FileName = x.FileName, }) .FirstOrDefault()); }
public ActionResult GetInfo(AttachmentItemKeyModel model) { try { var attachmentItem = attachmentBusiness.GetAttachmentItem(model);//check details permission if (attachmentItem == null) { return(NotFound()); } return(Ok(attachmentItem)); } catch (Exception) { return(BadRequest()); } }
public ActionResult Download(AttachmentItemKeyModel model) { try { var item = attachmentBusiness.DownloadAttachmentItem(model);//check download permission if (item == null) { return(NotFound()); } return(File(item.FileContent, item.FileExtension, item.FileName)); } catch (Exception) { return(BadRequest()); } }
public bool Download(AttachmentItemKeyModel model) { throw new NotImplementedException(); }