コード例 #1
0
        public IActionResult Update(GameViewModel gameViewModel)
        {
            if (!ModelState.IsValid)
            {
                gameViewModel.Authors = _authorRepository.GetAll();
                return(View(gameViewModel));
            }

            var game = gameViewModel.Game;

            var game2 = _favoriteRepository.GetAllChangesForGame(game.GameId);

            if (game2.Count() == 0)
            {
                _favoriteRepository.Create(new Favorites
                {
                    NewGame = new NamePrice
                    {
                        Name   = gameViewModel.Game.Name,
                        Price  = gameViewModel.Game.Price,
                        GameID = gameViewModel.Game.GameId
                    },

                    OldGame = new NamePrice {
                        Name = "UNregistered", Price = 0
                    },
                    Date = DateTime.Now
                });
            }
            else
            {
                var game1 = game2.First();

                var fav = new Favorites
                {
                    OldGame = new NamePrice
                    {
                        Name   = game1.NewGame.Name,
                        Price  = game1.NewGame.Price,
                        GameID = game1.NewGame.GameID
                    },
                    NewGame = new NamePrice
                    {
                        Name   = gameViewModel.Game.Name,
                        Price  = gameViewModel.Game.Price,
                        GameID = gameViewModel.Game.GameId
                    },
                    Date = DateTime.Now
                };

                _favoriteRepository.Create(fav);
            }

            _gameRepository.Update(gameViewModel.Game);

            return(RedirectToAction("List"));
        }
コード例 #2
0
        public FavoriteCreateResponse Create([FromBody] FavoriteCreateRequest request)
        {
            FavoriteCreateResponse response = new FavoriteCreateResponse();

            favoriteRepository.Create(favoriteConvertor.toEntity(request));

            response.Status = 1;
            return(response);
        }
コード例 #3
0
        public async Task <IActionResult> AddCourseToFavorites([FromBody] Favorite favorite)
        {
            var lang          = Request.Headers["language"].ToString();
            var errorMessages = new List <string>();

            try
            {
                if (string.IsNullOrEmpty(favorite.UserId) || favorite.CourseId == null)
                {
                    errorMessages.Add(_translator.GetTranslation("ERROR", lang));
                    return(BadRequest(new { errors = errorMessages }));
                }


                var user = await _userManager.FindByIdAsync(favorite.UserId);

                var course = _courseRepository.FindById(favorite.CourseId.Value);

                if (user == null || course == null)
                {
                    errorMessages.Add(_translator.GetTranslation("ERROR", lang));
                    return(BadRequest(new { errors = errorMessages }));
                }


                var newFavorite = new Favorite()
                {
                    Course   = course,
                    CourseId = course.Id,
                    User     = user,
                    UserId   = user.Id
                };

                var createdFavorite = _favoriteRepository.Create(newFavorite);
                return(Ok(new { createdFavorite }));
            }
            catch
            {
                errorMessages.Add(_translator.GetTranslation("ERROR", lang));
                return(BadRequest(new { errors = errorMessages }));
            }
        }
コード例 #4
0
        public async Task CreateOrDelete(string userId, string reviewId)
        {
            Guid userIdGuid   = Guid.Parse(userId);
            Guid reviewIdGuid = Guid.Parse(reviewId);

            Favorite insertedFavorite = await _favoriteRepository.GetByUserIdAndReviewId(userIdGuid, reviewIdGuid);

            if (insertedFavorite == null)
            {
                await ThrowIfReviewNotExists(reviewIdGuid);

                Favorite favorite = new Favorite(userIdGuid, reviewIdGuid);
                await _favoriteRepository.Create(favorite);

                await _favoriteRepository.Save();

                return;
            }

            _favoriteRepository.Delete(insertedFavorite);
            await _favoriteRepository.Save();
        }
コード例 #5
0
 public void AddFavorite(FavoriteEntity favorite)
 {
     favoriteRepository.Create(favorite.ToDalFavorite());
 }