Ejemplo n.º 1
0
        public async Task Post_ShouldReturnOk()
        {
            // Arrange
            var model = new AccountCreateViewModel {
                UserId = Guid.NewGuid(), CompanyName = "Brandscreen", CompanyType = "Other"
            };
            var owner = new User();

            Mock.Mock <IUserService>().Setup(x => x.GetUser(model.UserId))
            .Returns(Task.FromResult(owner));
            Mock.Mock <ICountryService>().Setup(x => x.GetCountry(It.IsAny <string>()))
            .Returns(Task.FromResult(new Country()));
            Mock.Mock <ICurrencyService>().Setup(x => x.GetCurrency(It.IsAny <string>()))
            .Returns(Task.FromResult(new Currency()));
            Mock.Mock <ILanguageService>().Setup(x => x.GetLanguage(It.IsAny <string>()))
            .Returns(Task.FromResult(new Language()));
            Mock.Mock <ITimeZoneService>().Setup(x => x.GetTimeZone(It.IsAny <string>()))
            .Returns(Task.FromResult(new TimeZone()));

            // Act
            var retVal = await Controller.Post(model);

            // Assert
            Assert.That(retVal, Is.Not.Null);
            Assert.That(retVal, Is.TypeOf <CreatedAtRouteNegotiatedContentResult <AccountViewModel> >());
            Mock.Mock <IAccountService>().Verify(x => x.CreateAccount(It.IsAny <BuyerAccount>(), owner), Times.Once);
        }
        public async Task <ActionResult <ResponseModel> > Create(AccountCreateViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            if (model.Name.Trim().Length <= 0)
            {
                response.SetFailed("请输入财务账号名称");
                return(Ok(response));
            }

            await using (_dbContext)
            {
                if (_dbContext.DncRole.Count(x => x.Name == model.Name) > 0)
                {
                    response.SetFailed("财务账号已存在");
                    return(Ok(response));
                }
                var entity = _mapper.Map <AccountCreateViewModel, FinanceAccount>(model);

                entity.CreatedOn         = DateTime.Now;
                entity.Code              = RandomHelper.GetRandomizer(8, true, false, true, true);
                entity.CreatedByUserGuid = AuthContextService.CurrentUser.Guid;
                entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName;

                await _dbContext.FinanceAccount.AddAsync(entity);

                await _dbContext.SaveChangesAsync();

                response.SetSuccess();
                return(Ok(response));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(string id)
        {
            AccountCreateViewModel model = AccountHelper.GetAccount(id);

            List <AccountValueViewModel> accountValues = AccountValueHelper.GetAccountValuesbyChartId(Convert.ToInt64(id), SessionHelper.SOBId);

            if (accountValues.Any())
            {
                throw new Exception("Edit Error", new Exception {
                    Source = "Accounts having values cannot be edited"
                });
            }

            List <Core.Entities.CodeCombinition> codeCombinitions = CodeCombinationHelper.GetCodeCombinations(model.SOBId, AuthenticationHelper.CompanyId.Value);

            if (codeCombinitions.Any())
            {
                throw new Exception("Edit Error", new Exception {
                    Source = "Accounts having code combinitions cannot be edited"
                });
            }

            model.SOBId = SessionHelper.SOBId;
            return(View(model));
        }
Ejemplo n.º 4
0
        /*
         * This function is for updatig user or equal to add a new seller into system
         */
        internal ServiceResult AddAccount(AccountCreateViewModel vm)
        {
            ABUserModel abuserModel = new ABUserModel();

            abuserModel.Alias    = vm.Alias;
            abuserModel.Email    = vm.EmailAddress;
            abuserModel.Password = vm.Password;
            abuserModel.Token    = null;

            ABUser currentUser = GetUserByUserName(vm.EmailAddress);

            currentUser.Alias    = vm.Alias;
            currentUser.Password = vm.Password;
            currentUser.Token    = null;

            _userRepository.Update(currentUser);


            bool commitSuccess = UpdateUser(currentUser);

            if (commitSuccess)
            {
                return(new ServiceResult()
                {
                    Success = true,
                    Params = currentUser.ToString()
                });
            }

            return(new ServiceResult()
            {
                ErrorMessage = "Error message",
                Success = false
            });
        }
Ejemplo n.º 5
0
        private ActionResult DoRegister(AccountCreateViewModel model, Guid sellerGuid, string token, string returnUrl)
        {
            bool isRegisterValidEmail    = isValidEmail(model.EmailAddress);
            bool isRegisterValidPassword = isValidPassword(model.Password);

            if (isRegisterValidEmail && isRegisterValidPassword)
            {
                ABUser currentUser         = AccountService.GetUserByUserName(model.EmailAddress);
                var    currentUserGuid     = currentUser.ABUserGUID;
                var    currentUserToken    = currentUser.Token;
                Guid   tempCurrentUserGuid = sellerGuid;



                if (tempCurrentUserGuid == currentUserGuid && currentUserToken == token && isRegisterValidEmail)
                {
                    var hashedPassword        = Utilities.CreatePasswordHash(model.Password, model.EmailAddress);
                    AccountCreateViewModel vm = new AccountCreateViewModel();
                    vm.Password        = hashedPassword;
                    vm.EmailAddress    = model.EmailAddress;
                    vm.ConfirmPassword = hashedPassword;
                    vm.Alias           = model.Alias;

                    ServiceResult result = new ServiceResult();
                    result = AccountService.AddAccount(vm);
                    if (result.Success)
                    {
                        return(RedirectToAction("RegisterSuccess", result));
                    }
                    return(RedirectToAction("RegisterFail", result));
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
        public async Task <IHttpActionResult> Post(AccountCreateViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

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

            var owner = await _userService.GetUser(model.UserId).ConfigureAwait(false);

            if (owner == null)
            {
                return(BadRequest("The specified user was not found."));
            }

            var buyerAccount = _mapping.Map <BuyerAccount>(model);
            await _accountService.CreateAccount(buyerAccount, owner).ConfigureAwait(false);

            var accountViewModel = _mapping.Map <AccountViewModel>(buyerAccount);

            return(CreatedAtRoute("Accounts.GetById", new { Id = accountViewModel.BuyerAccountUuid }, accountViewModel));
        }
Ejemplo n.º 7
0
        public ActionResult RegisterSeller(string returnUrl)
        {
            var sellerGuid = Request.QueryString["sellerGuid"];
            var code       = Request.QueryString["code"];

            ABUser currentUser      = AccountService.GetUserByGUID(sellerGuid);
            var    currentUserEmail = currentUser.Email;

            ViewBag.UserEmail = currentUserEmail;

            AccountCreateViewModel model = new AccountCreateViewModel();

            model.userGUID  = new Guid(sellerGuid);
            model.userToken = code;

            HttpCookie cookie = Request.Cookies["AnonymousBidder"];

            if (cookie != null)
            {
                try
                {
                    return(DoRegister(model, model.userGUID, model.userToken, returnUrl));
                }
                catch (Exception)
                {
                }
            }
            ViewBag.ReturnUrl = returnUrl;

            return(View(model));
        }
        public void TestAccountCreateViewModelCancel()
        {
            ILoggerFactory loggerFactory = new LoggerFactory();

            using (var sqliteMemoryWrapper = new SqliteMemoryWrapper())
            {
                var currencyFactory   = new CurrencyFactory();
                var usdCurrencyEntity = currencyFactory.Create(CurrencyPrefab.Usd, true);
                currencyFactory.Add(sqliteMemoryWrapper.DbContext, usdCurrencyEntity);

                var accountService = new AccountService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var currencyService = new CurrencyService(
                    loggerFactory,
                    sqliteMemoryWrapper.DbContext);

                var viewModel = new AccountCreateViewModel(
                    loggerFactory,
                    accountService,
                    currencyService
                    );

                viewModel.Name = "MyAccount";
                viewModel.SelectedAccountType    = AccountType.Asset;
                viewModel.SelectedAccountSubType = AccountSubType.Investment;
                viewModel.CancelCommand.Execute(this);

                List <Account> accounts = accountService.GetAll().ToList();

                Assert.AreEqual(0, accounts.Count);
            }
        }
Ejemplo n.º 9
0
 private Account mapModel(AccountCreateViewModel model)            ////TODO: this should be done in service will discuss later - FK
 {
     return(new Account
     {
         Id = model.Id,
         CompanyId = model.CompanyId,
         CreateDate = DateTime.Now,
         SegmentChar1 = model.SegmentChar1,
         SegmentChar2 = model.SegmentChar2,
         SegmentChar3 = model.SegmentChar3,
         SegmentChar4 = model.SegmentChar4,
         SegmentChar5 = model.SegmentChar5,
         SegmentChar6 = model.SegmentChar6,
         SegmentChar7 = model.SegmentChar7,
         SegmentChar8 = model.SegmentChar8,
         SegmentEnabled1 = model.SegmentEnabled1,
         SegmentEnabled2 = model.SegmentEnabled2,
         SegmentEnabled3 = model.SegmentEnabled3,
         SegmentEnabled4 = model.SegmentEnabled4,
         SegmentEnabled5 = model.SegmentEnabled5,
         SegmentEnabled6 = model.SegmentEnabled6,
         SegmentEnabled7 = model.SegmentEnabled7,
         SegmentEnabled8 = model.SegmentEnabled8,
         SegmentName1 = model.SegmentName1,
         SegmentName2 = model.SegmentName2,
         SegmentName3 = model.SegmentName3,
         SegmentName4 = model.SegmentName4,
         SegmentName5 = model.SegmentName5,
         SegmentName6 = model.SegmentName6,
         SegmentName7 = model.SegmentName7,
         SegmentName8 = model.SegmentName8,
         SOBId = model.SOBId,
         UpdateDate = DateTime.Now
     });
 }
Ejemplo n.º 10
0
        public static AccountCreateViewModel GetAccount(string id)
        {
            AccountCreateViewModel account = new AccountCreateViewModel
                                                 (service.GetSingle(id, AuthenticationHelper.CompanyId.Value));

            return(account);
        }
        public async Task <IActionResult> Add(AccountCreateViewModel model)
        {
            if (!UserIsAuthorized())
            {
                return(RedirectToReferer());
            }

            var user = new ApplicationUser {
                UserName = model.LoginData.Email, Email = model.LoginData.Email, Name = model.AuthorName
            };

            await _accountUnitOfWork.Users.Insert(user, model.LoginData.Password);

            if (model.IsAdmin == true)
            {
                var role = await _accountUnitOfWork.Roles.SearchFor(r => r.Name == BlogConstants.AdministratorRoleName).SingleOrDefaultAsync();

                _accountUnitOfWork.UserRoles.Insert(
                    new IdentityUserRole <string>()
                {
                    RoleId = role.Id,
                    UserId = user.Id
                });
                await _accountUnitOfWork.SaveAsync();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
        public IActionResult Create(AccountCreateViewModel accountViewModel)
        {
            var accountService = new AccountService(_context);

            accountService.CreateNew(new Account(accountViewModel.Name, accountViewModel.Pin));

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Post([FromBody] AccountCreateViewModel model)
        {
            var createdItemId = await _service.Create(_mapper.Map <Account>(model));

            var createdItem = await _service.Load(createdItemId);

            return(Created(createdItemId.ToString(), _mapper.Map <AccountViewModel>(createdItem)));
        }
Ejemplo n.º 14
0
        public ActionResult RegisterSeller(AccountCreateViewModel model, string returnUrl)
        {
            string code;
            Guid   sellerGuid;

            ViewBag.ReturnUrl = returnUrl;
            sellerGuid        = model.userGUID;
            code = model.userToken;

            return(DoRegister(model, sellerGuid, code, returnUrl));
        }
Ejemplo n.º 15
0
        public ActionResult Create()
        {
            AccountCreateViewModel model = new AccountCreateViewModel();

            model.SetOfBooks = sobService.GetByCompanyId(AuthenticationHelper.User.CompanyId)
                               .Select(x => new SelectListItem {
                Text = x.Name, Value = x.Id.ToString()
            }).ToList();

            return(View(model));
        }
Ejemplo n.º 16
0
        public ActionResult Edit(AccountCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.CompanyId = AuthenticationHelper.User.CompanyId;
                string result = service.Update(mapModel(model));
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 17
0
        public ActionResult Create()
        {
            if (AccountHelper.GetAccountBySOBId(SessionHelper.SOBId.ToString()) != null)
            {
                ViewBag.ErrorMessage = "One book can have maximum one chart of account!";
                return(RedirectToAction("Index"));
            }
            AccountCreateViewModel model = new AccountCreateViewModel();

            model.SOBId = SessionHelper.SOBId;
            return(View("Edit", model));
        }
Ejemplo n.º 18
0
        public ActionResult Create([Bind(Include = "Id,Login,Phone,Email,Password")] AccountCreateViewModel accountCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                accountCreateViewModel.Password = _encrypter.HashPassword(accountCreateViewModel.Password);
                var account = _mapper.Map <Account>(accountCreateViewModel);

                _repositoryAccount.Add(account);
                return(RedirectToAction("Index"));
            }

            return(View(accountCreateViewModel));
        }
Ejemplo n.º 19
0
        private static Account getEntityByModel(AccountCreateViewModel model)
        {
            if (model == null)
            {
                return(null);
            }

            Account entity = new Account();

            entity.Id              = model.Id;
            entity.SegmentChar1    = model.SegmentChar1;
            entity.SegmentChar2    = model.SegmentChar2;
            entity.SegmentChar3    = model.SegmentChar3;
            entity.SegmentChar4    = model.SegmentChar4;
            entity.SegmentChar5    = model.SegmentChar5;
            entity.SegmentChar6    = model.SegmentChar6;
            entity.SegmentChar7    = model.SegmentChar7;
            entity.SegmentChar8    = model.SegmentChar8;
            entity.SegmentEnabled1 = model.SegmentEnabled1;
            entity.SegmentEnabled2 = model.SegmentEnabled2;
            entity.SegmentEnabled3 = model.SegmentEnabled3;
            entity.SegmentEnabled4 = model.SegmentEnabled4;
            entity.SegmentEnabled5 = model.SegmentEnabled5;
            entity.SegmentEnabled6 = model.SegmentEnabled6;
            entity.SegmentEnabled7 = model.SegmentEnabled7;
            entity.SegmentEnabled8 = model.SegmentEnabled8;
            entity.SegmentName1    = model.SegmentName1;
            entity.SegmentName2    = model.SegmentName2;
            entity.SegmentName3    = model.SegmentName3;
            entity.SegmentName4    = model.SegmentName4;
            entity.SegmentName5    = model.SegmentName5;
            entity.SegmentName6    = model.SegmentName6;
            entity.SegmentName7    = model.SegmentName7;
            entity.SegmentName8    = model.SegmentName8;
            entity.SOBId           = model.SOBId;
            if (model.Id == 0)
            {
                entity.CompanyId  = AuthenticationHelper.CompanyId.Value;
                entity.CreateBy   = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CompanyId  = model.CompanyId;
                entity.CreateBy   = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }
            entity.UpdateDate = DateTime.Now;
            return(entity);
        }
Ejemplo n.º 20
0
        public ActionResult Edit(string id)
        {
            AccountCreateViewModel model = new AccountCreateViewModel(service.GetSingle(id, AuthenticationHelper.User.CompanyId));
            SetOfBook sob = sobService.GetSingle(model.SOBId.ToString(), AuthenticationHelper.User.CompanyId);

            model.SetOfBooks = new List <SelectListItem>();
            model.SetOfBooks.Add(new SelectListItem {
                Text = sob.Name, Value = sob.Id.ToString()
            });

            return(View(model));

            //Opens popup in grid..
        }
Ejemplo n.º 21
0
        public ActionResult EditAccount(AccountCreateViewModel acvm)
        {
            var account = AccountBLO.Current.GetAccountByCode(acvm.Username);

            account.Address        = acvm.Address;
            account.Email          = acvm.Email;
            account.Fullname       = acvm.Fullname;
            account.Company        = acvm.Company;
            account.Identification = acvm.Identification;
            account.Phone          = acvm.Phone;
            AccountBLO.Current.Update(account);

            return(RedirectToAction("ViewProfile", new { username = acvm.Username, Message = "Profile was updated!" }));
        }
Ejemplo n.º 22
0
        public ActionResult EditStaff(AccountCreateViewModel viewmodel)
        {
            var account = AccountBLO.Current.GetAccountByCode(viewmodel.Username);

            account.GroupCode      = viewmodel.GroupCode;
            account.Role           = viewmodel.Role;
            account.Fullname       = viewmodel.Fullname;
            account.Phone          = viewmodel.Phone;
            account.Address        = viewmodel.Address;
            account.Identification = viewmodel.Identification;
            account.Email          = viewmodel.Email;
            AccountBLO.Current.Update(account);

            return(RedirectToAction("ViewProfile", new { username = viewmodel.Username, Message = "Profile was updated!" }));
        }
Ejemplo n.º 23
0
        public ActionResult CreateStaff(AccountCreateViewModel accountCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                var account = Mapper.Map <AccountCreateViewModel, Account>(accountCreateViewModel);
                account.Status   = true;
                account.Password = AccountBLO.Current.GeneratePassword();
                AccountBLO.Current.Add(account);
                //send account info to login to the system
                AccountBLO.Current.SendAccountInfo(account);

                return(RedirectToAction("Index", new { Message = "New Staff was added!" }));
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult Create(AccountCreateViewModel uCreate)
        {
            if (!ModelState.IsValid)
            {
                return(View(uCreate));
            }

            User user = uCreate.CopyTo <User>();

            _context.Add(new User {
                Email = user.Email, Password = user.Password, Name = user.Name, UserType = user.UserType, Street1 = user.Street1, Street2 = user.Street2, City = user.City, State = user.State, Country = user.Country, Active = Enums.ActiveStatus.Active
            });
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 25
0
        public async Task <ActionResult <AccountViewModel> > Post(AccountCreateViewModel accountInfo)
        {
            if (ModelState.IsValid)
            {
                Account createAccount = _mapper.Map <Account>(accountInfo);
                createAccount = await _accountManager.Create(createAccount);

                if (createAccount != null)
                {
                    AccountViewModel createdAccountInfo = _mapper.Map <AccountViewModel>(createAccount);
                    return(Ok(createdAccountInfo));
                }

                return(BadRequest(new { ErrorMessage = "Account create failed! Try again." }));
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Create(AccountCreateViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                User user = new User
                {
                    UserName = model.UserName,
                    Email    = model.Email
                };

                var existingUser = await _userManager.FindByNameAsync(user.UserName);

                if (existingUser != null)
                {
                    TempData["Message"] =
                        new SystemMessage(MessageType.Warning, "Brukernavnet er opptatt. Vennligst velg et annet.")
                        .GetSystemMessage();
                    return(RedirectToAction("Create", model));
                }

                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                // If a new user was created..
                if (result.Succeeded)
                {
                    // Redirect user to the location specified in returnUrl if not empty, else redirect to /Dashboard
                    TempData["Message"] = new SystemMessage(MessageType.Success, "Din konto ble registrert. Velkommen!")
                                          .GetSystemMessage();
                    await _signInManager.PasswordSignInAsync(user, model.Password, false, false);

                    return(Redirect(returnUrl ?? "/Dashboard"));
                }
                // A new user was NOT created for some reason
                else
                {
                    TempData["Message"] =
                        new SystemMessage(MessageType.Critical, "Det oppstod en feil under oppretting av brukerkontoen din.")
                        .GetSystemMessage();
                }
            }

            return(View(model));
        }
Ejemplo n.º 27
0
        public ActionResult CreateStaff()
        {
            var data      = new AccountCreateViewModel();
            var listgroup = new List <SelectListItem>();

            var count = AccountDAO.Current.GetCountMemberOfGroup();

            for (int i = 0; i < count.Count; i++)
            {
                var list = new SelectListItem();
                if (count[i].CountMember < 3 && count[i].GroupCode != "Admin")
                {
                    list.Value = count[i].GroupCode;
                    list.Text  = count[i].GroupCode;
                    listgroup.Add(list);
                }
            }
            data.Groups = listgroup;
            return(View(data));
        }
Ejemplo n.º 28
0
        public ActionResult ViewProfile(AccountCreateViewModel acvm)
        {
            var mess = "";

            if (acvm.Button == "Deactivate")
            {
                var account = AccountBLO.Current.GetAccountByCode(acvm.Username);
                account.Status = false;
                AccountBLO.Current.Update(account);
                mess = "Account was deativated!";
            }
            if (acvm.Button == "Activate")
            {
                var account = AccountBLO.Current.GetAccountByCode(acvm.Username);
                account.Status = true;
                AccountBLO.Current.Update(account);
                mess = "Account was activated!";
            }

            return(RedirectToAction("ViewProfile", new { username = acvm.Username, Message = mess }));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Create(AccountCreateViewModel input)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var userId = await this.userManager.GetUserIdAsync(user);

            input.UserId = userId;

            if (!this.ModelState.IsValid || input.UserId == null)
            {
                return(this.View(input));
            }

            AccountType accType = (AccountType)Enum.ToObject(typeof(AccountType), input.TypeAccount);

            var postId = await this.accountsService.CreateAsync(input.AccountName, input.UserId, accType);

            this.TempData["InfoMessage"] = "Account created!";
            return(this.Redirect("/Accounts/GetAll"));
            //return this.RedirectToAction(nameof(this.ById), new { id = postId });
        }
Ejemplo n.º 30
0
        public ActionResult _Create(AccountCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            var accountDTO = new AccountDTO()
            {
                FullName = model.FullName,
                Email    = model.Email,
                Password = model.Password,
                RoleName = model.RoleName
            };

            var accountID = AccountBL.Create(accountDTO, base._DB);

            return(new ContentResult()
            {
                Content = "OK"
            });
        }