public ActionResult EditAlbum(EditAlbumModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.Id == 0)
                    {
                        var added = _albumService.AddOne(model);
                        model.Id = added.Id;
                        if (model.ParentAlbum.Id != 0)
                        {
                            model.ParentAlbum = _albumService.GetOne(model.ParentAlbum.Id);
                        }
                        ViewBag.Success = $"Альбом {model.TitleRu} был успешно добавлен";
                    }
                    else
                    {
                        if (model.ParentAlbum.Id != 0)
                        {
                            model.ParentAlbum = _albumService.GetOne(model.ParentAlbum.Id);
                        }
                        _albumService.UpdateOne(model);
                        ViewBag.Success = $"Альбом {model.TitleRu} был успешно обновлен";
                    }
                }

                model.ParentAlbums = _albumService.GetAvailableAlbumSelectList(_photoService.GetAll()).Where(x => x.Value != model.Id.ToString());
                model.ViewPatterns = ViewPatternHelper.GetPatterns();
                model.Photos       = new PhotoListModel()
                {
                    Photos = _photoService.GetAll().Where(x => x.AlbumId == model.Id).Select(x => new PhotoModel()
                    {
                        Id             = x.Id,
                        DescriptionEng = x.DescriptionEng,
                        DescriptionRu  = x.DescriptionRu,
                        PhotoPath      = x.PhotoPath,
                        ThumbnailPath  = x.ThumbnailPath,
                        TitleRu        = x.TitleRu,
                        TitleEng       = x.TitleEng,
                        Album          = _albumService.GetOne(model.Id),
                        Order          = x.Order
                    }).OrderBy(x => x.Order).ToList(),
                    ReturnUrl = Url.Action("EditAlbum")
                };
            }
            catch (Exception exception)
            {
                Log.RegisterError(exception);
            }

            return(View(model));
        }
        public ActionResult AddAlbum()
        {
            var model = new EditAlbumModel()
            {
                ParentAlbum  = new Album(),
                ParentAlbums = _albumService.GetAvailableAlbumSelectList(_photoService.GetAll()),
                Photos       = new PhotoListModel(),
                ViewPatterns = ViewPatternHelper.GetPatterns()
            };

            return(View("EditAlbum", model));
        }
        public ActionResult EditAlbum(int id)
        {
            var album = _albumService.GetOne(id);

            if (album == null)
            {
                throw new NullReferenceException();
            }

            var model = new EditAlbumModel()
            {
                Id             = album.Id,
                ParentAlbum    = album.ParentId == 0 ? new Album() : _albumService.GetOne(album.ParentId),
                DescriptionRu  = album.DescriptionRu,
                DescriptionEng = album.DescriptionEng,
                TitleRu        = album.TitleRu,
                TitleEng       = album.TitleEng,
                ParentAlbums   = _albumService.GetAvailableAlbumSelectList(_photoService.GetAll()).Where(x => x.Value != album.Id.ToString()),
                IsParent       = _albumService.GetAll().isParent(album),
                ViewPattern    = album.ViewPattern,
                CoverPath      = album.CoverPath,
                ViewPatterns   = ViewPatternHelper.GetPatterns()
            };

            var photos = _photoService.GetAll().Where(x => x.AlbumId == model.Id);

            model.Photos = new PhotoListModel()
            {
                Photos = photos.Select(x => new PhotoModel()
                {
                    Id             = x.Id,
                    DescriptionEng = x.DescriptionEng,
                    DescriptionRu  = x.DescriptionRu,
                    PhotoPath      = x.PhotoPath,
                    ThumbnailPath  = x.ThumbnailPath,
                    TitleRu        = x.TitleRu,
                    TitleEng       = x.TitleEng,
                    Album          = _albumService.GetOne(model.Id),
                    Order          = x.Order == default(int) ? x.Id : x.Order
                }).OrderByDescending(x => x.Order).ToList(),

                ReturnUrl       = Url.Action("EditAlbum"),
                ShowOrderArrows = true
            };

            return(View(model));
        }