Esempio n. 1
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
                });
            }
        }
        public DTOLoginResult Login(long cardNumber, int password)
        {
            var entity = _repositoryUserCard.GetByCardNumber(cardNumber);

            if (entity == null)
            {
                return new DTOLoginResult {
                           Sucess = false
                }
            }
            ;
            else
            {
                if (entity.Blocked)
                {
                    return new DTOLoginResult {
                               Sucess = false, Blocked = true
                    }
                }
                ;

                if (entity.Password == password)
                {
                    entity.LoginAttempts = 0;

                    _repositoryUserCard.Update(entity);
                    _repositoryUserCard.SaveChanges();
                    return(new DTOLoginResult {
                        Sucess = true, CardNumber = entity.CardNumber
                    });
                }
                else
                {
                    entity.LoginAttempts++;
                    entity.Blocked = entity.LoginAttempts >= 4;
                    _repositoryUserCard.Update(entity);
                    _repositoryUserCard.SaveChanges();
                    return(new DTOLoginResult {
                        Sucess = false, Blocked = entity.Blocked, Message = "Wrong password. Please try again."
                    });
                }
            }
        }
    }