public IActionResult NewAttachment(IFormFile file, AttachmentVm model) { if (file is null || !ModelState.IsValid) { return(BadRequest()); } model.FileName = file.FileName; model.FileType = file.ContentType; var entity = AttachmentVm.MapToEntityModel(model); using var memoryStream = new MemoryStream(); file.CopyTo(memoryStream); IValidationResult upload; try { upload = _attachmentBlProvider.UploadAttachment(memoryStream, entity); } catch (Exception e) { return(Conflict(e.ToString())); } if (!upload.IsValid) { return(Conflict()); // ModelState.AddModelError("File error", upload.Message); } return(RedirectToAction("Index", "Attachment")); }
public IActionResult DeleteAttachment(AttachmentVm model) { var entityModel = AttachmentVm.MapToEntityModel(model); _attachmentBlProvider.DeleteAttachment(entityModel); return(RedirectToAction("Index", "Attachment")); }