public ActionResult Create(int Page_ID, string Gallery_Name) { if (ModelState.IsValid) { Gallery gal = new Gallery(); gal.Gallery_Name = Gallery_Name; gal.Date_Added = DateTime.Now; gal.Added_By = User.Identity.Name.ToString();///TODO: auth gal.Archived = false; db.Galleries.Add(gal); db.SaveChanges(); PageGalleryAssign galAss = new PageGalleryAssign(); galAss.Gallery = gal; galAss.Page_ID = Page_ID; galAss.Date_Added = DateTime.Now; galAss.Added_By = User.Identity.Name.ToString();///TODO: auth galAss.Archived = false; db.PageGalleryAssigns.Add(galAss); db.SaveChanges(); return(RedirectToAction("Edit", new { Page_ID = Page_ID, Gallery_ID = gal.Gallery_ID })); } else { ModelState.AddModelError("", "Error. Invalid Model State. Please try again."); GalleryCreateViewModel viewMod = new GalleryCreateViewModel(Page_ID); viewMod.Gallery_Name = Gallery_Name; return(View(viewMod)); } }
public async Task <ActionResult> PictureCreate([FromForm] GalleryCreateViewModel galleryVM) { if (ModelState.IsValid) { var uploadedImage = ""; if (galleryVM.Photo != null) { uploadedImage = await ProcessPhoto(galleryVM.Photo); } try { var picture = _mapper.Map <Picture>(galleryVM); picture.CreatedAt = DateTime.Now; picture.ImgUrl = uploadedImage; if (await _galleryRepo.AddPicture(picture)) { TempData["Alert"] = "Picture Added Successfully"; return(RedirectToAction(nameof(GalleryIndex))); } ViewBag.Error = "Unable to add picture, please try again or contact administrator"; return(View()); } catch (Exception ex) { ViewBag.Error = "Unable to add picture, please try again or contact administrator"; return(View()); } } ViewBag.Error = "Please correct the error(s) in Form"; return(View(galleryVM)); }
public ActionResult Create(GalleryCreateViewModel galleryCreate) { var image = galleryCreate.Image; var imageSave = WorkImage.CreateImage(galleryCreate.Image, 800, 600); if(imageSave!=null) { string path = Server.MapPath("~/Upload/ImageGallery/"); string fileName = Guid.NewGuid().ToString() + ".jpg"; imageSave.Save(path + fileName, ImageFormat.Jpeg); } return View(); }
public async Task <ActionResult> PictureEdit([FromForm] GalleryCreateViewModel pictureVM) { if (ModelState.IsValid) { var editPicture = _mapper.Map <Picture>(pictureVM); try { await _galleryRepo.UpdatePicture(editPicture); TempData["Alert"] = "Picture Edited Successfully"; return(RedirectToAction(nameof(GalleryIndex))); } catch (Exception ex) { ViewBag.Error = "Unable to add picture, please try again or contact administrator"; return(View()); } } ViewBag.Error = "Please correct the error(s) in Form"; return(View()); }
public ActionResult Create(int Page_ID) { GalleryCreateViewModel viewMod = new GalleryCreateViewModel(Page_ID); return(View(viewMod)); }