public ActionResult Edit(EditAttachmentViewModel model, HttpPostedFileBase attachment) { if (ModelState.IsValid) { if (attachment != null && attachment.ContentLength > 0) { var fileName = UploadFile(attachment); model.FileName = fileName; } _attachmentsService.Edit(model); return(new RedirectResult(Url.Action("Manage", "Projects", new { id = model.Id }) + "#attachments")); } return(View(model)); }
public void Edit(EditAttachmentViewModel model) { var attachment = _unitOfWork.Attachments.GetById(model.Id); if (!String.IsNullOrEmpty(model.FileName)) { File.Delete(_uploadPath + attachment.FileName); attachment.FileName = model.FileName; attachment.Size = (int)new FileInfo(_uploadPath + model.FileName).Length; } attachment.Title = model.Title; attachment.Description = model.Description; _unitOfWork.Attachments.Update(attachment); _unitOfWork.SaveChanges(); }