Exemplo n.º 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                AccountServiceModel accountServiceModel = new AccountServiceModel();
                accountServiceModel.FirstName  = model.FirstName;
                accountServiceModel.LastName   = model.LastName;
                accountServiceModel.Address    = model.Address;
                accountServiceModel.BirthDay   = model.BirthDay;
                accountServiceModel.CritizenId = model.CritizenId;
                accountServiceModel.Email      = model.Email;
                accountServiceModel.UserName   = model.UserName;
                accountServiceModel.Password   = model.Password;

                AccountService accountService = new AccountService();
                if (accountService.RegisterAccount(accountServiceModel))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "UserName already exists.");
                    return(View(model));
                }
            }
            ModelState.AddModelError(string.Empty, "UserName already exists.");
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Main(string accountID, string signature, string msg_signature, string timestamp, string nonce, string echostr)
        {
            FileLogHelper.WriteInfo(string.Format("accountID:{0}\r\nsignature:{1}\r\ntimestamp:{2}\r\nnonce:{3}\r\nechostr:{4}\r\nmsg_signature:{5}",
                accountID, signature, timestamp, nonce, echostr, msg_signature));

            OperateStatus status;
            Guid aID;
            if (!Guid.TryParse(accountID, out aID))
            {
                status = new OperateStatus { ResultSign = ResultSign.Failed, Message = "账号不存在" };
            }
            else
            {
                AccountServiceModel model = new AccountServiceModel();
                var account = model.GetById(aID);
                if (account == null)
                {
                    return new ServiceResult(new OperateStatus { ResultSign = ResultSign.Failed, Message = "账户不存在" });
                }
                if (account.IsCorp)
                {
                    var func = FunctionFactory.GetFunctionInstance<Extentions.IFunction.Corp.Receive.IReceive>();
                    status = func.Main(account, msg_signature, timestamp, nonce, echostr);
                }
                else
                {
                    var func = FunctionFactory.GetFunctionInstance<Extentions.IFunction.Normal.Receive.IReceive>();
                    status = func.Main(account, signature, timestamp, nonce, echostr);
                }
            }

            FileLogHelper.WriteInfo(JsonConvert.SerializeObject(status));
            return new ServiceResult(status);
        }
        public AccountServiceModel GetAccountProfileByUserId(int id)
        {
            var reader = this.ExecuteReader(QueryConstants.GetAccountBillsByUserId, new Dictionary <string, object> {
                { "@userId", id }
            });
            var counter = 0;

            AccountServiceModel account = null;

            while (reader.Read())
            {
                counter++;

                if (counter == 1)
                {
                    var username  = (string)reader[0];
                    var firstName = (string)reader[1];
                    var lastName  = (string)reader[2];

                    account = new AccountServiceModel(username, firstName, lastName);
                }

                var IBAN   = (string)reader[3];
                var amount = (decimal)reader[4];

                var bill = new BillServiceModel(IBAN, amount);

                account.Bills.Add(bill);
            }

            return(account);
        }
Exemplo n.º 4
0
 public SearchController(IBlockInfoRepository blockInfoRepository,
                         TransactionServiceModel transactionServiceModel, AccountServiceModel accountServiceModel)
 {
     _blockInfoRepository     = blockInfoRepository;
     _transactionServiceModel = transactionServiceModel;
     _accountServiceModel     = accountServiceModel;
 }
Exemplo n.º 5
0
        public void UpdateAccount(AccountServiceModel account)
        {
            _unitOfWork.AddRepository <AccountEntityModel>();

            var accountEntity = _mapper.Map <AccountEntityModel>(account);

            _dateService.SetDateEditedNow(ref accountEntity);

            _unitOfWork.GetRepository <AccountEntityModel>().Update(accountEntity);
            _unitOfWork.Save();
        }
Exemplo n.º 6
0
        public async Task <bool> FindUserAsync(AccountServiceModel model)
        {
            _logger.LogInformation($"AccountService (FindUserAsync) - {model.Email}");
            var hashPassword = HashPasswordService.GetHshedPassword(model.Password);
            var user         = await Task.Run(() => _unitOfWork.Users.Get(u => u.Email == model.Email && u.Password == hashPassword).FirstOrDefault());

            if (user == null)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
0
        public int CreateAccount(AccountServiceModel account)
        {
            _unitOfWork.AddRepository <AccountEntityModel>();

            var accountEntity = _mapper.Map <AccountEntityModel>(account);

            _dateService.SetDateCreatedNow(ref accountEntity);

            _unitOfWork.GetRepository <AccountEntityModel>().AddItem(accountEntity);
            _unitOfWork.Save();

            return(accountEntity.Id);
        }
        public async Task AccountControllerShouldRegisterNewUser()
        {
            var registerViewModel = new RegisterViewModel
            {
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******"
            };

            var registerServiceModel = new RegisterServiceModel
            {
                Email    = "*****@*****.**",
                Password = "******",
            };

            var accountServiceModel = new AccountServiceModel
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var service = new Mock <IAccountService>();

            service.Setup(u => u.FindUserAsync(It.IsAny <AccountServiceModel>())).ReturnsAsync(false);

            service.Setup(m => m.RegisterUserAsync(registerServiceModel));

            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <AccountServiceModel>(registerViewModel)).Returns(accountServiceModel);
            mapper.Setup(m => m.Map <RegisterServiceModel>(registerViewModel)).Returns(registerServiceModel);

            var authorizationService = new Mock <IAuthorizationService>();
            var logger = new Mock <ILogger <AccountController> >();


            var controller = new AccountController(mapper.Object, service.Object, authorizationService.Object, logger.Object, null, null);
            var result     = await controller.Register(registerViewModel);

            service.Verify(u => u.RegisterUserAsync(registerServiceModel), Times.Once, "fail");
            Assert.IsType <OkResult>(result);
        }
Exemplo n.º 9
0
        public async Task AddUser(AccountServiceModel userSm)
        {
            var existingUsers = _repository.Where <Account>(
                a => a.ExternalId == userSm.ExternalId || a.Username == userSm.Username || a.Email == userSm.Email)
                                .ToArray();

            if (existingUsers.Length > 0)
            {
                var message = "User already exists. ";
                if (existingUsers[1].ExternalId == userSm.ExternalId)
                {
                    message += "User already registered";
                }
                if (existingUsers[1].Username == userSm.Username)
                {
                    message += "Username " + userSm.Username + " already in use.";
                }
                if (existingUsers[1].Email == userSm.Email)
                {
                    message += "Email " + userSm.Email + " already in use.";
                }
                throw new DuplicateUserException(message);
            }

            var user = new Account()
            {
                Username        = userSm.Username,
                FirstName       = userSm.FirstName,
                LastName        = userSm.LastName,
                ExternalId      = userSm.ExternalId,
                Email           = userSm.Email,
                Created         = DateTime.Now,
                ProfileImageUrl = userSm.ProfileImageUrl,
                LastLogin       = DateTime.Now,
                IsActive        = true
            };

            await _repository.Add(user);
        }
        public int EnactTransaction(AccountServiceModel sender, decimal amount, int currentUserId, string toIBAN, AccountServiceModel recipient = null)
        {
            int     senderTransactionId = int.MinValue;
            decimal unconvertedAmount   = amount;
            string  uniqueIdentifier    = Guid.NewGuid().ToString();

            using (var dbTransaction = _unitOfWork.BankContext.Database.BeginTransaction())
            {
                try
                {
                    _unitOfWork.AddRepository <AccountEntityModel>().AddRepository <TransactionEntityModel>();

                    var accountRepo     = _unitOfWork.GetRepository <AccountEntityModel>();
                    var transactionRepo = _unitOfWork.GetRepository <TransactionEntityModel>();

                    // deduct money from the senders account
                    sender.Balance -= amount;

                    if (recipient != null)
                    {
                        // give money to recipient
                        if (recipient.CurrencyId != sender.CurrencyId)
                        {
                            double rate = _currencyService.GetExchangeRate(sender.CurrencyId, recipient.CurrencyId);

                            // do we have the exchange rate
                            if (rate == double.MinValue)
                            {
                                // exchange rate should at least exist backwards
                                rate = _currencyService.GetExchangeRate(recipient.CurrencyId, sender.CurrencyId);

                                amount /= decimal.Parse(rate.ToString());
                            }
                            else
                            {
                                amount *= decimal.Parse(rate.ToString());
                            }
                        }

                        recipient.Balance += amount;

                        var recipientEntity = _mapper.Map <AccountEntityModel>(recipient);

                        accountRepo.Update(recipientEntity);

                        var recipientTransactionEntity = new TransactionEntityModel
                        {
                            AccountId   = recipientEntity.Id,
                            CurrencyId  = sender.CurrencyId,
                            Amount      = unconvertedAmount,
                            CreatedById = currentUserId,
                            UniqueTransactionIdentifier = uniqueIdentifier,
                            ToIBAN            = null,
                            TransactionTypeId = (int)TransactionTypeEnum.TransactionType.Debit
                        };

                        _dateService.SetDateCreatedNow(ref recipientTransactionEntity);
                        transactionRepo.AddItem(recipientTransactionEntity);
                    }

                    var senderEntity = _mapper.Map <AccountEntityModel>(sender);

                    accountRepo.Update(senderEntity);

                    var senderTransactionEntity = new TransactionEntityModel
                    {
                        AccountId   = senderEntity.Id,
                        CurrencyId  = sender.CurrencyId,
                        Amount      = unconvertedAmount,
                        CreatedById = currentUserId,
                        UniqueTransactionIdentifier = uniqueIdentifier,
                        ToIBAN            = toIBAN,
                        TransactionTypeId = (int)TransactionTypeEnum.TransactionType.Credit
                    };

                    _dateService.SetDateCreatedNow(ref senderTransactionEntity);
                    transactionRepo.AddItem(senderTransactionEntity);

                    _unitOfWork.Save();

                    senderTransactionId = senderTransactionEntity.Id;

                    dbTransaction.Commit();
                }
                catch (Exception)
                {
                    senderTransactionId = int.MinValue;
                    dbTransaction.Rollback();
                }
            }

            return(senderTransactionId);
        }
Exemplo n.º 11
0
 public AccountController(IDbContextCore dbContext, AccountServiceModel accountServiceModel)
 {
     _dbContext           = dbContext;
     _accountServiceModel = accountServiceModel;
 }