Exemple #1
0
        public async ValueTask Setup()
        {
            _mapper            = Resolve <IMapper>();
            _leadRepository    = Resolve <ILeadRepository>();
            _accountRepository = Resolve <IAccountRepository>();
            _systemUnderTest   = new LeadController(_leadRepository, _accountRepository, _mapper, _urlOptions);
            await DropOrRestoreTestDbs("Dbs_Restore");

            _leadForTest      = (LeadInputModel)LeadInputModelMock.leadInputModel.Clone();
            _accountIMForTest = (AccountInputModel)AccountInputModelMock.accountInputModel.Clone();

            foreach (var item in LeadInputModelMock.leadsToInsertForSearchTest)
            {
                _leadsToInsertForSearch.Add((LeadInputModel)item.Clone());
            }

            foreach (var leadModel in _leadsToInsertForSearch)
            {
                ActionResult <LeadOutputModel> leadsInsertActionResult
                    = await _systemUnderTest.AddLead(leadModel);

                LeadOutputModel outputLead = AssertAndConvert(leadsInsertActionResult);
                leadModel.Id = outputLead.Id;
                _leadsForCompare.Add(outputLead);
                _accountIMForTest.LeadId = (long)outputLead.Id;
                ActionResult <AccountOutputModel> accountForSearchActionResult = await _systemUnderTest.AddAccount(_accountIMForTest);

                var accountForSearch = AssertAndConvert(accountForSearchActionResult);
                _accountsOMForTest.Add(accountForSearch);
            }
        }
        public ActionResult <AccountInputModel> ImplicitInputValidation([FromQuery] AccountInputModel model)
        {
            // try the following url: mvc/implicit-input-validation
            // note: with the above url you won't even hit this breakpoint - the framework will not even call our Action method

            return(model);
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var isAuthorize = User.IsInRole(Constants.AdministratorRole);

            if (!isAuthorize)
            {
                return(new ChallengeResult());
            }

            var pageResult = await LoadPageData(id.Value);

            if (WorkerCrossPageData == null)
            {
                return(NotFound());
            }

            Account = new AccountInputModel
            {
                WorkerId = WorkerCrossPageData.WorkerID
            };

            return(pageResult);
        }
Exemple #4
0
        public async ValueTask <ActionResult <AccountOutputModel> > AddAccount(AccountInputModel accountInputModel)
        {
            string URIdeposit = $"api/transaction/initialize";

            if (accountInputModel.CurrencyId < 1)
            {
                return(BadRequest("Account cannot be added"));
            }
            var result = await _accountRepository.AddAccount(_mapper.Map <Account>(accountInputModel));

            TransactionEntityInputModel transactionEntityInputModel = new TransactionEntityInputModel {
                Amount = 19000
            };

            if (result.IsOkay)
            {
                if (result.RequestData == null)
                {
                    return(Problem($"Added account not found", statusCode: 520));
                }

                transactionEntityInputModel.Account = new AccountShortInputModel
                {
                    Id         = (long)result.RequestData.Id,
                    CurrencyId = result.RequestData.Currency.Id
                };
                var requestResult = await RequestSender.SendRequest <TransactionEntityOutputModel>(_urlOptions.Value.TransactionStoreApiUrl, URIdeposit, Method.POST, transactionEntityInputModel);

                if (requestResult.IsSuccessful)
                {
                    return(Ok(_mapper.Map <AccountOutputModel>(result.RequestData)));
                }
            }
            return(Problem($"Transaction failed {result.ExMessage}", statusCode: 520));
        }
Exemple #5
0
        public async Task <IActionResult> Create(AccountInputModel acount)
        {
            if (!ModelState.IsValid)
            {
                var error = new { Message = ModelState.Values };
                return(BadRequest(error));
            }

            try
            {
                var userId = base.GetUserIdFromAuthorizeHeader();

                var acountModel = new Account
                {
                    Name   = acount.Name,
                    UserId = userId,
                };
                await accountsService.Create(acountModel);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #6
0
        protected void DeepEqualForAccountModels(AccountInputModel inputModel, AccountOutputModel outputModel)
        {
            Assert.NotNull(outputModel.CurrencyCode);
            var model  = mapper.Map <Account>(inputModel);
            var model1 = mapper.Map <AccountOutputModel>(model);

            Assert.IsTrue(model1.EqualsForAccountTest(outputModel));
        }
        public IActionResult PostAccount([FromBody] AccountInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(_utilityAppService.CreateNewAccount(model)));
        }
Exemple #8
0
 public void ProcessAccountCheckout(AccountInputModel account)
 {
     if (string.IsNullOrEmpty(account.FirstName))
     {
         throw new Exception("First name is missing");
     }
     if (string.IsNullOrEmpty(account.LastName))
     {
         throw new Exception("Last name is missing");
     }
     if (string.IsNullOrEmpty(account.Email))
     {
         throw new Exception("Email is missing");
     }
     if (string.IsNullOrEmpty(account.BillingAddressStreet))
     {
         throw new Exception("Street is missing");
     }
     if (string.IsNullOrEmpty(account.BillingAddressHouseNumber))
     {
         throw new Exception("House number is missing");
     }
     if (string.IsNullOrEmpty(account.BillingAddressCity))
     {
         throw new Exception("City is missing");
     }
     if (string.IsNullOrEmpty(account.BillingAddressCountry))
     {
         throw new Exception("Country is missing");
     }
     if (string.IsNullOrEmpty(account.BillingAddressZipCode))
     {
         throw new Exception("Postal code is missing");
     }
     if (string.IsNullOrEmpty(account.DeliveryAddressStreet))
     {
         throw new Exception("Street is missing");
     }
     if (string.IsNullOrEmpty(account.DeliveryAddressHouseNumber))
     {
         throw new Exception("House number is missing");
     }
     if (string.IsNullOrEmpty(account.DeliveryAddressCity))
     {
         throw new Exception("City is missing");
     }
     if (string.IsNullOrEmpty(account.DeliveryAddressCountry))
     {
         throw new Exception("Country is missing");
     }
     if (string.IsNullOrEmpty(account.DeliveryAddressZipCode))
     {
         throw new Exception("Postal code is missing");
     }
 }
Exemple #9
0
        public ActionResult Register(AccountInputModel model)
        {
            var account = Mapper.Map <AccountInputModel, Account>(model);

            account.IsConfirm        = false;
            account.HashConfirmation = CreateHastConfirmationString();
            account = _writeOnlyRepository.Create(account);

            //enviar email para confirmar
            // si paso el email
            return(View());
        }
Exemple #10
0
        public async Task <IdentityResult> UpdateSecurity(AccountInputModel account)
        {
            IdentityResult result = new IdentityResult();
            IdentityUser   user   = await UserManager.FindByNameAsync(account.Username).ConfigureAwait(false);

            if (user != null && await UserManager.CheckPasswordAsync(user, account.OldPassword).ConfigureAwait(false))
            {
                result = await UserManager.ChangePasswordAsync(user, account.OldPassword, account.Password);
            }

            return(result);
        }
Exemple #11
0
        public async Task <IActionResult> UpdateSecurity([FromForm] AccountInputModel account)
        {
            IdentityResult result = await AuthService.UpdateSecurity(account).ConfigureAwait(false);

            if (result.Succeeded)
            {
                return(Ok("Password aggiornata correttamente"));
            }
            else
            {
                return(BadRequest(result.Errors));
            }
        }
Exemple #12
0
        public ResponseViewModel CreateNewAccount(AccountInputModel account)
        {
            var valid = _utiityService.GetAccounts().FirstOrDefault(x => x.Name == account.AccountName &&
                                                                    x.Number == account.AccountNumber);

            if (valid != null)
            {
                return(Failed(ResponseMessageViewModel.ACCOUNT_ALREADY_EXITS));
            }

            return(Ok(_mapper.Map <Account, AccountViewModel>
                          (_utiityService.Create(_mapper.Map <AccountInputModel, Account>(account)))));
        }
Exemple #13
0
        public async Task <IActionResult> Register(AccountInputModel input)
        {
            IdentityResult result = await AuthService.Register(input).ConfigureAwait(false);

            if (result.Succeeded)
            {
                return(Ok("Account successfuly created."));
            }
            else
            {
                return(BadRequest(result.Errors));
            }
        }
        public IActionResult Checkout(AccountInputModel updatedAccount)
        {
            var user = HttpContext.User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(View());
            }

            _accountService.ProcessAccountCheckout(updatedAccount);
            _accountService.UpdateAccountCheckout(user, updatedAccount);

            return(RedirectToAction("ReviewStep"));
        }
Exemple #15
0
        public async Task <IActionResult> EditProfile()
        {
            ViewBag.Title = "Notenda upplýsingar";
            var user = await _userManager.GetUserAsync(User);

            var account = new AccountInputModel();

            account.FirstName = user.FirstName;
            account.LastName  = user.LastName;
            account.Email     = user.Email;
            account.Age       = user.Age;
            account.Image     = user.Image;
            account.FavBook   = user.FavBook;
            return(View(account));
        }
Exemple #16
0
        public async Task <ActionResult <Account> > CreateAccountAsync([FromBody] AccountInputModel inputModel)
        {
            if (!TryValidateModel(inputModel))
            {
                return(BadRequest());
            }

            var accountDetails = new AccountDetails(AccountId.New.Id, inputModel.Externalid, inputModel.Name,
                                                    inputModel.CountryCode, inputModel.CurrencyCode, inputModel.StartingBalance);
            var @event = new AccountOpenedEvent(accountDetails);

            await _eventStoreConnection.AppendToStreamAsync(@event.Data.AccountId, ExpectedVersion.Any,
                                                            @event.EventData);

            return(new Account(accountDetails));
        }
        public async Task <IActionResult> Create(AccountInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            Account account = this.mapper.Map <Account>(model);
            string  adUrl   = await this.cloudinaryService.UploadPictureAsync(model.AdUrl, model.Currency);

            account.AdUrl = adUrl;

            this.accountsService.AddAccountToUser(account);

            return(Redirect("Index"));
        }
Exemple #18
0
        public async Task <IdentityResult> Register(AccountInputModel input)
        {
            IdentityUser newUser = new IdentityUser()
            {
                UserName = input.Username
            };
            IdentityResult result = await UserManager.CreateAsync(newUser, input.Password).ConfigureAwait(false);

            IdentityUser user = await UserManager.FindByNameAsync(input.Username).ConfigureAwait(false);

            if (user != null && !(await UserManager.IsInRoleAsync(user, input.Role).ConfigureAwait(false)))
            {
                await UserManager.AddToRoleAsync(user, input.Role).ConfigureAwait(false);
            }

            return(result);
        }
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            string username        = bindingContext.ValueProvider.GetValue("username").FirstValue;
            string oldPassword     = bindingContext.ValueProvider.GetValue("oldPassword").FirstValue;
            string password        = bindingContext.ValueProvider.GetValue("password").FirstValue;
            string confirmPassword = bindingContext.ValueProvider.GetValue("confirmpassword").FirstValue;
            string role            = bindingContext.ValueProvider.GetValue("role").FirstValue;

            if (role != "admin" && role != "user")
            {
                role = "user";
            }

            var input = new AccountInputModel(username, oldPassword, password, confirmPassword, role);

            bindingContext.Result = ModelBindingResult.Success(input);

            return(Task.CompletedTask);
        }
Exemple #20
0
        public async Task <IActionResult> EditProfile(AccountInputModel account)
        {
            ViewBag.Title = "Notenda upplýsingar";
            if (!ModelState.IsValid)
            {
                return(View(account));
            }
            var user = await _userManager.GetUserAsync(User);

            user.FirstName = account.FirstName;
            user.LastName  = account.LastName;
            user.Email     = account.Email;
            user.Age       = account.Age;
            user.UserName  = account.Email;
            user.Image     = account.Image;
            user.FavBook   = account.FavBook;
            await _userManager.UpdateAsync(user);

            return(RedirectToAction("MyAccount", "Account"));
        }
Exemple #21
0
        public async Task <ActionResult <ApiResultViewModel <AccountViewModel> > > CreateAccount(
            [FromBody] AccountInputModel inputModel,
            CancellationToken cancellationToken)
        {
            var account = new Account();

            account.Email                 = inputModel.Email;
            account.PasswordHash          = PasswordHash.CreateHash(inputModel.Password);
            account.PhoneNumber           = inputModel.PhoneNumber;
            account.FirstName             = inputModel.FirstName;
            account.LastName              = inputModel.LastName;
            account.Nickname              = inputModel.Nickname;
            account.GenderId              = inputModel.GenderTypeId.ToInt();
            account.BirthDate             = inputModel.BirthDate;
            account.StatusId              = inputModel.StatusId.ToInt();
            account.StatusNote            = inputModel.StatusNote;
            account.IsEmailVerified       = inputModel.IsEmailVerified;
            account.IsPhoneNumberVerified = inputModel.IsPhoneNumberVerified;
            account.Timezone              = "Asia/Tehran";
            account.ReceiveNotifications  = true;
            account.SearchableByEmailAddressOrUsername = true;
            account.FriendsOnlyBattleInvitations       = false;
            account.RegisterDateTime = DateTime.UtcNow;

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                account = await _accountManager.SaveAsync(account, cancellationToken);

                await _accountManager.UpdateRolesAsync(account, inputModel.RoleIds.Select(rid => rid.ToLong()), cancellationToken);

                var accountStats = new AccountStatsSummary
                {
                    AccountId = account.Id
                };
                await _statsManager.SaveAsync(accountStats, cancellationToken);

                transaction.Complete();
            }

            return(OkData(AccountViewModel.Map(account)));
        }
        public IActionResult VerifyWallet(AccountInputModel account, int walletNumber, bool verify = false)
        {
            var wallet = _walletService.GetWalletByWalletNumber(walletNumber, true);

            if (wallet == null)
            {
                return(RedirectToAction("Error", "Error", new ErrorViewModel {
                    RequestId = "Error, wallet does not exist"
                }));
            }

            // Modal for verification
            if (verify)
            {
                wallet.IsVerified = true;
                _walletService.UpdateWallet(wallet);

                return(RedirectToAction("WalletVerificationList"));
            }

            // Modal for adding accounts to the wallet before it is verified
            if (!ModelState.IsValid)
            {
                var model = _mapper.Map <VerifyWalletViewModel>(wallet);

                model.CurrencyList = _mapper.Map <List <CurrencyModel> >(_nomenclatureService.GetCurrencies());

                return(View(model));
            }

            var acc = _mapper.Map <AccountServiceModel>(account);

            acc.WalletId        = wallet.Id;
            acc.AccountStatusId = (int)StatusEnum.Status.Okay;
            acc.CreatedById     = int.Parse(_userService.GetUserId(User));

            _accountService.CreateAccount(acc);

            return(RedirectToAction("VerifyWallet", new { walletNumber }));
        }
        public void UpdateAccountCheckout(string userId, AccountInputModel model)
        {
            var accounts = GetAllAccounts();
            var account  = (from a in _db.Accounts
                            where a.Email == model.Email
                            select a).FirstOrDefault();

            account.FirstName                 = model.FirstName;
            account.LastName                  = model.LastName;
            account.Email                     = model.Email;
            account.ProfilePicture            = model.ProfilePicture;
            account.FavoriteBook              = model.FavoriteBook;
            account.BillingAddressStreet      = model.BillingAddressStreet;
            account.BillingAddressHouseNumber = model.BillingAddressHouseNumber;
            account.BillingAddressLine2       = model.BillingAddressLine2;
            account.BillingAddressCity        = model.BillingAddressCity;
            account.BillingAddressCountry     = model.BillingAddressCountry;
            account.BillingAddressZipCode     = model.BillingAddressZipCode;

            if (model.SameAddresses == 1)
            {
                account.DeliveryAddressStreet      = model.BillingAddressStreet;
                account.DeliveryAddressHouseNumber = model.BillingAddressHouseNumber;
                account.DeliveryAddressLine2       = model.BillingAddressLine2;
                account.DeliveryAddressCity        = model.BillingAddressCity;
                account.DeliveryAddressCountry     = model.BillingAddressCountry;
                account.DeliveryAddressZipCode     = model.BillingAddressZipCode;
            }
            else
            {
                account.DeliveryAddressStreet      = model.DeliveryAddressStreet;
                account.DeliveryAddressHouseNumber = model.DeliveryAddressHouseNumber;
                account.DeliveryAddressLine2       = model.DeliveryAddressLine2;
                account.DeliveryAddressCity        = model.DeliveryAddressCity;
                account.DeliveryAddressCountry     = model.DeliveryAddressCountry;
                account.DeliveryAddressZipCode     = model.DeliveryAddressZipCode;
            }

            _db.SaveChanges();
        }
Exemple #24
0
        public async Task <IActionResult> EditAccountInfo(AccountInputModel model)
        {
            //入力値チェック
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            var userInfo = multiTenancyLogic.CurrentUserInfo;

            if (userInfo == null)
            {
                return(JsonBadRequest("Couldn't get activated user informations"));
            }

            Tenant defaultTenant = userInfo.TenantDic.Keys.FirstOrDefault(t => t.Name == model.DefaultTenant);

            if (defaultTenant == null)
            {
                return(JsonBadRequest("Invalid tenant name"));
            }

            //アップデート処理
            User user = await userRepository.GetByIdAsync(userInfo.Id);

            user.DefaultTenantId = defaultTenant.Id;
            unitOfWork.Commit();

            AccountOutputModel result = new AccountOutputModel()
            {
                UserId         = userInfo.Id,
                UserName       = userInfo.Name,
                SelectedTenant = new TenantInfo(userInfo.SelectedTenant, userInfo.TenantDic, userInfo.DefaultTenant.Id),
                DefaultTenant  = new TenantInfo(defaultTenant, userInfo.TenantDic, userInfo.DefaultTenant.Id),
                Tenants        = userInfo.TenantDic.Select(x => new TenantInfo(x.Key, x.Value, userInfo.DefaultTenant.Id)).ToList()
            };

            return(JsonOK(result));
        }
Exemple #25
0
        public async Task <IActionResult> Edit(AccountInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var userId  = base.GetUserIdFromAuthorizeHeader();
                var account = new Account {
                    Id = model.Id, Name = model.Name
                };
                var returnAccount = await accountsService.Edit <AccountDTO>(account, userId);

                var accountView = mapper.Map <AccountViewModel>(returnAccount);

                return(Ok(accountView));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #26
0
 public void UpdateAccountCheckout(string userId, AccountInputModel model)
 {
     _accountRepo.UpdateAccountCheckout(userId, model);
 }
Exemple #27
0
        public async ValueTask <ActionResult <AccountWithLeadOutputModel> > UpdateAccount(AccountInputModel account)
        {
            DataWrapper <AccountDto> dataWrapper = await _repo.AddOrUpdateAccount(_mapper.Map <AccountDto>(account));

            _logger.Info($"Update account with Id: {dataWrapper.Data.Id}");
            return(MakeResponse(dataWrapper, _mapper.Map <AccountWithLeadOutputModel>));
        }
Exemple #28
0
        public async ValueTask <ActionResult <AccountWithLeadOutputModel> > CreateAccount(AccountInputModel account)
        {
            if (account.CurrencyId == null)
            {
                return(BadRequest("Choose currency"));
            }
            DataWrapper <AccountDto> dataWrapper = await _repo.AddOrUpdateAccount(_mapper.Map <AccountDto>(account));

            _logger.Info($"Create new account with Id: {dataWrapper.Data.Id}");
            return(MakeResponse(dataWrapper, _mapper.Map <AccountWithLeadOutputModel>));
        }
Exemple #29
0
        public async Task <ActionResult <ApiResultViewModel <AccountViewModel> > > UpdateAccount(string id,
                                                                                                 [FromBody] AccountInputModel inputModel, CancellationToken cancellationToken)
        {
            var account = await _accountManager.GetAsync(id.ToInt(), cancellationToken);

            if (account is null)
            {
                return(NotFound());
            }

            if (account.Email != inputModel.Email && await _accountManager.FindByEmailAsync(inputModel.Email, cancellationToken) != null)
            {
                return(BadRequest("duplicate_email", "Account with entered email already exists."));
            }

            account.Email = inputModel.Email;

            if (!string.IsNullOrWhiteSpace(inputModel.Password))
            {
                account.PasswordHash = PasswordHash.CreateHash(inputModel.Password);
            }

            account.PhoneNumber           = inputModel.PhoneNumber;
            account.FirstName             = inputModel.FirstName;
            account.LastName              = inputModel.LastName;
            account.Nickname              = inputModel.Nickname;
            account.GenderId              = inputModel.GenderTypeId.ToInt();
            account.BirthDate             = inputModel.BirthDate;
            account.StatusId              = inputModel.StatusId.ToInt();
            account.StatusNote            = inputModel.StatusNote;
            account.IsEmailVerified       = inputModel.IsEmailVerified;
            account.IsPhoneNumberVerified = inputModel.IsPhoneNumberVerified;
            account.Timezone              = "Asia/Tehran";
            account.CoverImageId          = inputModel.CoverImageId;

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var selectedAvatarItemIds = inputModel.AvatarItemIds.Select(q => q.ToLong()).ToArray();
                if (selectedAvatarItemIds.Any())
                {
                    var accountItems = await _accountItemManager.GetByAccountIdAsync(account.Id, cancellationToken);

                    var imagesToCombine = new List <Stream>();
                    foreach (var selectedAvatarItemId in selectedAvatarItemIds)
                    {
                        var shopItem = await _shopItemManager.GetAsync(selectedAvatarItemId, cancellationToken);

                        imagesToCombine.Add(_fileService.GetFile(shopItem.ImageFileId));

                        if (!accountItems.Any(q => q.ShopItemId == selectedAvatarItemId))
                        {
                            // add item to user's items
                            var newAccountItem = new AccountItem
                            {
                                AccountId  = account.Id,
                                ShopItemId = selectedAvatarItemId,
                                ItemTypeId = shopItem.TypeId,
                                Quantity   = 1
                            };
                            newAccountItem = await _accountItemManager.SaveAsync(newAccountItem, cancellationToken);
                        }
                    }

                    using (var avatarImg = _imageProcessingService.Combine(imagesToCombine))
                    {
                        var fileId = await _fileService.SaveFileAsync(avatarImg, cancellationToken);

                        var file = await _fileManager.SaveAsync(new UploadedFile
                        {
                            FileId             = fileId,
                            CreatorAccountId   = AccountId,
                            Extension          = "png",
                            MimeType           = "image/png",
                            MimeTypeCategoryId = UploadedFileMimeTypeCategoryIds.Image,
                            Name   = "avatar",
                            Size   = avatarImg.Length,
                            TypeId = UploadedFileTypeIds.AccountAvatarImage
                        }, cancellationToken);

                        account.AvatarImageId = file.FileId;
                    }
                }

                account.AvatarItemIds = JsonConvert.SerializeObject(selectedAvatarItemIds);
                account.RoleIds       = JsonConvert.SerializeObject(inputModel.RoleIds?.Select(q => q.ToLong()) ?? new long[0]);
                account = await _accountManager.SaveAsync(account, cancellationToken);

                await _accountManager.UpdateRolesAsync(account, inputModel.RoleIds.Select(rid => rid.ToLong()), cancellationToken);

                transaction.Complete();
            }

            return(OkData(AccountViewModel.Map(account)));
        }