public AlbumCreateViewModel BuildCreateAlbum(Album album)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            var result = new AlbumCreateViewModel();
            result.Name = album.Name;
            result.Description = album.Description;
            result.Key = album.Key;
            return result;
        }
        public Album BuildAlbum(AlbumCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            var result = new Album();
            result.ImageNumber = 0;
            result.Name = viewModel.Name;
            result.Description = viewModel.Description;
            result.CreationDate = DateTime.UtcNow;

            return result;
        }
        public ActionResult CreateAlbum(AlbumCreateViewModel viewModel)
        {
            bool result = false;
            var user = this.User.Identity as CustomIdentity;
            if (this.ModelState.IsValid && viewModel != null)
            {
                try
                {
                    User owner = this._membershipService.GetUserByKey(user.Id);
                    Album album = this._albumMapper.BuildAlbum(viewModel);
                    this._imageAlbumService.CreateAlbum(owner, album);
                    result = true;
                }
                catch (Exception)
                {
                    this.ModelState.AddModelError(string.Empty, Resources.Resources.OperationFailure);
                }
            }
            else
            {
                this.ModelState.AddModelError(string.Empty, Resources.Resources.OperationFailure);
            }

            if (result)
            {
                return this.Json(new { success = result });
            }

            return this.PartialView("_CreateAlbum", viewModel);
        }
 public PartialViewResult CreateAlbum()
 {
     var result = new AlbumCreateViewModel();
     return this.PartialView("_CreateAlbum", result);
 }
        public ActionResult RemoveAlbum(AlbumCreateViewModel viewModel)
        {
            bool result = false;
            if (viewModel != null)
            {
                try
                {
                    Album album = this._imageAlbumService.GetAlbumByKey(viewModel.Key);
                    if (album != null)
                    {
                        result = this._imageAlbumService.RemoveAlbum(album);
                    }
                    else
                    {
                        this.TempData[Constants.TempDataErrorMessage] = "Album is missing.";
                        return this.PartialView("_ErrorModal");
                    }
                }
                catch (Exception ex)
                {
                    this.TempData[Constants.TempDataErrorMessage] = ex.Message;
                    return this.PartialView("_ErrorModal");
                }
            }
            else
            {
                this.TempData[Constants.TempDataErrorMessage] = "Album is missing.";
                return this.PartialView("_ErrorModal");
            }

            if (result)
            {
                return this.Json(new { success = result });
            }

            return this.PartialView("_Success");
        }
        public ActionResult EditAlbum(AlbumCreateViewModel viewModel)
        {
            bool result = false;
            int key;

            if (!int.TryParse(ViewBag.Key, out key))
            {
                key = -1;
            }

            var user = this.User.Identity as CustomIdentity;

            if (this.ModelState.IsValid && viewModel != null)
            {
                try
                {
                    User owner = this._membershipService.GetUserByKey(key);
                    Album sourceAlbum = this._imageAlbumService.GetAlbumByKey(viewModel.Key);
                    if (sourceAlbum != null)
                    {
                        this._albumMapper.UpdateAlbum(sourceAlbum, viewModel);
                        this._imageAlbumService.UpdateAlbum(owner, sourceAlbum);
                    }

                    result = true;
                }
                catch (Exception)
                {
                    this.ModelState.AddModelError(string.Empty, Resources.Resources.OperationFailure);
                }
            }
            else
            {
                this.ModelState.AddModelError(string.Empty, Resources.Resources.OperationFailure);
            }

            if (result)
            {
                return this.Json(new { success = result });
            }

            return this.PartialView("_EditAlbum", viewModel);
        }
        public void UpdateAlbum(Album album, AlbumCreateViewModel viewModel)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            album.Name = viewModel.Name;
            album.Description = viewModel.Description;
        }