public ActionResult SubmitGallery(EventGalleryVM eventGalleryVM) { if (!ModelState.IsValid) { return(View(eventGalleryVM)); } if (eventGalleryVM.Files.Count() > 0) { eventGalleryVM.Id = _eventRepo.InsertEventGallery(eventGalleryVM); } if (eventGalleryVM.Id > 0) { foreach (HttpPostedFileBase file in eventGalleryVM.Files) { string fileName = string.Empty; if (file != null && file.ContentLength > 0) { fileName = Guid.NewGuid() + "_" + System.IO.Path.GetFileName(file.FileName); string _path = System.IO.Path.Combine(Server.MapPath("~/EventGalleryImages"), fileName); file.SaveAs(_path); } eventGalleryVM.ImageName = fileName; _eventRepo.InsertGalleryImages(eventGalleryVM); } } _eventRepo.SaveChanges(); return(Json("Success", JsonRequestBehavior.AllowGet)); }
public void InsertGalleryImages(EventGalleryVM eventGallery) { if (eventGallery != null) { Event_Gallery_Images event_Gallery = new Event_Gallery_Images(); event_Gallery.GalleryImage = eventGallery.ImageName; event_Gallery.DetailGalleryId = eventGallery.Id; event_Gallery.CreatedDate = DateTime.Now; event_Gallery.IsThumbnail = true; _dbContext.Event_Gallery_Images.Add(event_Gallery); } }
public int InsertEventGallery(EventGalleryVM eventGalleryVM) { if (eventGalleryVM != null) { Event_GalleryDetail galleryDetail = new Event_GalleryDetail(); galleryDetail.EventMessage = eventGalleryVM.GalleryDescription; galleryDetail.EventTitle = eventGalleryVM.GalleryName; galleryDetail.GalleryName = eventGalleryVM.GalleryName; galleryDetail.CreatedDate = DateTime.Now; Event_GalleryDetail addedGallery = _dbContext.Event_GalleryDetail.Add(galleryDetail); _dbContext.SaveChanges(); return(addedGallery.Id); } return(0); }