Beispiel #1
0
        public async Task <IActionResult> AddPhoto(int albumId, AddPhotoToAlbumViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var album = await this.albums.Find(albumId);

            var user = await this.userManager.GetUserAsync(this.User);

            if (album.UserId != user.Id)
            {
                return(this.BadRequest());
            }

            var success = await this.photos.Create(
                model.Description,
                model.ImageUrl,
                model.Location,
                model.Latitude,
                model.Longitude,
                model.Tags,
                albumId);

            if (!success)
            {
                return(this.BadRequest());
            }

            this.TempData.AddSuccessMessage($"The photo has been successfully added.");
            return(this.RedirectToAction("Details", "Albums", new { area = "", id = albumId }));
        }
Beispiel #2
0
        public ActionResult AddToAlbum(AddPhotoToAlbumViewModel model)
        {
            string userId = User.Identity.GetUserId();

            _logger.Info("photo {0} is requested to be added to album {1} by {2}", model.PhotoName, model.AlbumName, userId);

            var request = new RequestEntity
            {
                UniqueUserName = model.UniqueUserName,
                AlbumName      = model.AlbumName,
                PhotoName      = model.PhotoName
            };

            _albumService.AddPhotoToAlbum(request);

            _logger.Info("Successfully added photo {0} to albuem {1} both owned by {2}", model.PhotoName, model.AlbumName, userId);

            TempData["ResultMessage"] = string.Format(SuccessMessages.SuccessfullyAddedPhotoToAlbum, model.PhotoName, model.AlbumName);

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