public void CreateRootGallery(User owner, bool isTrashGallery) { string galleryName; string galleryDescription; if(isTrashGallery) { galleryName = "Trash"; galleryDescription = "Use for photos that does not belong to any gallery"; } else { galleryName = "Root gallery"; galleryDescription = "Root gallery for user, cannot be deleted."; } var gal = new Gallery { DateCreated = DateTime.Now, ParentId = ObjectId.Empty, OwnerId = owner.Id, Name = galleryName, Description = galleryDescription, Order = 1, IsTrashGallery = isTrashGallery }; Save(gal); }
public void Save(Gallery gallery) { _galleries.Collection.Save(gallery); }
public ActionResult GalleryEdit(GalleryEdit galEdit, string hdnPreviewPhotosShadow, string hdnPhotosShadow, string hdnTrashShadow) { if (ModelState.IsValid) { try { var gal = new Gallery { DateCreated = DateTime.Now, Name = galEdit.Name, Description = galEdit.Description, ParentId = galEdit.ParentGalleryId == "0" ? ObjectId.Empty : ObjectId.Parse(galEdit.ParentGalleryId), Order = galEdit.Order, OwnerId = CurrentUser.Id }; if(!string.IsNullOrEmpty(galEdit.GalleryId)) //UPDATE { gal.Id = ObjectId.Parse(galEdit.GalleryId); gal = ProcessGalleryPhotos(gal, hdnPreviewPhotosShadow, hdnPhotosShadow, hdnTrashShadow); _galleryManager.Save(gal); galEdit.OKMessage = string.Format("Update galerie {0} proběhl úspěšně.", gal.Name); } else //INSERT { gal.OwnerId = CurrentUser.Id; _galleryManager.Save(gal); galEdit.OKMessage = string.Format("Uložení nové galerie {0} proběhlo úspěšně.", gal.Name); } } catch (Exception ex) { galEdit.ErrorMessage = "Při ukládání galerie došlo k chybě: " + ex.Message; } } else { galEdit.ErrorMessage = "Některá povinná položka není vyplněná."; } return View(galEdit); }
public void Delete(Gallery gallery) { _galleries.Collection.Remove(Query.EQ("_id", gallery.Id)); }
private Gallery ProcessGalleryPhotos(Gallery gallery, string previewPhotos, string photos, string trash) { var previewPhotosList = new List<GalleryPhoto>(); var photosList = new List<GalleryPhoto>(); var separator = new[] { ',' }; if (!string.IsNullOrEmpty(previewPhotos) && previewPhotos.Length > 1) { previewPhotos = previewPhotos.Trim(separator); var previewPhotosArr = previewPhotos.Split(new[] { ',' }); for (int i = 0; i < previewPhotosArr.Length; i++) { var photo = _photoManager.GetPhoto(previewPhotosArr[i]); if (photo != null) { previewPhotosList.Add(new GalleryPhoto(photo, i + 1)); } } } if (!string.IsNullOrEmpty(photos) && photos.Length > 1) { photos = photos.Trim(separator); var photosArr = photos.Split(new[] { ',' }); for (int i = 0; i < photosArr.Length; i++) { var photo = _photoManager.GetPhoto(photosArr[i]); if (photo != null) { photosList.Add(new GalleryPhoto(photo, i + 1)); } } } if (!string.IsNullOrEmpty(trash) && trash.Length > 1) { trash = trash.Trim(separator); var trashArr = trash.Split(new[] { ',' }); if(trashArr.Length > 0) { var trashGal = _galleryManager.ClearTrashGallery(CurrentUser); _galleryManager.AddPhotosToGallery(trashGal.Id.ToString(), trashArr); } } gallery.Photos = photosList; gallery.PreviewPhotos = previewPhotosList; return gallery; }