コード例 #1
0
        private void UpdateGameLoan(GameLoan gameLoan)
        {
            var currentGameLoan = GetCurrentGameLoan(gameLoan.Id);

            //If the game is being changed
            if (gameLoan.GameId != currentGameLoan.GameId)
            {
                //Releasing current game
                var loanedGame = GameRepository.FindGamesById(currentGameLoan.GameId);
                loanedGame.IsLent = false;
                GameRepository.Update(loanedGame);

                var game = GameRepository.FindGamesById(gameLoan.GameId);
                ValidateGameLoan(gameLoan, game);
                gameLoan.LoanDate = currentGameLoan.LoanDate;
                GameRepository.Update(loanedGame);
                GameLoanRepository.Update(gameLoan);
            }
            else
            {
                var game = GameRepository.FindGamesById(gameLoan.GameId);
                gameLoan.LoanDate = currentGameLoan.LoanDate;
                GameLoanRepository.Update(gameLoan);
            }
        }
コード例 #2
0
        public GameLoan Save(GameLoan gameLoan)
        {
            try
            {
                ApplicationDbContext.Database.BeginTransaction();
                Model.CheckModel(gameLoan);

                var game = GameRepository.FindGamesById(gameLoan.GameId);
                ValidateGameLoan(gameLoan, game);

                //Setting data
                game.IsLent         = true;
                gameLoan.LoanDate   = DateService.GetCurrentDate();
                gameLoan.ReturnDate = null;

                //Saving
                GameRepository.Update(game);
                GameLoanRepository.Save(gameLoan);

                ApplicationDbContext.Database.CommitTransaction();
            }
            catch (Exception e)
            {
                ApplicationDbContext.Database.RollbackTransaction();
                throw e;
            }

            return(gameLoan);
        }
コード例 #3
0
        private void RegisterGameReturn(GameLoan gameLoan)
        {
            var currentGameLoan = GetCurrentGameLoan(gameLoan.Id);

            if (currentGameLoan.IsActive)
            {
                var loanedGame = GameRepository.FindGamesById(currentGameLoan.GameId);
                loanedGame.IsLent   = false;
                gameLoan.IsActive   = false;
                gameLoan.LoanDate   = currentGameLoan.LoanDate;
                gameLoan.ReturnDate = DateService.GetCurrentDate();

                GameRepository.Update(loanedGame);
                GameLoanRepository.Update(gameLoan);
            }
        }
コード例 #4
0
        private GameLoan GetCurrentGameLoan(long id)
        {
            var currentGameLoan = GameLoanRepository.FindGameLoansById(id);

            if (currentGameLoan == null)
            {
                throw new GameManagerException(new List <ValidationError>()
                {
                    new ValidationError()
                    {
                        DataField = "Id",
                        ErrorMsg  = "Empréstimo inválido"
                    }
                });
            }

            return(currentGameLoan);
        }
コード例 #5
0
        public void Delete(GameLoan gameLoan)
        {
            try
            {
                ApplicationDbContext.Database.BeginTransaction();
                Model.CheckModel(gameLoan);

                gameLoan = ApplicationDbContext.GameLoans.Find(gameLoan.Id);
                var game = ApplicationDbContext.Games.Find(gameLoan.GameId);
                game.IsLent = false;
                GameRepository.Update(game);
                GameLoanRepository.Delete(gameLoan);
                ApplicationDbContext.Database.CommitTransaction();
            }
            catch (Exception e)
            {
                ApplicationDbContext.Database.RollbackTransaction();
                throw e;
            }
        }
コード例 #6
0
 public List <GameLoan> FindGameLoansTimeline(long?friendId, long?gameId)
 {
     return(GameLoanRepository.FindGameLoansTimeline(friendId, gameId));
 }
コード例 #7
0
 public PagedResult <GameLoan> FindUserGameLoansByDate(int page, int pageSize, DateTime?initialDate, DateTime?finalDate, long friendId)
 {
     return(GameLoanRepository.FindUserGameLoansByDate(page, pageSize, initialDate, finalDate, friendId));
 }
コード例 #8
0
 public PagedResult <GameLoan> FindGameLoansByDate(int page, int pageSize, DateTime?initialDate, DateTime?finalDate)
 {
     return(GameLoanRepository.FindGameLoansByDate(page, pageSize, initialDate, finalDate));
 }
コード例 #9
0
 public GameLoan FindGameLoanById(long id)
 {
     return(GameLoanRepository.FindGameLoansById(id));
 }