private void FirstTimeCheck()
        {
            var users = _repositoryUserCard.GetAll();

            if (users.Count() == 0)
            {
                _repositoryUserCard.Insert(new UserCard {
                    Balance = 100, CardNumber = 1111111111111111, LoginAttempts = 0, Blocked = false, Password = 1234
                });
                _repositoryUserCard.Insert(new UserCard {
                    Balance = 0, CardNumber = 1111111111111112, LoginAttempts = 0, Blocked = false, Password = 1234
                });
                _repositoryUserCard.Insert(new UserCard {
                    Balance = 200, CardNumber = 1111111111111113, LoginAttempts = 0, Blocked = false, Password = 1234
                });
                _repositoryUserCard.SaveChanges();
            }
            var codes = _repositoryOperationCode.GetAll();

            if (codes.Count() == 0)
            {
                _repositoryOperationCode.Insert(new OperationCode {
                    Description = "Balance"
                });
                _repositoryOperationCode.Insert(new OperationCode {
                    Description = "Withdraw"
                });
                _repositoryOperationCode.SaveChanges();
            }
        }
Exemple #2
0
        public DTOWithdrawResult WithDraw(long cardNumber, decimal amount)
        {
            var user = _repositoryUserCard.GetByCardNumber(cardNumber);

            if (user.Balance < amount)
            {
                return new DTOWithdrawResult {
                           Success = false, Message = "Your account balance is lower than " + amount
                }
            }
            ;
            else
            {
                user.Balance -= amount;

                _repositoryUserCard.Update(user);
                _repositoryUserCard.SaveChanges();

                Operation operation = new Operation {
                    IDCard = user.IDUserCard, IDOperationCode = Convert.ToInt32(EntitiesEnums.OperationCode.Withdraw), Amount = amount
                };
                _repositoryOperation.Insert(operation);
                _repositoryOperation.SaveChanges();
                return(new DTOWithdrawResult {
                    Success = true
                });
            }
        }