public virtual ActionResult Edit(string id, ImageInfoDto dto) { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); if (ModelState.IsValid) { try { var metadata = new ImageInfo(PhysicalPath + id.Replace("/", "\\")); Mapper.Map(dto, metadata); metadata.SaveWithCaption(dto.Caption, dto.DateCreated); //await Service.UpdateAsync(dto, cts.Token); return(RedirectToControllerDefault().WithSuccess(this, Messages.UpdateSuccessful)); } catch (Exception ex) { HandleUpdateException(ex); } } ViewBag.PageTitle = Title; ViewBag.Admin = Admin; // return View("Edit", dto); return(View("~/Views/Bootstrap4/Edit.cshtml", dto)); }
public static ImageInfo MapImageInfoDto(ImageInfoDto imageInfoDto) { if (imageInfoDto == null) { return(new ImageInfo()); } return(new ImageInfo { ImagePath = imageInfoDto.ImagePath, Md5Hash = imageInfoDto.Md5Hash }); }
public static string SaveImageForPolitician(HttpPostedFileBase image, PersonDto personDto, PoliticianImageTypeEnum imageType) { var fileName = Path.Combine(ConfigHelper.ContentPath, ConfigHelper.POLITICIANS_FOLDER, personDto.GenericName, $"{personDto.GenericName}{imageType.ToString()}{Path.GetExtension(image.FileName)}"); var rescueFileName = Path.Combine(ConfigHelper.ContentPath, ConfigHelper.POLITICIANS_FOLDER, personDto.GenericName, $"{personDto.GenericName}{imageType.ToString()}Rescue{Path.GetExtension(image.FileName)}"); if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } try { image.SaveAs(fileName); } catch { fileName = rescueFileName; image.SaveAs(fileName); } var relativeFilePath = fileName.Replace(ConfigHelper.ContentPath, ""); var pathPlusContent = "\\content" + relativeFilePath; var imageInfo = new ImageInfoDto { ImagePath = pathPlusContent, Md5Hash = FileHelper.CalcMD5(fileName) }; switch (imageType) { case PoliticianImageTypeEnum.MainPic: personDto.MainPicPath = imageInfo; break; case PoliticianImageTypeEnum.ListButtonPic: personDto.ListButtonPicPath = imageInfo; break; case PoliticianImageTypeEnum.SmallButtonPic: personDto.SmallButtonPicPath = imageInfo; break; } return(pathPlusContent); }