public IActionResult UpdateGallery([FromBody] GalleryUpdate gallery) { using TransactionScope scope = new TransactionScope(); foreach (var itemimage in gallery.ImageAttributes) { var imageAttribute = _ijpRepository.GetImageAttribute(itemimage.ImageId); imageAttribute.Description = itemimage.Description; _ijpRepository.UpdateImageAttribute(imageAttribute); } _ijpRepository.Save(); IjpGallery galleryupdate = new IjpGallery() { Active = gallery.Active, Columns = gallery.Columns, Description = gallery.Description, GalleryId = gallery.GalleryId, Images = gallery.Images, Name = gallery.Name }; var galleryEntity = _mapper.Map <Context.IjpGallery>(galleryupdate); _ijpRepository.UpdateGallery(galleryEntity); _ijpRepository.Save(); scope.Complete(); return(NoContent()); }
public void UpdateGallery(IjpGallery gallery) { var res = _ijpContext.Gallery.FirstOrDefault(x => x.GalleryId == gallery.GalleryId); res.Active = gallery.Active; res.Columns = gallery.Columns; res.DateUpdate = DateTime.Now; res.Description = gallery.Description; res.Images = gallery.Columns; res.Name = gallery.Name; _ijpContext.Gallery.Update(res); }
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); }
public ItemGallery() { Gallery = new IjpGallery(); GalleryFile = new List <IjpGalleryFile>(); }
public void AddGallery(IjpGallery gallery) { _ijpContext.Gallery.Add(gallery); }