public ActionResult changeProfile(gov_user item) {
            gov_user userInfo = _cnttDB.gov_user.Find(item.username);
            if (Request.Files.Count > 0)
            {
                String dirOld = userInfo.avatar;
                var fileName = string.Empty;
                var file = Request.Files[0];
                var bytes = new byte[file.ContentLength];
                if (bytes.Length > 0)
                {
                    file.InputStream.Read(bytes, 0, file.ContentLength);
                    fileName = (file.FileName.IndexOf('\\') != -1 ? file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1) : file.FileName);

                    var fileFolder = fileSaveFolder;
                    var fileDir = Server.MapPath("/") + fileFolder;
                    if (!System.IO.Directory.Exists(fileDir))
                        System.IO.Directory.CreateDirectory(fileDir);
                    var filePath = fileFolder + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + fileName.Substring(fileName.LastIndexOf("."));
                    System.IO.File.WriteAllBytes(Server.MapPath("/") + filePath, bytes);
                    userInfo.avatar = filePath.Replace("\\", "/");
                    if (System.IO.File.Exists(Server.MapPath("/") + fileFolder + dirOld))
                    {
                        System.IO.File.Delete(Server.MapPath("/") + fileFolder + dirOld);
                    }
                }
            }
            
            userInfo.family_name = item.family_name;
            userInfo.first_name = item.first_name;
            userInfo.birth_day = item.birth_day;
            userInfo.sex = item.sex;
            userInfo.address = item.address;
            userInfo.email = item.email;
            userInfo.phone = item.phone;
            userInfo.mobile = item.mobile;
            userInfo.is_shared = item.is_shared;
            int rs = _cnttDB.SaveChanges();
            if (rs > 0)
            {
                Session.SetCurrentUser(userInfo);
            }
            ViewData["message"] = "Cập nhật thông tin thành công!";
            ViewData["userInfo"] = Session.getCurrentUser();
            return View("Index");
        }
 public ActionResult SaveRegist(gov_user item)
 {
     if (Session.getCurrentUser() == null)
         return Redirect("/admin/account/logon");
     if (!SercurityServices.HasPermission((int)TypeModule.MODULE_NGUOIDUNG, Session.getCurrentUser().username, TypeAudit.Addnew))
     {
         return Redirect("/admin/error/error403");
     }
     item.password = FormsAuthentication.HashPasswordForStoringInConfigFile(item.password, "MD5");
     item.entry_datetime = DateTime.Now;
     item.entry_username = Session.getCurrentUser().username;
     item.update_datetime = DateTime.Now;
     item.update_user_name = Session.getCurrentUser().username;
     item.active_flg = true;
     item.hidden_flg = false;
     try
     {
         _cnttDB.gov_user.Add(item);
         int rs = _cnttDB.SaveChanges();
         if (rs > 0)
         {
             insertHistory(AccessType.themMoiUser, Constant.THEM(Constant.ITEM_USER, Constant.USERNAME, item.username));
             TempData["message"] = Constant.REGIST_SUCCESSFULL;
         }
         else
         {
             TempData["err"] = Constant.REGIST_ERR;
         }
     }
     catch (Exception ex)
     {
         TempData["err"] = Constant.REGIST_ERR;
     }
     return Redirect("Index");
 }
 public ActionResult SaveEdit(gov_user item)
 {
     if (Session.getCurrentUser() == null)
         return Redirect("/admin/account/logon");
     if (!SercurityServices.HasPermission((int)TypeModule.MODULE_NGUOIDUNG, Session.getCurrentUser().username, TypeAudit.Edit))
     {
         return Redirect("/admin/error/error403");
     }
     gov_user userInfo = _cnttDB.gov_user.Find(item.username);
     userInfo.address = item.address;
     userInfo.birth_day = item.birth_day;
     userInfo.department_id = item.department_id;
     userInfo.email = item.email;
     userInfo.family_name = item.family_name;
     userInfo.first_name = item.first_name;
     userInfo.mobile = item.mobile;
     userInfo.active_flg = item.active_flg;
     userInfo.role_id = item.role_id;
     userInfo.phone = item.phone;
     userInfo.sex = item.sex;
     userInfo.is_shared = item.is_shared;
     userInfo.avatar = item.avatar;
     if(!userInfo.password.Equals(item.password))
         userInfo.password = FormsAuthentication.HashPasswordForStoringInConfigFile(item.password, "MD5");
     userInfo.update_datetime = DateTime.Now;
     userInfo.update_user_name = Session.getCurrentUser().username;
     try
     {
         int rs = _cnttDB.SaveChanges();
         if (rs > 0)
         {
             insertHistory(AccessType.chinhSuaUser, Constant.CHINHSUA(Constant.ITEM_USER, Constant.USERNAME, item.username));
             TempData["message"] = Constant.EDIT_SUCCESSFULL;
         }
         else
         {
             TempData["err"] = Constant.EDIT_ERR;
         }
     }
     catch (Exception ex)
     {
         TempData["err"] = Constant.EDIT_ERR;
     }
     return Redirect("Index");
 }
 public static void SetCurrentUser(this HttpSessionStateBase session, gov_user user )
 {
     session["currentUser"] = user;
 }