public ActionResult SubmitApprenticeshipImage(ApprenticeshipImageModel model) { var contentService = Services.ContentService; var content = contentService.GetById(model.ApprenticeshipId); if (model.MainImage != null && ModelState.IsValid) { string extension = Path.GetExtension(model.MainImage.FileName).Replace(".", ""); if (!utilities.ValidImageFileExtension(extension)) { ModelState.AddModelError("", "Only image file types are allowed (png, jpg, jpeg, gif, webp, tiff)"); return(PartialView(GetTasksViewPath("_ApprenticeshipImage"), model)); } var mediaUdi = _mediaUploadService.CreateMediaItemFromFileUpload(model.MainImage, PAGE_IMAGES_FOLDER_ID, "Image"); content.SetValue(Apprenticeship.GetModelPropertyType(x => x.MainImage).Alias, mediaUdi); contentService.SaveAndPublish(content); string _mediaUdi = content.GetValue("mainImage") != null?content.GetValue("mainImage").ToString() : ""; if (!string.IsNullOrEmpty(_mediaUdi)) { Udi imageUdi = Udi.Parse(_mediaUdi); model.ImageUrl = Umbraco.PublishedContent(imageUdi).Url(); } ViewData["successMessage"] = string.Format(" The file <b><i>{0}</i></b> was succesfully uploaded.<br />", model.MainImage.FileName); } return(PartialView(GetTasksViewPath("_ApprenticeshipImage"), model)); }
public ActionResult ApprenticeshipImage(int apprenticeshipId) { var contentService = Services.ContentService; var content = contentService.GetById(apprenticeshipId); ApprenticeshipImageModel model = new ApprenticeshipImageModel(); string mediaUdi = content.GetValue("mainImage") != null?content.GetValue("mainImage").ToString() : ""; if (!string.IsNullOrEmpty(mediaUdi)) { Udi imageUdi = Udi.Parse(mediaUdi); model.ImageUrl = Umbraco.PublishedContent(imageUdi).Url(); } model.ApprenticeshipId = apprenticeshipId; return(PartialView(GetTasksViewPath("_ApprenticeshipImage"), model)); }