public ActionResult ExhibitionSetup() { ExhibitionModels model = new ExhibitionModels(); if (User.Identity.IsAuthenticated) { model.ServicesGallery = GalleryPage(User.Identity.GetUserId().ToString()); } else { RedirectToAction("LogOff", "Account"); } return(View(model)); }
public List <ExhibitionModels> GalleryPage(string userId) { List <ExhibitionModels> list = new List <ExhibitionModels>(); List <Exhibition> objlist = serviceContext.Exhibitions.Where(x => x.UserId == userId).ToList(); if (objlist == null) { TempData["gal"] = "Please Upload your pictures For "; } foreach (var a in objlist) { ExhibitionModels model = new ExhibitionModels(); model.description = a.Description; model.ImagePath = a.ImagePath; model.UserId = a.UserId; model.Title = a.Title; list.Add(model); } return(list); }
public ActionResult ExhibitionSetup(ExhibitionModels model, HttpPostedFileBase[] uploadedFile) { if (User.Identity.IsAuthenticated) { foreach (HttpPostedFileBase upload in uploadedFile) { var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png" }; if (upload == null || upload.ContentLength == 0) { ModelState.AddModelError("ImageUpload", "This field is required"); return(View()); } else if (!validImageTypes.Contains(upload.ContentType)) { ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image."); return(View()); } Exhibition exhibit = new Exhibition(); exhibit.Description = model.description; exhibit.Title = model.Title; exhibit.UserId = User.Identity.GetUserId().ToString(); string ImageName = System.IO.Path.GetFileName(upload.FileName); string physicalPath = Server.MapPath("~/images/" + ImageName); upload.SaveAs(physicalPath); exhibit.ImagePath = ImageName; serviceContext.Exhibitions.Add(exhibit); serviceContext.SaveChanges(); } } Session["Success"] = "Exhibition Created Sucessfully"; return(RedirectToAction("ExhibitionSetup")); }