Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Event).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(Event.Id))
                {
                    return(RedirectToPage("/Admin/Events/Index"));
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            if (!ModelState.IsValid)
            {
                SetDropdownLists();

                return(Page());
            }

            var game = new Game
            {
                Id          = Input.Id,
                Title       = Input.Title,
                Developer   = Input.Developer,
                Description = Input.Description,
                PlatformId  = Input.PlatformId,
                CategoryId  = Input.CategoryId,
                Price       = Input.Price
            };

            _context.Attach(game).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(game.Id))
                {
                    return(RedirectToPage("/Admin/Games/Index"));
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostReviewGameAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(RedirectToPage("/Account/Login"));
            }

            Game = await _context.GetGameAsync(Id);

            if (Game == null)
            {
                return(NotFound());
            }

            CanReview = await _context.DoesUserOwnGameAsync(user, Game);

            Reviews = await _context.GetGameReviewsAsync(Game);

            if (!CanReview)
            {
                StatusMessage = $"Error: You are not able to review this game.";
                return(RedirectToPage());
            }

            var review = Reviews.FirstOrDefault(r => r.Reviewer == user);

            HasReview = review == null ? false : true;

            try
            {
                if (HasReview)
                {
                    review.ReviewStatus = ReviewStatus.Pending;
                    review.Content      = Review.Content ?? "No review.";
                    review.Rating       = Review.Rating;

                    _context.Attach(review).State = EntityState.Modified;

                    StatusMessage = $"Review saved and is currently pending. Please wait for an administrator to accept it.";
                }
                else
                {
                    await _context.Reviews.AddAsync(new Review { ReviewerId = user.Id, GameId = Game.Id, Content = Review.Content ?? "No review.", Rating = Review.Rating });

                    StatusMessage = $"Review posted and is currently pending. Please wait for an administrator to accept it.";
                }

                await _context.SaveChangesAsync();

                return(RedirectToPage());
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(Review.Id))
                {
                    StatusMessage = $"Error: An unknown error has occurred while trying to post your review.";
                    return(RedirectToPage());
                }
                else
                {
                    throw;
                }
            }
        }