Beispiel #1
0
        public ActionResult UpdateAlbum(UpdateAlbumViewModel model, HttpPostedFileBase image = null)
        {
            if (ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                _logger.Info("User {0} requested to update album {1}", userId, model.AlbumId);

                ActionResult alternativeResult = ErrorIfNotAnOwner(model.UniqueUserName, Errors.AttemptToRemoveAlbum, _userService, userId, _logger);

                if (alternativeResult == null)
                {
                    if (image != null)
                    {
                        model.ImageMimeType = image.ContentType;
                        model.ImageData     = new byte[image.ContentLength];
                        image.InputStream.Read(model.ImageData, 0, image.ContentLength);
                    }

                    UpdateAlbum request = MapperHelper.GetValue <UpdateAlbumViewModel, UpdateAlbum>(model);

                    _albumService.UpdateAlbum(request);

                    _logger.Info("Album {0} successfully updated", model.AlbumId);
                    TempData["ResultMessage"] = string.Format(SuccessMessages.SuccessfullyUpdatedAlbum, model.AlbumName);

                    return(RedirectToAction("ViewAlbum", new { albumName = model.AlbumName, uniqueUserName = model.UniqueUserName }));
                }

                return(alternativeResult);
            }
            return(View(model));
        }
Beispiel #2
0
        public UpdateAlbum GetAlbumForUpdate(RequestEntity data)
        {
            UpdateAlbum album = _albumRepo.GetEntities(x => x.UniqueUserName == data.UniqueUserName && x.AlbumName == data.AlbumName)
                                .Select(x => new UpdateAlbum
            {
                AlbumId        = x.AlbumId,
                AlbumName      = x.AlbumName,
                Description    = x.Description,
                ImageData      = x.ImageData,
                ImageMimeType  = x.ImageMimeType,
                UniqueUserName = x.UniqueUserName
            }).FirstOrDefault();

            return(album);
        }
Beispiel #3
0
        public void UpdateAlbum(UpdateAlbum data)
        {
            Album album = _albumRepo.Get(x => x.AlbumId == data.AlbumId);

            if (album != null)
            {
                album.AlbumName   = data.AlbumName;
                album.Description = data.Description;
                if (data.ImageData != null && data.ImageMimeType != null)
                {
                    album.ImageData     = data.ImageData;
                    album.ImageMimeType = data.ImageMimeType;
                }
            }
            _albumRepo.Update(album);
        }