Esempio n. 1
0
        public ActionResult MyListChangeRating(int?id, int?selectedRating)
        {
            string userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(View("Error"));
            }

            if (selectedRating == null)
            {
                using (var userGameRatingService = new UserGameRatingService())
                {
                    var existingUserGameRating = userGameRatingService.GetExistingUserGameRating(userId, (int)id);
                    if (existingUserGameRating != null)
                    {
                        var dbUserGameRating = userGameRatingService.GetByID(existingUserGameRating.Id);
                        userGameRatingService.Delete(dbUserGameRating);
                        userGameRatingService.Save();
                    }
                }
            }

            if (selectedRating != null)
            {
                int gameRatingIdToStore;
                using (var gameRatingService = new GameRatingService())
                {
                    gameRatingIdToStore = gameRatingService.GetGameRatingByRating((int)selectedRating);
                }
                using (var userGameRatingService = new UserGameRatingService())
                {
                    var dbUserGameRating = userGameRatingService.GetExistingUserGameRating(userId, (int)id);
                    if (dbUserGameRating == null)
                    {
                        var userGameRating = new UserGameRating
                        {
                            UserId       = userId,
                            GameId       = (int)id,
                            GameRatingId = gameRatingIdToStore
                        };
                        userGameRatingService.Add(userGameRating);
                        userGameRatingService.Save();
                    }
                    else
                    {
                        var dbUGRToStore = userGameRatingService.GetByID(dbUserGameRating.Id);
                        dbUGRToStore.GameRatingId = gameRatingIdToStore;
                        userGameRatingService.Save();
                    }
                }
            }
            return(RedirectToAction("MyList", "Account"));
        }
Esempio n. 2
0
        public ActionResult RemoveFromList(int?id, string uid)
        {
            try
            {
                UserGameRating userGameRating = null;
                using (var userRatingService = new UserGameRatingService())
                {
                    userGameRating = userRatingService.GetExistingUserGameRating(User.Identity.GetUserId(), (int)id);
                }
                using (var userRatingService = new UserGameRatingService())
                {
                    if (userGameRating != null)
                    {
                        userRatingService.Delete(userGameRating);
                        userRatingService.Save();
                    }
                }
                UserGameStatus userGameStatus = null;
                using (var userStatusService = new UserGameStatusService())
                {
                    userGameStatus = userStatusService.GetExistingUserGameStatus(User.Identity.GetUserId(), (int)id);
                }

                using (var userStatusService = new UserGameStatusService())
                {
                    userStatusService.Delete(userGameStatus);
                    userStatusService.Save();
                }
                return(RedirectToAction("MyList"));
            }
            catch
            {
                ModelState.AddModelError("", "Database error!");
                return(View("RemoveFromList", id));
            }
        }
        public ActionResult Details(int?id, GameViewModel gameViewModel)
        {
            string userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(View("Error"));
            }
            if (id == null || id <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (gameViewModel.SelectedStatus != null)
            {
                int gameStatusIdToStore = int.Parse(gameViewModel.SelectedStatus);
                //using (var gameStatusService = new GameStatusService())
                //{
                //    gameStatusIdToStore = gameStatusService.GetStatusIdBySelectedStatus(gameViewModel.SelectedStatus);
                //}
                using (var userGameStatusService = new UserGameStatusService())
                {
                    var dbUserGameStatus = userGameStatusService.GetExistingUserGameStatus(userId, (int)id);
                    if (dbUserGameStatus == null)
                    {
                        var userGameStatus = new UserGameStatus
                        {
                            UserId       = userId,
                            GameId       = (int)id,
                            GameStatusId = gameStatusIdToStore
                        };
                        userGameStatusService.Add(userGameStatus);
                        userGameStatusService.Save();
                    }
                    else
                    {
                        var dbUGSToStore = userGameStatusService.GetByID(dbUserGameStatus.Id);
                        dbUGSToStore.GameStatusId = gameStatusIdToStore;
                        userGameStatusService.Save();
                    }
                }
            }

            if (gameViewModel.SelectedRating == 0)
            {
                using (var userGameRatingService = new UserGameRatingService())
                {
                    var existingUserGameRating = userGameRatingService.GetExistingUserGameRating(userId, (int)id);
                    if (existingUserGameRating != null)
                    {
                        var dbUserGameRating = userGameRatingService.GetByID(existingUserGameRating.Id);
                        userGameRatingService.Delete(dbUserGameRating);
                        userGameRatingService.Save();
                    }
                }
            }

            if (gameViewModel.SelectedRating != 0)
            {
                int gameRatingIdToStore;
                using (var gameRatingService = new GameRatingService())
                {
                    gameRatingIdToStore = gameRatingService.GetGameRatingByRating((int)gameViewModel.SelectedRating);
                }
                using (var userGameRatingService = new UserGameRatingService())
                {
                    var dbUserGameRating = userGameRatingService.GetExistingUserGameRating(userId, (int)id);
                    if (dbUserGameRating == null)
                    {
                        var userGameRating = new UserGameRating
                        {
                            UserId       = userId,
                            GameId       = (int)id,
                            GameRatingId = gameRatingIdToStore
                        };
                        userGameRatingService.Add(userGameRating);
                        userGameRatingService.Save();
                    }
                    else
                    {
                        var dbUGRToStore = userGameRatingService.GetByID(dbUserGameRating.Id);
                        dbUGRToStore.GameRatingId = gameRatingIdToStore;
                        userGameRatingService.Save();
                    }
                }
            }
            return(RedirectToAction("Details", "Games"));
        }