public ActionResult AddUser(AddUserViewModel addUser)
        {
            if(ModelState.IsValid)
            {
                using (new UnitOfWork(_currentContext))
                {
                    var user = new Account()
                                   {
                                       Username = addUser.Username,
                                       Password = addUser.Password.Sha256(Const.HashSalt),
                                       RegisteredAt = DateTime.Now,
                                       RoleId = (int) AccountRole.Administrator
                                   };

                    accountRepository.Add(user);

                    TempData[Const.ActionResultInfo] = "Пользователь успешно добавлен";

                    return RedirectToAction("Users");
                }
            }

            TempData[Const.ActionErrorInfo] = "Невозможно создать пользователя. Проверьте правильность заполнения данных";

            return View();
        }
Example #2
0
 /// <summary>
 /// Create a new Account object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="username">Initial value of the Username property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="roleId">Initial value of the RoleId property.</param>
 /// <param name="registeredAt">Initial value of the RegisteredAt property.</param>
 public static Account CreateAccount(global::System.Int32 id, global::System.String username, global::System.String password, global::System.Int32 roleId, global::System.DateTime registeredAt)
 {
     Account account = new Account();
     account.Id = id;
     account.Username = username;
     account.Password = password;
     account.RoleId = roleId;
     account.RegisteredAt = registeredAt;
     return account;
 }
Example #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the AccountSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAccountSet(Account account)
 {
     base.AddObject("AccountSet", account);
 }