public async Task <IActionResult> AddNewPicture(Guid id)
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            Guid currentUserId = new Guid(applicationUser.Id);

            if (!await _repository.ContainsUserAsync(currentUserId))
            {
                return(RedirectToAction("MakeNewProfile", "Main"));
            }

            Album album = await _repository.GetAlbumAsync(id);

            if (album == null)
            {
                return(View("~/Views/Shared/InvalidAttempt.cshtml"));
            }
            else if (album.UserId != currentUserId)
            {
                return(View("~/Views/Shared/InvalidAttempt.cshtml"));
            }
            AddNewPictureVM addNewPictureVM = new AddNewPictureVM
            {
                AlbumId = id
            };

            return(View(addNewPictureVM));
        }
        public async Task <ActionResult> ChangeProfilePicture()
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            if (!await _repository.ContainsUserAsync(new Guid(applicationUser.Id)))
            {
                return(RedirectToAction("MakeNewProfile", "Main"));
            }
            return(View());
        }
Exemplo n.º 3
0
        public async Task <ActionResult> MakeNewProfile()
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            Guid curretUserId = new Guid(applicationUser.Id);

            if (await _repository.ContainsUserAsync(curretUserId))
            {
                return(RedirectToAction("Index"));
            }
            return(View(new AddUserProfileVM()));
        }
        public async Task <IActionResult> Index(Guid id)
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            Guid currentUserId = new Guid(applicationUser.Id);

            if (!await _repository.ContainsUserAsync(currentUserId))
            {
                return(RedirectToAction("MakeNewProfile", "Main"));
            }

            List <string> roles = (List <string>) await _userManager.GetRolesAsync(applicationUser);

            bool isAdmin = roles.Contains("Admin");

            Picture picture = await _repository.GetPictureWithUsersGradedAsync(id);

            if (picture == null)
            {
                return(View("~/Views/Shared/InvalidAttempt.cshtml"));
            }
            picture.Comments.OrderByDescending(c => c.DateCreated);
            picture.User = await _repository.GetUserByIdAsync(picture.UserId);

            PictureDetailsVM pictureDetailsVM = new PictureDetailsVM(picture.UsersFavorite.Any(u => u.Id == currentUserId), currentUserId, isAdmin, picture);

            return(View(pictureDetailsVM));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AlbumDetails(Guid id)
        {
            ApplicationUser applicationUser = await _userManager.GetUserAsync(HttpContext.User);

            Guid currentUserId = new Guid(applicationUser.Id);

            if (!await _repository.ContainsUserAsync(currentUserId))
            {
                return(RedirectToAction("MakeNewProfile", "Main"));
            }
            Album album = await _repository.GetAlbumAsync(id);

            if (album == null)
            {
                return(View("~/Views/Shared/InvalidAttempt.cshtml"));
            }
            album.User = await _repository.GetUserByIdAsync(album.UserId);

            if (album.UserId == currentUserId)
            {
                return(RedirectToAction("Index", "ManageAlbum"));
            }
            AlbumVM        albumVM  = new AlbumVM(album);
            List <Picture> pictures = await _repository.GetPicturesFromAlbumAsync(id);

            List <PictureVM> picturesVM = new List <PictureVM>();

            foreach (var picture in pictures)
            {
                picturesVM.Add(new PictureVM(picture));
            }
            AlbumDetailsVM albumDetailsVM = new AlbumDetailsVM(album.UserId, album.User.UserName, albumVM, picturesVM);

            return(View(albumDetailsVM));
        }