public Account Create([FromBody] AddAccountModel model)
        {
            if (accountRepository.Exists(a => a.Email == model.Email))
            {
                ModelState.ThrowModelError("email", "Cet adresse électronique est déjà utilisée");
            }

            Account account = new Account
            {
                Name    = model.Name,
                Surname = model.Surname,
                Email   = model.Email
            };

            string username      = model.Name + model.Surname.Substring(0, 1).ToUpper() + model.Surname.Substring(1);
            long   usernameUsage = accountRepository.Count(a => a.Name == model.Name && a.Surname == model.Surname);

            if (usernameUsage == 0)
            {
                account.Username = username;
            }
            else
            {
                account.Username = username + usernameUsage;
            }

            string password = passwordHasher.HashPassword(account, model.Password);

            account.Password = password;

            account = accountRepository.Save(account);

            return(account);
        }
Exemple #2
0
        public JsonResult AddNewAccount(AddAccountModel accountmodel)
        {
            string errMessage = string.Empty;

            if (ModelState.IsValid)
            {
                var validation = SecurityController.ValidateToken(accountmodel.TokenCode);
                try
                {
                    if (validation.Validated == true)
                    {
                        var AccListResult = _db.Query <AccountResultModel>(";Exec Supreme_AddNewAccount @ClientID,@AccountName,@ProductID,@Address,@CityID,@CountryID,@Mobile,@OperatingModeID,@OperatorID",
                                                                           new
                        {
                            ClientID        = accountmodel.ClientID,
                            AccountName     = accountmodel.AccountName,
                            ProductID       = accountmodel.ProductID,
                            Address         = accountmodel.Address,
                            CityID          = accountmodel.CityID,
                            CountryID       = accountmodel.CountryID,
                            Mobile          = accountmodel.Mobile,
                            OperatingModeID = accountmodel.OperatingModeID,
                            OperatorID      = SecurityController.GetValidOperator(accountmodel.TokenCode).ToString()
                        }).SingleOrDefault();

                        logger.LogWrite(JsonConvert.SerializeObject(accountmodel).ToString() + ":-" + JsonConvert.SerializeObject(AccListResult).ToString());

                        return(Json(AccListResult, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        GenericResultModel AccListResult2 = new GenericResultModel();
                        AccListResult2.Status  = "Fail";
                        AccListResult2.Remarks = validation.Errors[0].ToString();
                        logger.LogWrite(JsonConvert.SerializeObject(validation).ToString());
                        return(Json(AccListResult2, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ee)
                {
                    GenericResultModel AccListResult2 = new GenericResultModel();
                    AccListResult2.Status  = "Fail";
                    AccListResult2.Remarks = ee.Message;
                    GeneralService.WriteErrorLog(ref ee);
                    return(Json(AccListResult2, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var message = string.Join(" | ", ModelState.Values
                                          .SelectMany(v => v.Errors)
                                          .Select(e => e.ErrorMessage));

                GenericResultModel AccListResult2 = new GenericResultModel();
                AccListResult2.Status  = "Fail";
                AccListResult2.Remarks = message;
                return(Json(AccListResult2, JsonRequestBehavior.AllowGet));
            }
        }
        public AddAccountViewModel(AddAccountModel model, IPleaseWaitService pleaseWaitService, IMessageService messageService)
        {
            AddAccount = model;

            _messageService    = messageService;
            _pleaseWaitService = pleaseWaitService;

            CreateAccountCommand = new Command(CreateAccount);
        }
        public ActionResult AccountAdd()
        {
            FillDropDownListForAccountView();
            var emptyAccount = new AddAccountModel
            {
                AccountMaxLeverage = 10
            };

            return(View(emptyAccount));
        }
        public async Task <IActionResult> AddAccount([FromBody] AddAccountModel model)
        {
            try
            {
                model.UserId = CurrentUserId;

                var result = await accountLib.AddAccountAsync(model);

                return(CustomResult(result));
            }
            catch (System.Exception exp)
            {
                return(CustomError(exp));
            }
        }
        public ActionResult AccountAdd(AddAccountModel account)
        {
            FillDropDownListForAccountView();
            if (!ModelState.IsValid)
            {
                return(View(account));
            }
            var viewModel = AccountUtils.GetAccountViewModel(accountRepository.GetFilterAccountFromServer(null));

            ResultMessage =
                accountRepository.AddAccount(account) ?
                Resource.MessageAccauntAdded :
                Resource.ErrorMessageAccauntAdded;

            return(View("Accounts", viewModel));
        }
Exemple #7
0
        public void BeforeEach()
        {
            IServiceCollection serviceCollection = ServiceConfiguration.InitServiceCollection();
            IServiceProvider   serviceProvider   = ServiceConfiguration.BuildServiceProvider();


            controller        = serviceProvider.GetRequiredService <AccountController>();
            accountRepository = serviceProvider.GetRequiredService <IRepository <Account, string> >();
            passwordHasher    = serviceProvider.GetRequiredService <IPasswordHasher <Account> >();

            model = new AddAccountModel
            {
                Email    = "*****@*****.**",
                Name     = "caleb",
                Surname  = "deGrace",
                Password = "******"
            };
        }
Exemple #8
0
        public async Task<AccountModel> AddAccountAsync(AddAccountModel model)
        {
            var entity = new Account
            {
                InitialAmount = model.InitialAmount,
                IsCredit = model.IsCredit,
                IsDebit = model.IsDebit,
                Name = model.Name,
                OveralTotal = model.OveralTotal,
                ParentAccountId = model.ParentAccountId,
                UserId = model.UserId
            };

            await accountRepo.AddAsync(entity);

            await unitOfWork.CommitAsync();

            return ConvertEntityToAccountModel(entity);
        }
        public async Task <AccountModel> Register([FromBody] AddAccountModel model)
        {
            ValidateInputModel();

            var accountFilter = new AccountFilter()
            {
                UserName = model.UserName
            };
            var accounts = await accountDao.Filter(accountFilter);

            if (accounts.Count > 0)
            {
                throw new DomainValidateException(new List <string>()
                {
                    AccountErrorMessages.REGISTER_EXIST_USERNAME
                });
            }

            var    passwordSalt = "-" + model.UserName + "-AuctionHub-" + model.UserName;
            string passwordHash = StringUtils.ComputeSha256Hash(model.Password + passwordSalt);

            var accountDto = new MdAccount()
            {
                Id           = ObjectId.GenerateNewId(),
                UserName     = model.UserName,
                PasswordSalt = passwordSalt,
                PasswordHash = passwordHash,
                Email        = model.Email,
                PhoneNumber  = model.PhoneNumber,
                CreatedAt    = DateTime.UtcNow,
                ModifiedAt   = DateTime.UtcNow
            };

            await accountDao.AddAsync(accountDto);

            var userAccountResponse = GetFromAccount(accountDto);

            return(userAccountResponse);
        }
        public async Task <ActionResult> Post([FromBody] AddAccountModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var exists = await _context.Customers.AnyAsync(x => x.Id == model.CustomerId);

            if (!exists)
            {
                return(NotFound("Customer not found"));
            }

            var account = new Account();

            account.CustomerId = model.CustomerId;
            _context.Accounts.Add(account);
            await _context.SaveChangesAsync();

            return(StatusCode(201, account.Id));
        }
Exemple #11
0
        public void TestBlueSky_SaveAccount()
        {
            //set-up
            IAccountService service = MockAccountService.Singleton;

            AddAccountModel = new AddAccountModel();
            AddAccountModel.AccountBalance = 100m;
            AddAccountModel.CompanyName    = "test";
            AddAccountModel.InterestRate   = 2m;
            AddAccountModel.FirstDueDate   = new DateTime(2017, 05, 05);
            AddAccountModel.AmountDue      = 10m;

            //exercise
            Presenter.SaveAccount(AddAccountModel);

            //post-conditions
            IAccount account = service.GetAccount(1);

            Assert.AreEqual(account.AccountBalance, AddAccountModel.AccountBalance);
            Assert.AreEqual(account.CompanyName, AddAccountModel.CompanyName);
            Assert.AreEqual(account.InterestRate, AddAccountModel.InterestRate);
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (EditMode)
            {
                AccountModel accountModel = tableLayoutPanelAccount.Tag as AccountModel;
                accountModel.AccountBalance = decimal.Parse(textBoxBalance.Text);
                accountModel.CompanyName    = textBoxName.Text;
                accountModel.InterestRate   = decimal.Parse(textBoxInterestRate.Text);
                Presenter.EditAccount(accountModel);
                Close();
                return;
            }

            AddAccountModel model = new AddAccountModel();

            model.AccountBalance = decimal.Parse(textBoxBalance.Text);
            model.CompanyName    = textBoxName.Text;
            model.InterestRate   = decimal.Parse(textBoxInterestRate.Text);
            model.FirstDueDate   = DateTime.Parse(textBoxFirstDueDate.Text);
            model.AmountDue      = decimal.Parse(textBoxAmountDue.Text);

            Presenter.SaveAccount(model);
            Close();
        }
        public bool AddAccount(AddAccountModel newAccount)
        {
            // В данном методе напрямую с БД не работаем - работаем через прокси
            // Сформированный JSON отправляется на сервер терминала
            const string queryPtr = "/?formatquery=1&register=1";

            var urlSrv   = AppConfig.GetStringParam("Env.TradeSharpServiceUrl", "http://10.5.237.10:8061");
            var userName = AppConfig.GetStringParam("Env.TradeSharpUser", "forexinvest\\asitaev");
            var userPwrd = AppConfig.GetStringParam("Env.TradeSharpPwrd", "AndSit!qa");


            if (newAccount == null)
            {
                Logger.Error("AddAccount. Ошибка добавления аккаунта. Объект модели равен null");
                return(false);
            }

            var newAccountParamList = new List <HttpParameter>
            {
                new RegisterAccountQuery
                {
                    #region быстрая инициализация свойств
                    Balance     = newAccount.AccountBalance,
                    Group       = newAccount.AccountGroup,
                    Currency    = newAccount.AccountCurrency,
                    MaxLeverage = newAccount.AccountMaxLeverage,

                    UserLogin       = newAccount.UserLogin,
                    UserPassword    = newAccount.UserPassword,
                    UserName        = newAccount.UserName,
                    UserSurname     = newAccount.UserSurname,
                    UserPatronym    = newAccount.UserPatronym,
                    UserDescription = newAccount.UserDescription,
                    UserEmail       = newAccount.UserEmail,
                    UserPhone1      = newAccount.UserPhone1,
                    UserPhone2      = newAccount.UserPhone2,
                    UserRightsMask  = newAccount.UserRightsMask,
                    UserRoleMask    = newAccount.UserRoleMask,
                    #endregion
                }
            };

            try
            {
                string rawData;

                var result = HttpParameter.DeserializeServerResponse(urlSrv + queryPtr, newAccountParamList, out rawData, userName, userPwrd);
                var report = (ExecutionReport)result.FirstOrDefault(p => p is ExecutionReport);

                if (report != null)
                {
                    if (!report.IsOk)
                    {
                        Logger.Error("Ошибка: " + report.Comment);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("AddAccount(). Ошибка добавления аккаунта", ex);
            }
            try
            {
                if (newAccount.WalletBalance < 0)
                {
                    Logger.Error("AddAccount(). Не удалось зачислить средства на кошелёк пользователя - невозможно зачислить отридцательную сумму.");
                    return(false);
                }
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var userId = ctx.PLATFORM_USER.Single(x => x.Login == newAccount.UserLogin);
                    var wallet = ctx.WALLET.Single(w => w.User == userId.ID);
                    wallet.Balance = (decimal)newAccount.AccountBalance;
                    ctx.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error("AddAccount() - не удалось зачислить средства на кошелёк пользователя", ex);
            }
            return(false);
        }
Exemple #14
0
        public async Task <AccountModel> AddAccount(AddAccountModel model)
        {
            var result = await _requestManagerService.Post <ServiceResponse <AccountModel> >("/accounts_add", model);

            return(result.DataModel);
        }
Exemple #15
0
        private void AddAccount()
        {
            AddAccountModel model = new AddAccountModel();

            _uiVisualizerService.ShowDialog(new AddAccountViewModel(model, _pleaseWaitService, _messageService));
        }
 public void SetUp()
 {
     Model = new AddAccountModel();
 }
Exemple #17
0
 public IActionResult AddAccount([FromBody] AddAccountModel model)
 {
     return(Ok(_accountService.AddAccount(model.UserId, model.Amount)));
 }