Esempio n. 1
0
 public async Task <IActionResult> Post([FromBody] AccountInfoDto account)
 {
     try
     {
         return(Ok(await _userService.AddAccount(_mapper.Map <AccountInfo>(account))));
     } catch (Exception ex) {
         return(BadRequest(ex.ToString()));
     }
 }
Esempio n. 2
0
        public void TestBlueSky_AddAccount()
        {
            // set-up
            IAccount account = CreateAccount();

            // pre-conditions
            Assert.IsNull(AccountService.GetAccount(account.RecordId));

            // exercise
            AccountService.AddAccount(account);
            IAccount persistedAccount = AccountService.GetAccount(account.RecordId);

            // post-conditions
            Assert.AreEqual(persistedAccount, account);
        }
        public ActionResult Post([FromBody] CreateAccountModel createAccountModel)
        {
            if (!_customerService.CheckIfCustomerExists(createAccountModel.CustomerId))
            {
                return(BadRequest("Customer could not be found."));
            }
            var result = _accountService.AddAccount(createAccountModel.CustomerId, createAccountModel.InitialCredit);

            return(Ok(result));
        }
Esempio n. 4
0
        public async Task <ActionResult> Register(RegisterModel model)
        {
            var result = await _accountService.AddAccount(_mapper.Map <AccountDto>(model), _httpContextAccessor);

            if (result)
            {
                return(CreatedAtAction(nameof(Get), true));
            }
            return(BadRequest());
        }
        public void AddAccountCheckDb()
        {
            Currency currency = context.Currencies.FirstOrDefault();
            Account  account  = accountService.CreateAccount(new User(), currency);

            accountService.AddAccount(account);
            Account accountInDb = context.Accounts.FirstOrDefault(a => a.Id == account.Id);

            Assert.NotNull(accountInDb);
        }
Esempio n. 6
0
        protected void CreateAccountData()
        {
            IAccountService service = MockAccountService.Singleton;
            IAccount        account = new Account();

            account.CompanyName    = "Haribo";
            account.AccountBalance = 200.00m;
            account.InterestRate   = 3.9m;
            account.GeneratePaymentSchedule(DateTime.Now, 20.00m);
            service.AddAccount(account);
        }
Esempio n. 7
0
 private void Add()
 {
     AccountEditRequest.Raise(new AccountConfirmation(), x =>
     {
         if (x.Confirmed)
         {
             _accountService.AddAccount(x.Account);
             Items.Add(x.Account);
             Search();
         }
     });
 }
 public IHttpActionResult Add(Account account)
 {
     try
     {
         _service.AddAccount(account);
         return(Ok());
     }
     catch
     {
         return(InternalServerError());
     }
 }
Esempio n. 9
0
 public IActionResult Add([FromBody] AccountViewModel model)
 {
     try
     {
         var acc = service.AddAccount(model);
         return(CreatedAtAction(nameof(GetById), new { id = acc.Id }, ResponceViewModel <AccountViewModel> .GenerateRepsonce(acc)));
     }
     catch (Exception ex)
     {
         logger.LogError($"Exception thrown in add account: {ex}");
         return(BadRequest(ResponceViewModel <string> .GenerateError($"Error in add account:{ex.Message}")));
     }
 }
        public async Task <IActionResult> AddAccount(AddAccountViewModel accountModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Account model is not valid."));
            }
            else
            {
                var account = AddAccountToAccountDTOMapper.Instance.Map(accountModel);
                await accountService.AddAccount(account);

                return(RedirectToAction(nameof(GetAllAccounts)));
            }
        }
Esempio n. 11
0
        public async Task <IActionResult> AddAccount([FromBody] AccountRequestDto account)
        {
            AccountResponseDto createdAccount = await _service.AddAccount(account);

            if (createdAccount == null)
            {
                return(BadRequest(new
                {
                    Data = "Account already exists",
                    StatusCode = HttpStatusCode.BadRequest,
                    Message = ResponseMessages.FAILED
                }));
            }
            return(Ok(new { Data = createdAccount, StatusCode = (int)HttpStatusCode.Created, ResponseMessages.CREATED }));
        }
Esempio n. 12
0
        internal static List <Account> SetupAccounts(IAccountService accountService, IFacilityService facilityService, IClientRepository clientRepository)
        {
            clientRepository.AddClient(GenerateClient(1));
            clientRepository.AddClient(GenerateClient(6));
            var accounts = new List <Account>();

            for (int x = 0; x < 10; x++)
            {
                facilityService.AddFacility(GenerateFacility(x));
                var account = GenerateAccount(x, facilityService, clientRepository);
                accountService.AddAccount(account);
                accounts.Add(account);
            }

            return(accounts);
        }
        public async Task <IActionResult> AddRegularAccount([FromForm][Required] string username,
                                                            [FromForm][Required] string password,
                                                            [FromForm][Required] string phone_number,
                                                            [FromForm][Required] string email)
        {
            var _account = new AddAccountDto()
            {
                Name        = username,
                Password    = password,
                PhoneNumber = phone_number,
                Email       = email,
                AccountRole = AccountRoles.Regular
            };
            var serviceResponse = await accountService.AddAccount(_account);

            var controllerResponse = mapper.Map <ServiceResponse, ControllerResponse>(serviceResponse);

            return(StatusCode(serviceResponse.StatusCode, controllerResponse));
        }
Esempio n. 14
0
        private void btnAddAccount_Click(object sender, EventArgs e)
        {
            string userName = txbUserName.Text.ToString();
            int    temp     = (int)numericUpDownType.Value;
            bool   type     = Convert.ToBoolean(temp);
            bool   test     = _accountService.AddAccount(userName, type);

            if (test == true)
            {
                MessageBox.Show("Thêm tài khoản thành công");
            }
            else
            {
                MessageBox.Show("Tài khoản đã trùng tên, vui lòng thay đổi thông tin");
            }

            txbUserName.DataBindings.Clear();
            ListAccount();
            txbUserName.DataBindings.Add(new Binding("Text", dtgvAccount.DataSource, "userName", true, DataSourceUpdateMode.Never));
        }
        public async Task <IActionResult> Token([FromBody] AccountModel accountModel)
        {
            var accountValid = await ValidateAccount(accountModel.Name, accountModel.AccessToken);

            if (!accountValid)
            {
                return(BadRequest("Accesstoken not matching Account"));
            }

            var account = await _accountService.GetAccount(accountModel.Name);

            if (account == null)
            {
                account = await _accountService.AddAccount(accountModel);
            }

            var token = AuthHelper.GenerateToken(_secret, account);

            account.AccessToken = token;

            return(Ok(account));
        }
Esempio n. 16
0
        public AccountModule(IAccountService accountService)
        {
            _accountService = accountService;

            /// <summary>
            /// Adds account to repository.  Body must contain Query string of name="AccountNameHere"&pwd="PasswordHere"
            /// </summary>
            Post("Account/Add", async(args, ct) =>
            {
                var request = Nancy.Extensions.RequestStreamExtensions.AsString(Nancy.IO.RequestStream.FromStream(this.Request.Body));
                NameValueCollection coll = HttpUtility.ParseQueryString(request);
                var name = coll["name"];
                var pwd  = coll["pwd"];
                Task <ActionResult <Account> > addTask = _accountService.AddAccount(name, pwd);
                ActionResult <Account> addResult       = await addTask;
                if (addResult.statusCode != (System.Net.HttpStatusCode)HttpStatusCode.Created)
                {
                    return(addResult.statusCode);
                }
                var account = addResult.resposeObject;

                var links = new List <HyperMedia> {
                    new HyperMedia {
                        Href = this.Request.Url,
                        Rel  = "self"
                    },
                    new HyperMedia {
                        Href = $"{this.Request.Url.SiteBase}/Account/{account.Id}/Update",
                        Rel  = "edit"
                    }
                };

                return(Response.AsJson(new { account = account, links = links }));
            });

            /// <summary>
            /// Updates account on registry.  Body must contain Query string of name="AccountNameHere"&pwd="PasswordHere"
            /// </summary>
            Put("Account/{accountId}/Update", async(args, ct) =>
            {
                var request = Nancy.Extensions.RequestStreamExtensions.AsString(Nancy.IO.RequestStream.FromStream(this.Request.Body));
                NameValueCollection coll = HttpUtility.ParseQueryString(request);
                var name = coll["name"];
                var pwd  = coll["pwd"];
                Task <ActionResult <Account> > updateTask = _accountService.UpdateAccount(args.accountId, name, pwd);
                ActionResult <Account> updatResult        = await updateTask;
                if (updatResult.statusCode != (System.Net.HttpStatusCode)HttpStatusCode.OK)
                {
                    return(updatResult.statusCode);
                }
                var account = updatResult.resposeObject;
                var links   = new List <HyperMedia> {
                    new HyperMedia {
                        Href = this.Request.Url,
                        Rel  = "self"
                    },
                    new HyperMedia {
                        Href = $"{this.Request.Url.SiteBase}/Account/Add",
                        Rel  = "add"
                    }
                };
                return(Response.AsJson(new { account = account, links = links }));
            });
        }
Esempio n. 17
0
 public async Task <IActionResult> Add([FromBody] Accounts accounts)
 {
     return(Ok(await _accountService.AddAccount(accounts)));
 }
Esempio n. 18
0
 public Account Post([FromBody] Account account)
 {
     return(_accountService.AddAccount(account));
 }
Esempio n. 19
0
 public async Task <int> Create(CreateAccountModel model)
 {
     return(await accService.AddAccount(model.Username,
                                        model.Password,
                                        model.Displayname));
 }
Esempio n. 20
0
        public async Task <ApiDataResponse <AccountDTO> > AddAccount([FromBody] AccountDTO account)
        {
            await accountService.AddAccount(account);

            return(new ApiDataResponse <AccountDTO>(account));
        }
Esempio n. 21
0
 public IActionResult AddAccount([FromBody] AddAccountModel model)
 {
     return(Ok(_accountService.AddAccount(model.UserId, model.Amount)));
 }
Esempio n. 22
0
        public async Task <IActionResult> AddAccount(AccountAddModel account)
        {
            var result = await accountService.AddAccount(account);

            return(result == null?Ok(new { message = "Adding account was successful" }) : (IActionResult)Conflict(new { message = "User already has account with this name" }));
        }
 public JsonResult Post([FromBody] AddAccountRequest request)
 {
     return(Json(_accountService.AddAccount(request)));
 }
Esempio n. 24
0
 public Guid Add(AccountModel model)
 {
     return(_accountService.AddAccount(model));
 }