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)); }