Exemple #1
0
 public ActionResult Create(User user)
 {
     if (getCurrentUser() == null)
     {
         return(RedirectToAction("Index", "Login"));
     }
     else
     {
         try
         {
             if (user.u_role_id != 0)
             {
                 User usercheck = iuser.getUserbyUsername(user.u_name);
                 if (usercheck == null)
                 {
                     var key             = "shdfg2323g3g4j3879sdfh2j3237w8eh";
                     var encryptedString = AesOperaions.EncryptString(key, user.u_password);
                     user.u_password  = encryptedString.ToString();
                     user.u_cre_by    = getCurrentUser().u_id;
                     user.u_cre_date  = DateTime.Now;
                     user.u_active_yn = "Y";
                     iuser.Add(user);
                     return(RedirectToAction(nameof(Index)));
                 }
                 else
                 {
                     ViewBag.RoleList       = (irole.GetRoles);
                     ViewBag.DepartmentList = (idepartment.GetDepartments);
                     ViewBag.Message        = "Username already exsist";
                     return(View());
                 }
             }
             else
             {
                 ViewBag.Message = "Please enter all column";
                 return(View());
             }
         }
         catch (Exception ex)
         {
             ViewBag.RoleList       = (irole.GetRoles);
             ViewBag.DepartmentList = (idepartment.GetDepartments);
             ViewBag.Message        = ex.Message;
             return(View());
         }
     }
 }
Exemple #2
0
        public ActionResult Edit(int id, User user)
        {
            if (getCurrentUser() == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                try
                {
                    User temp_user = iuser.GetUser(id);

                    var key = "shdfg2323g3g4j3879sdfh2j3237w8eh";

                    temp_user.u_full_name     = user.u_full_name;
                    temp_user.u_name          = user.u_name;
                    temp_user.u_is_admin      = user.u_is_admin;
                    temp_user.u_role_id       = user.u_role_id;
                    temp_user.u_active_yn     = user.u_active_yn;
                    temp_user.u_email         = user.u_email;
                    temp_user.u_allocation_yn = user.u_allocation_yn;
                    if (user.u_password != null)
                    {
                        var encryptedString = AesOperaions.EncryptString(key, user.u_password);
                        temp_user.u_password = encryptedString.ToString();
                    }
                    else
                    {
                        temp_user.u_password = temp_user.u_password;
                    }


                    iuser.Update(temp_user);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    ViewBag.RoleList       = (irole.GetRoles);
                    ViewBag.DepartmentList = (idepartment.GetDepartments);
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    ViewBag.Message = ex.Message;
                    return(View());
                }
            }
        }
 public IActionResult ChangePassword(string u_password, string u_confirm)
 {
     if (getCurrentUser() == null)
     {
         return(RedirectToAction("Index", "Login"));
     }
     else
     {
         if (u_password.Equals(u_confirm))
         {
             User user            = getCurrentUser();
             var  key             = "shdfg2323g3g4j3879sdfh2j3237w8eh";
             var  encryptedString = AesOperaions.EncryptString(key, u_password);
             user.u_password = encryptedString.ToString();
             iuser.Update(user);
             return(RedirectToAction("Index", "Login"));
         }
         else
         {
             ViewBag.Error = "Your password and confirmation password do not match!!";
             return(RedirectToAction("Reset"));
         }
     }
 }