public ActionResult Change_user(string user_name, string type, string act, string ctrl, string type_act) { UserModels userModels = new UserModels(); RoleModels roleModels = new RoleModels(); C_User cuser = new C_User(); StringBuilder sb = new StringBuilder(); var user_view = new Web.Areas.Admin.ViewModels.User_view(); if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateProduct; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "change_user"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminUser"; } if (user_name == null) { user_name = Request.QueryString["user_name"] != null ? Request.QueryString["user_name"].ToString() : string.Empty; } if (string.IsNullOrEmpty(type_act)) { type_act = Request.QueryString["type_act"] != null ? Request.QueryString["type_act"].ToString() : CommonGlobal.Add; if (user_name == string.Empty) { type_act = CommonGlobal.Add; } else { type_act = CommonGlobal.Edit; } } sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_user", ctrl = "adminUser", type = type, page = "1" }) + "\"><span><span>Danh sách Admin</span></span></a></li>"); if (type_act == CommonGlobal.Edit) { cuser = userModels.GetUserbyUserName(user_name); sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + cuser.Username + "</span></span></a></li>"); if (type == "Admin") { sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_user_permission", ctrl = "adminUser", type = type, page = "1", user_name = cuser.Username }) + "\"><span><span>Page Permission</span></span></a></li>"); } user_view.Username = cuser.Username; user_view.Username_text = "readonly='readonly'"; user_view.Role = cuser.Role; user_view.Online = cuser.Online ?? false; if (cuser.Online == true) { user_view.Online = true; user_view.Online_text = "checked='checked'"; } else { user_view.Online = false; user_view.Online_text = string.Empty; } } else { if (type == "Admin") { sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm Admin</span></span></a></li>"); user_view.Username_text = string.Empty; } } user_view.Html_link_tab = sb.ToString(); user_view.Type = type; user_view.Type_act = type_act; ////action and parent action user_view.Act = act; user_view.Ctrl = ctrl; user_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); user_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(this.PartialView("../control/change_user", user_view)); }
public ActionResult Change_user(FormCollection collection) { UserModels userModels = new UserModels(); C_User cuser = null; StringBuilder sb = new StringBuilder(); var user_view = new Web.Areas.Admin.ViewModels.User_view(); this.TryUpdateModel(user_view); string rt = string.Empty; bool is_valid = true; if (!string.IsNullOrEmpty(user_view.Username)) { cuser = userModels.GetUserbyUserName(user_view.Username); } ////validation server if (string.IsNullOrEmpty(user_view.Username)) { is_valid = false; if (user_view.Message == string.Empty) { user_view.Message = "Bạn phải nhập User Name"; } } ////UserName duplicate Admin if (user_view.Username == "Admin") { is_valid = false; if (user_view.Message == string.Empty) { user_view.Message = "Bạn không thể tạo Admin"; } } ////Link tab sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_user", ctrl = "adminUser", type = user_view.Type, page = "1" }) + "\"><span><span>Danh sách Admin</span></span></a></li>"); if (!string.IsNullOrEmpty(user_view.Username) && user_view.Type_act == CommonGlobal.Edit) { sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + cuser.Username + "</span></span></a></li>"); } else { sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>"); ////validation password if (string.IsNullOrEmpty(user_view.Password)) { is_valid = false; if (user_view.Message == string.Empty) { user_view.Message = "Bạn phải nhập mật khẩu"; } } if (string.IsNullOrEmpty(user_view.ConfirmPassword)) { is_valid = false; if (user_view.Message == string.Empty) { user_view.Message = "Bạn phải xác nhận mật khẩu"; } } if (user_view.Password != user_view.ConfirmPassword) { is_valid = false; if (user_view.Message == string.Empty) { user_view.Message = "Bạn phải xác nhận mật khẩu"; } } } sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_user_permission", ctrl = "adminUser", type = user_view.Type, user_name = user_view.Username, page = "1" }) + "\"><span><span>Permission</span></span></a></li>"); user_view.Html_link_tab = sb.ToString(); if (!is_valid) { return(this.PartialView("../control/change_user", user_view)); } cuser = new C_User(); cuser.Username = user_view.Username; cuser.Online = user_view.Online; if (cuser.Online == true) { user_view.Online = true; user_view.Online_text = "checked='checked'"; } else { user_view.Online = false; user_view.Online_text = string.Empty; } if (!string.IsNullOrEmpty(user_view.Username) && user_view.Type_act == CommonGlobal.Edit) { rt = userModels.Update_User(cuser); } else { cuser.Role = 1; cuser.Password = MD5Extend.EncodePassword(user_view.Password); cuser.IP = "not login"; cuser.Online = true; cuser.LastLogin = null; rt = userModels.Add_User(cuser); } if (rt.Length > 0) { user_view.Message = "Cập nhật thành công!"; user_view.Username = rt; user_view.Type_act = CommonGlobal.Edit; } else { user_view.Message = "Cập nhật không thành công!"; } return(this.PartialView("../control/change_user", user_view)); }