Пример #1
0
        public async Task ChangeCardPin(dynamic data)
        {
            try
            {
                string cardNum = data["card_num"];
                string newPin  = data["new_pin"];
                var    card    = await _unitOfWork.Repository <Card>().GetAsync(c => c.Number == cardNum);

                card.PinHash = CryptoHash.ComputeHash(newPin, new MD5CryptoServiceProvider());
                _unitOfWork.Repository <Card>().Update(card);
                await _unitOfWork.SaveChangesAsync();
            }
            catch (InvalidOperationException)
            {
                throw new Exception("Incorrect card number or new pin ");
            }
        }
Пример #2
0
        public async Task <User> LoginToAtm(dynamic data)
        {
            try
            {
                string cardNum = data["number"];
                string pin     = data["pincode"];


                var card = await _unitOfWork.Repository <Card>().GetAsync(
                    c => c.Number == cardNum && c.PinHash ==
                    CryptoHash.ComputeHash(pin, new MD5CryptoServiceProvider()));

                var ac = await _unitOfWork.Repository <Account>().GetAsync(
                    acc => acc.Id == card.AccountId);

                return(await _unitOfWork.Repository <User>().GetAsync(
                           user => user.Passport == ac.OwnerPassport));
            }
            catch (InvalidOperationException)
            {
                throw new Exception("Incorrect card number or pincode");
            }
        }