public void OnGet(int galleryId, string newg, string attr, string descrs) { GalleryIdSelected = galleryId; System.Security.Claims.ClaimsPrincipal currentUser = this.User; if (!string.IsNullOrEmpty(newg)) { ItemGallery mygallery = new ItemGallery(); mygallery.NewGallery("NoName_" + DateTime.Now.ToString("yyyyMMdd"), "NoDescription_" + DateTime.Now.ToString("yyyyMMdd"), newg, attr); GalleryIdSelected = this.MyContainer.myGalleries.SaveGallery(mygallery, descrs, userManager.GetUserId(currentUser)); MyContainer = new MyContainer(ijpContext, userManager.GetUserId(currentUser)); } }
public RedirectToPageResult OnPostSaveGallery() { ItemGallery newgallery = new ItemGallery(); newgallery.Gallery.Columns = Helper.Encode(GetRequestParam("attrs")); newgallery.Gallery.Description = GetRequestParam("inputgallerydescription"); newgallery.Gallery.Name = GetRequestParam("inputgalleryname"); newgallery.Gallery.GalleryId = Convert.ToInt32(GetRequestParam("galleryid")); newgallery.Gallery.Active = GetRequestParam("toggleActive") == "on" ? true : false; newgallery.Gallery.Images = Helper.Encode(GetRequestParam("images")); string description_ids = GetRequestParam("descriptions"); System.Security.Claims.ClaimsPrincipal currentUser = this.User; GalleryIdSelected = this.MyContainer.myGalleries.SaveGallery(newgallery, description_ids, userManager.GetUserId(currentUser)); return(new RedirectToPageResult("MyGalleries")); }
public int SaveGallery(ItemGallery gallery, string description_ids, string userId) { int newId = 0; using TransactionScope scope = new TransactionScope(); if (gallery.Gallery.GalleryId == 0) { if (!string.IsNullOrEmpty(gallery.Gallery.Images)) { var mygallery = new IjpGallery() { Name = gallery.Gallery.Name, Description = gallery.Gallery.Description, Columns = gallery.Gallery.Columns, DateInsert = DateTime.Now, DateUpdate = DateTime.Now, UserId = userId, Images = gallery.Gallery.Images }; ijpContext.Gallery.Add(mygallery); ijpContext.SaveChanges(); newId = mygallery.GalleryId; var images = Helper.Decode(gallery.Gallery.Images); foreach (string img in images.Split(',')) { var imagename = img.Split('/')[4].Split('?')[0]; var file = ijpContext.File.FirstOrDefault(x => x.Name.Equals(imagename)); if (file != null) { ijpContext.GalleryFile.Add(new IjpGalleryFile { FileId = file.FileId, GalleryId = mygallery.GalleryId, Description = "description of " + imagename }); } } ijpContext.SaveChanges(); } } else { var mygallery = ijpContext.Gallery.FirstOrDefault(x => x.GalleryId == gallery.Gallery.GalleryId); newId = mygallery.GalleryId; if (mygallery != null) { mygallery.Name = gallery.Gallery.Name; mygallery.Description = gallery.Gallery.Description; mygallery.DateUpdate = DateTime.Now; mygallery.UserId = userId; mygallery.Columns = gallery.Gallery.Columns; mygallery.Images = gallery.Gallery.Images; mygallery.Active = gallery.Gallery.Active; ijpContext.SaveChanges(); var galleryfile = ijpContext.GalleryFile.Where(x => x.GalleryId == gallery.Gallery.GalleryId); if (galleryfile != null) { foreach (string descrId in description_ids.Split(',')) { var desc = descrId.Split("-")[0]; int id = Convert.ToInt32(descrId.Split("|")[1]); galleryfile.FirstOrDefault(x => x.FileId == id).Description = descrId.Split("|")[0]; } ijpContext.SaveChanges(); } } } scope.Complete(); return(newId); }