public ActionResult Edit(Certificate certificate, HttpPostedFileBase CertificateImage) { if (ModelState.IsValid) { #region Upload Image if (CertificateImage != null) { if (System.IO.File.Exists(Server.MapPath("/Files/CertificatesImages/" + certificate.Image))) { System.IO.File.Delete(Server.MapPath("/Files/CertificatesImages/" + certificate.Image)); } // Saving Temp Image var newFileName = Guid.NewGuid() + Path.GetExtension(CertificateImage.FileName); CertificateImage.SaveAs(Server.MapPath("/Files/CertificatesImages/Temp/" + newFileName)); // Resize Image ImageResizer image = new ImageResizer(800, 600, true); image.Resize(Server.MapPath("/Files/CertificatesImages/Temp/" + newFileName), Server.MapPath("/Files/CertificatesImages/" + newFileName)); // Deleting Temp Image System.IO.File.Delete(Server.MapPath("/Files/CertificatesImages/Temp/" + newFileName)); certificate.Image = newFileName; } #endregion _repo.Update(certificate); return(RedirectToAction("Index")); } return(View(certificate)); }
public async System.Threading.Tasks.Task <OperationResult <Certificate> > UpdateCertificate(Certificate certificate) { return(await System.Threading.Tasks.Task.Factory.StartNew <OperationResult <Certificate> >(() => { OperationResult <Certificate> result = new OperationResult <Certificate>(); try { if (IsInCompany(certificate.CompanyId)) { result.Result = CertificatesRepository.Update(certificate); } } catch (Exception ex) { LoggingService.Log(ex); } return result; })); }