Esempio n. 1
0
 public ActionResult Create(AccountModel newAccount)
 {
     try
     {
         ActionResult result;
         if (ModelState.IsValid)
         {
             try
             {
                 var acc = _accountSvc.GetByLoginName(newAccount.CompanyCode);
                 if (acc != null)
                 {
                     ModelState.AddModelError(String.Empty,
                                              UserControllerResource.CreateAccountError.FormatWith("Tên đăng nhập đã tồn tại!"));
                     result = View();
                 }
                 else
                 {
                     var password = newAccount.Password;
                     var salt     = EntityUtils.GenerateRandomBytes(Constants.PasswordSaltLength);
                     var pwdHash  = EntityUtils.GetInputPasswordHash(password, salt);
                     var account  = new Account
                     {
                         Phone        = newAccount.Phone,
                         CompanyName  = newAccount.CompanyName,
                         CompanyCode  = newAccount.CompanyCode,
                         Status       = 0,
                         RoleCode     = (byte)newAccount.Role,
                         PasswordHash = pwdHash,
                         PasswordSalt = salt,
                         Permissions  = 0
                     };
                     _accountSvc.Add(account);
                     result = RedirectToAction("Me");
                 }
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError(String.Empty,
                                          UserControllerResource.CreateAccountError.FormatWith(ex.Message));
                 result = View();
             }
         }
         else
         {
             ModelState.AddModelError(String.Empty, UserControllerResource.InvalidAccountInfo);
             result = View();
         }
         return(result);
     }
     catch (Exception ex)
     {
         TempData.Add("error", ex.ToString());
         return(RedirectToAction("Index", "Error"));
     }
 }
Esempio n. 2
0
        public ActionResult Register(RegisterModel register)
        {
            if (ModelState.IsValid)
            {
                register.Subject   = "";
                register.Serial    = "";
                register.ValidFrom = "10/01/2018";
                register.ValidTo   = "10/01/2020";
                var profile = new Profile
                {
                    CompanyName          = register.CompanyName,
                    Email                = register.Email,
                    Phone                = register.Phone,
                    Fax                  = null,
                    CompanyCode          = register.CompanyCode,
                    Address              = register.Address,
                    Province             = register.Province,
                    StartOfFinancialYear = null,
                    TaxAgencyCode        = register.TaxAgencyCode,
                    TaxAgencyName        = register.TaxAgencyName,
                    Issuer               = register.Issuer,
                    Subject              = register.Subject,
                    Serial               = register.Serial,
                    ValidFrom            = DateTime.Parse(register.ValidFrom,
                                                          System.Globalization.CultureInfo.
                                                          GetCultureInfo("vi-VN").
                                                          DateTimeFormat),
                    ValidTo = DateTime.Parse(register.ValidTo,
                                             System.Globalization.CultureInfo.
                                             GetCultureInfo("vi-VN").
                                             DateTimeFormat),
                };

                var password = register.NewPassword;
                var salt     = EntityUtils.GenerateRandomBytes(Constants.PasswordSaltLength);
                var pwdHash  = EntityUtils.GetInputPasswordHash(password, salt);
                var accounts = new Account()
                {
                    ProfileId        = profile.Id,
                    CompanyCode      = register.CompanyCode,
                    PasswordHash     = pwdHash,
                    PasswordSalt     = salt,
                    CompanyName      = register.CompanyName,
                    Representative   = register.Representative,
                    Address          = register.Address,
                    Phone            = register.Phone,
                    AccountType      = null,
                    BankAccount      = register.BankAccount,
                    BankName         = null,
                    ActivationTime   = DateTime.Now,
                    DateExpired      = DateTime.Now,
                    DeactivationTime = DateTime.Now,
                    // LastLoginDate = DateTime.Now
                };

                using (var scope = new TransactionScope())
                {
                    _pro.Create(profile);

                    accounts.ProfileId = profile.Id;
                    _acc.Create(accounts);
                    scope.Complete();
                }
            }
            else
            {
                return(View());
            }

            return(null);
        }