private void setAutheniticated(string username) { try { DT_WebGISEntities MyContext = new DT_WebGISEntities(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); var user = objUserDao.GetByUserName(username); if (user == null) { CSF_Users obj = new CSF_Users(); obj.UserName = username; obj.FullName = username; obj.Status = 1; obj.RegisterDate = DateTime.Now; obj.Email = username + "@monre.gov.vn"; obj.Password = Encryptor.MD5Hash("e10adc3949ba59abbe56e057f20f883e"); MyContext.CSF_Users.Add(obj); MyContext.SaveChanges(); if (obj.ID > 0) { int IDRegistedGroup = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDRegistedGroup"]); CSF_UserRole objUR = new CSF_UserRole(); objUR.RoleID = IDRegistedGroup; objUR.UserID = obj.ID; MyContext.CSF_UserRole.Add(objUR); MyContext.SaveChanges(); } } FormsAuthentication.SetAuthCookie(username, false); } catch (Exception ex) { Logs.WriteLog(ex); } }
public ActionResult Create(FormCollection fc, CMS_Videos obj) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); TempData.Keep("TypeOfVideoID"); if (ModelState.IsValid) { CMS_Videos_DAO objDAO = new CMS_Videos_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { SetAlert("Thêm video thành công", AlertType.Success); return(RedirectToAction("index", "CMS_Videos")); } else { ModelState.AddModelError("", "Thêm mới không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CMS_Questions obj) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); TempData.Keep("TypeOfQuestionID"); if (ModelState.IsValid) { CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int userID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = userID; if (objDAO.Update(obj)) { SetAlert("Cập nhật thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Questions")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public PartialViewResult AdminMenu() { try { CSF_MVCEntities entities = new CSF_MVCEntities(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); string username = HttpContext.User.Identity.Name; int intGuestGroup = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]); List <int> lRoleID = objUserDao.GetRoleIDByUserName(username, intGuestGroup); string stringRoleID = String.Join(",", lRoleID); // List <CSF_Pages> listAllPage = new List <CSF_Pages>(); if (username.Trim().ToLower() != "host") { var lPageActiveID = entities.CSF_Pages_GetPageByRoleID(stringRoleID).Select(x => (int)x.id).ToList(); listAllPage = entities.CSF_Pages.Where(x => lPageActiveID.Contains(x.ID) && x.IsAdmin == true).OrderBy(x => x.Order).ToList(); } else { listAllPage = entities.CSF_Pages.Where(x => x.IsAdmin == true && x.IsBlank == false && x.IsActive == true).OrderBy(x => x.Order).ToList(); } // string stringMenu = buildTreeMenu(listAllPage); MainMenu mainMenu = new MainMenu(); mainMenu.stringMenu = stringMenu; return(PartialView(mainMenu)); } catch (Exception ex) { Logs.WriteLog(ex); return(PartialView()); } }
public ActionResult Edit(int id) { try { CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); var user = objUsersDAO.GetUserByID(id); if (user == null) { return(RedirectToAction("Index", "QT_Users")); } CSF_Roles_DAO objRolesDAO = new CSF_Roles_DAO(); var roles = objRolesDAO.GetAll(); TempData["Roles"] = roles.ToList(); TempData.Keep("Roles"); //Hiển thị Role đã có của User CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO(); List <CSF_UserRole_GetByUser_Result> userRole = objUserRoleDAO.GetListRoleByUserID(id); TempData["userRole"] = userRole; TempData.Keep("userRole"); return(View(user)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CSF_Modules obj) { try { if (ModelState.IsValid) { CSF_Modules_DAO objDAO = new CSF_Modules_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); if (objDAO.EditModules(obj)) { SetAlert("Cập nhật module thành công", AlertType.Success); return(RedirectToAction("Index", "QT_Modules")); } else { SetAlert("Cập nhật module không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CMS_Documents obj) { try { if (ModelState.IsValid) { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); if (objDAO.CheckExist_DocumentNumber(obj)) { SetAlert("Số hiệu đã tồn tại!", AlertType.Error); return(View()); } if (objDAO.Update(obj)) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Cập nhật văn bản thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Documents")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CMS_Videos obj) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); TempData.Keep("TypeOfVideoID"); if (ModelState.IsValid) { CMS_Videos_DAO objDAO = new CMS_Videos_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); if (objDAO.Update(obj)) { SetAlert("Cập nhật thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Videos")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Create(FormCollection fc, CMS_News obj) { try { TempData.Keep("categories"); if (ModelState.IsValid) { CMS_News_DAO objDAO = new CMS_News_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int userID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.ID_USERCREATE = userID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { SetAlert("Thêm tin tức thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_News")); } else { ModelState.AddModelError("", "Thêm tin tức không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CMS_News obj) { try { if (ModelState.IsValid) { CMS_News_DAO objDAO = new CMS_News_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int userID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.ID_USERMODIFY = userID; bool update = false; update = objDAO.Update(obj); if (update) { SetAlert("Cập nhật tin tức thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_News")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Create(FormCollection fc, CMS_Notifications obj) { try { if (ModelState.IsValid) { CMS_Notifications_DAO objDAO = new CMS_Notifications_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int userID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = userID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { //cache lai thong bao WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_ThongBao(); SetAlert("Thêm thông báo nội bộ thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Notifications")); } else { ModelState.AddModelError("", "Thêm thông báo nội bộ không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Create(FormCollection fc, CMS_Services obj, HttpPostedFileBase file) { try { TempData.Keep("TypeOfMap"); if (ModelState.IsValid) { CMS_Services_DAO objDAO = new CMS_Services_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { SetAlert("Thêm services thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Services")); } else { ModelState.AddModelError("", "Thêm services không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { try { var descriptor = filterContext.ActionDescriptor; var actionName = descriptor.ActionName; var controllerName = descriptor.ControllerDescriptor.ControllerName; DT_WebGISEntities MyContext = new DT_WebGISEntities(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); string username = filterContext.HttpContext.User.Identity.Name; if (!string.IsNullOrEmpty(username)) { int intGuestGroup = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]); List <int> listUserRole = objUserDao.GetRoleIDByUserName(username, intGuestGroup); string ControllerAction = controllerName + "-" + actionName; var ListPermission = (from a in MyContext.CSF_RoleFunction join b in MyContext.CSF_Functions on a.FunctionID equals b.ID where listUserRole.Contains(a.RoleID) select new { ca = b.Controller_Action.ToLower() }).ToList(); //write log int intUserID = objUserDao.GetUserIDByUserName(username); if (intUserID > 0) { CSF_Logs objLog = new CSF_Logs(); objLog.Controller_Action = controllerName + "-" + actionName; objLog.CreateDate = System.DateTime.Now; objLog.UserCreate = intUserID; //objLog.Content = descriptor.ToString(); MyContext.CSF_Logs.Add(objLog); MyContext.SaveChanges(); } var permission = ListPermission.Where(x => x.ca.Contains(ControllerAction.ToLower())).FirstOrDefault(); if (permission == null && username.ToLower().Trim() != "host") { base.OnActionExecuting(filterContext); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "home" }, { "action", "index" }, { "area", "" } }); } } else { //filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "home" }, { "action", "login" }, { "area", "" } }); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "Area", "" }, { "Controller", "home" }, { "Action", "login" }, { "RedirectUrl", filterContext.HttpContext.Request.Url } } ); } } catch (Exception ex) { Logs.WriteLog(ex); } }
public ActionResult Create(FormCollection fc, CSF_Users user) { try { ViewBag.isReload = 1; ViewBag.DonViSelect = Request.Form["MaDonVi"]; //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); if (ModelState.IsValid) { CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); //Kiểm tra trùng tên tài khoản if (objUsersDAO.CheckUserName(user.UserName.Trim())) { ModelState.AddModelError("", "Tên người dùng đã tồn tại!"); TempData.Keep("Roles"); return(View()); } int ReturnUserID = objUsersDAO.Insert(user); if (ReturnUserID > 0) { SetAlert("Thêm người dùng thành công", AlertType.Success); //Thêm người dùng vào nhóm CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO(); if (fc["chkRole_"] != null) { string[] arrRoleCheckBox = fc["chkRole_"].Split(','); int intRoleID = 0; for (int i = 0; i < arrRoleCheckBox.Length; i++) { intRoleID = Convert.ToInt32(arrRoleCheckBox[i].ToString()); objUserRoleDAO.Insert(user.ID, intRoleID); } } return(RedirectToAction("Index", "QT_Users")); } else { ModelState.AddModelError("", "Thêm người dùng không thành công"); } return(View("Index")); } TempData.Keep("Roles"); return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { string strUserName = model.UserName.Trim(); string strPass = Encryptor.MD5Hash(model.Password); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intResult = objUserDao.Login(strUserName, strPass); switch (intResult) { case 0: //Tên đăng nhập hoặc mật khẩu không đúng ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng!"); break; case 1: //Đăng nhập thành công if (model.RememberPass) { FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, model.UserName.Trim(), DateTime.Now, DateTime.Now.AddSeconds(20), false, "", FormsAuthentication.FormsCookiePath); //Encrypt the ticket string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //Create a cookie and add the encrypted ticket to the cookie as data HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); //Add the cookie to the outgoing cookie collection Response.Cookies.Add(authCookie); } FormsAuthentication.SetAuthCookie(model.UserName.Trim(), false); string url = System.Configuration.ConfigurationManager.AppSettings["SiteUrl"]; //Xác định redirect vào trang quản trị hay trang chính //if (model.UserName.Equals("host")) //{ //} //return Redirect(url + "/admin/qt_home"); //Hiển thời để redirect về trang chủ return(Redirect(model.ReturnURL ?? url)); case -1: ModelState.AddModelError("", "Tài khoản chưa được click hoạt!"); break; case -2: ModelState.AddModelError("", "Mật khẩu không đúng!"); break; default: break; } } return(View(model)); }
public JsonResult SetNgungCongBo(string[] arrChecked, string abc) { try { int ikq = 0; string[] arrIDTinTuc = arrChecked; CMS_News_DAO objNewsDao = new CMS_News_DAO(); CMS_Approves_DAO objApproverDao = new CMS_Approves_DAO(); CMS_Approves objApp = new CMS_Approves(); int iIDNews = 0; if (arrIDTinTuc != null && arrIDTinTuc.Length > 0) { for (int i = 0; i < arrIDTinTuc.Length; i++) { iIDNews = Convert.ToInt32(arrIDTinTuc[i].ToString()); objNewsDao.UpdateTrangThai(iIDNews, 6, 0); objApp.ID_News = iIDNews; objApp.ID_News_Status = 6; CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); objApp.ID_User = intUserID; objApp.Comment = abc; ikq = objApproverDao.Insert(objApp); } } if (ikq > 0) { //cache lai tin bai WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_TinBai(); return(Json(new { status = true, message = "Ngừng công bố tin tức thành công" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false, message = "Lỗi ngừng công bố tin tức" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Logs.WriteLog(ex); return(Json(new { status = false, message = "Lỗi: " + ex }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Index(LoginModel model) { if (ModelState.IsValid) { string strUserName = model.UserName.Trim(); string strPass = Encryptor.MD5Hash(model.Password); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intResult = objUserDao.Login(strUserName, strPass); switch (intResult) { case 0: //Tên đăng nhập hoặc mật khẩu không đúng ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng!"); break; case 1: //Đăng nhập thành công if (model.RememberPass) { FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, model.UserName.Trim(), DateTime.Now, DateTime.Now.AddMinutes(60), false, ""); //Encrypt the ticket string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //Create a cookie and add the encrypted ticket to the cookie as data HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); //Add the cookie to the outgoing cookie collection Response.Cookies.Add(authCookie); } FormsAuthentication.SetAuthCookie(model.UserName.Trim(), false); string url = ConfigurationManager.AppSettings["SiteUrl"]; return(Redirect(url + "/admin/qt_home")); case -1: ModelState.AddModelError("", "Tài khoản chưa được kích hoạt!"); break; case -2: ModelState.AddModelError("", "Mật khẩu không đúng!"); break; default: break; } } return(View(model)); }
public JsonResult SetDuyet(string[] arrChecked, string abc) { try { int ikq = 0; string[] arrIDTinTuc = arrChecked; CMS_News_DAO objNewsDao = new CMS_News_DAO(); CMS_Approves_DAO objApproverDao = new CMS_Approves_DAO(); CMS_Approves objApp = new CMS_Approves(); int iIDNews = 0; //int intRoleID = Convert.ToInt32(RoleID); //int intUserID = 0; //CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO(); if (arrIDTinTuc != null && arrIDTinTuc.Length > 0) { for (int i = 0; i < arrIDTinTuc.Length; i++) { iIDNews = Convert.ToInt32(arrIDTinTuc[i].ToString()); objNewsDao.UpdateTrangThai(iIDNews, 4, 0); objApp.ID_News = iIDNews; objApp.ID_News_Status = 4; CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); objApp.ID_User = intUserID; objApp.Comment = abc; ikq = objApproverDao.Insert(objApp); } } if (ikq > 0) { return(Json(new { status = true, message = "Duyệt tin tức thành công" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false, message = "Lỗi duyệt tin tức" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Logs.WriteLog(ex); return(Json(new { status = false, message = "Lỗi: " + ex }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Index(string searchString, int?page) { try { CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); var users = objUsersDAO.Search(searchString); ViewBag.SearchString = searchString; int pageSize = 10; int pageNumber = (page ?? 1); users = users.OrderBy(s => s.ID); return(View(users)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), "error"); Logs.WriteLog(ex); return(View()); } }
public ActionResult Create(FormCollection fc, CMS_Documents obj) { try { TempData.Keep("TypeOfDocumentID"); TempData.Keep("AreaOfDocument"); TempData.Keep("OrganizationID"); if (ModelState.IsValid) { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); if (objDAO.CheckExist_DocumentNumber(obj)) { SetAlert("Số hiệu đã tồn tại!", AlertType.Error); return(View()); } CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Thêm văn bản thành công", AlertType.Success); return(RedirectToAction("index", "cms_documents")); } else { ModelState.AddModelError("", "Thêm văn bản không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Index() { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); CSF_Roles_DAO objRolesDAO = new CSF_Roles_DAO(); var roles = objRolesDAO.GetAll(); TempData["Roles"] = roles.ToList(); var users = objUsersDAO.Search("").ToList(); TempData["Users"] = users; return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
//[CheckPermission] public JsonResult GetUsersGroup(string Name, string RoleID) { try { int intRoleID = Convert.ToInt32(RoleID); CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); List <CSF_Users_GetUsersNotInGroup_Result> listUser = objUsersDAO.GetUsersNotInGroup(Name, intRoleID).ToList(); //List user in group List <CSF_Users_GetUsersInGroup_Result> listUser1 = objUsersDAO.GetUsersInGroup(intRoleID).ToList(); var jsonResults = new { listUserNotInGroup = listUser, listUserInGroup = listUser1, status = true }; return(Json(jsonResults, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(null); } }
public JsonResult SaveSetupPage(CSF_PagePartial obj) { try { CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; CSF_Pages_DAO dao = new CSF_Pages_DAO(); int id = dao.PagePartialSave(obj); if (id > 0) { return(Json(new { state = true, message = "Thêm mới thành công" }, JsonRequestBehavior.AllowGet)); } return(Json(new { state = false, message = "Lỗi thêm mới" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { state = false, message = ex }, JsonRequestBehavior.AllowGet)); } }
public PartialViewResult MainMenu() { try { ViewBag.URLIMAGE = System.Configuration.ConfigurationManager.AppSettings["UrlImage"]; int intGuestGroup = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["IDGuestGroup"]); CSF_MVCEntities entities = new CSF_MVCEntities(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); string username = HttpContext.User.Identity.Name; List<int> lRoleID = objUserDao.GetRoleIDByUserName(username, intGuestGroup); string stringRoleID = String.Join(",", lRoleID); // List<CSF_Pages> listAllPage = new List<CSF_Pages>(); if (username.Trim().ToLower() != "host") { var lPageActiveID = entities.CSF_Pages_GetPageByRoleID(stringRoleID).Select(x => (int)x.id).ToList(); listAllPage = entities.CSF_Pages.Where(x => lPageActiveID.Contains(x.ID) && x.IsAdmin == false).OrderBy(x => x.Order).ToList(); } else { listAllPage = entities.CSF_Pages.Where(x => x.IsAdmin == false && x.IsBlank == false && x.IsActive == true).OrderBy(x => x.Order).ToList(); } // int sanphamtronggio = 0; if (Session["cart"] != null) { List<ShoppingCart> lCart = (List<ShoppingCart>)Session["cart"]; sanphamtronggio = lCart.Count(); } string stringMenu = buildTreeMenu(listAllPage, sanphamtronggio); MainMenu mainMenu = new MainMenu(); mainMenu.stringMenu = stringMenu; return PartialView(mainMenu); } catch (Exception ex) { Logs.WriteLog(ex); return PartialView(); } }
public JsonResult Delete(int id) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); if (objUsersDAO.Delete(id)) { SetAlert("Xóa người dùng thành công", AlertType.Success); return(Json(new { status = true, message = "" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false, message = "Lỗi xóa người dùng" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Logs.WriteLog(ex); return(Json(new { status = false, message = "Lỗi: " + ex }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create(FormCollection fc, CSF_Pages obj) { try { TempData.Keep("module"); TempData.Keep("page"); if (ModelState.IsValid) { CSF_Pages_DAO objDAO = new CSF_Pages_DAO(); if (objDAO.CheckExist_PageKey(obj)) { SetAlert("Key đã tồn tại!", AlertType.Error); return(View()); } CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { SetAlert("Thêm page thành công", AlertType.Success); return(RedirectToAction("Index", "QT_Pages")); } else { ModelState.AddModelError("", "Thêm page không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CSF_Users user) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); //Xóa nhóm hiện tại của người dùng CSF_UserRole_DAO objUserRoleDAO = new CSF_UserRole_DAO(); objUserRoleDAO.DelRoleByUserID(user.ID); CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); if (objUsersDAO.Update(user)) { if (fc["chkRole_"] != null) { string[] arrRoleCheckBox = fc["chkRole_"].Split(','); int intRoleID = 0; for (int i = 0; i < arrRoleCheckBox.Length; i++) { intRoleID = Convert.ToInt32(arrRoleCheckBox[i].ToString()); objUserRoleDAO.Insert(user.ID, intRoleID); } } SetAlert("Cập nhật người dùng thành công", AlertType.Success); return(RedirectToAction("Index", "QT_Users")); } else { ModelState.AddModelError("", "Cập nhật người dùng không thành công"); } return(View("Index")); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult UpdateInformation(string id) { try { CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); var user = objUsersDAO.GetByUserName(id); if (user == null) { return(RedirectToAction("Index", "QT_Home")); } if (id.ToLower().Trim() != HttpContext.User.Identity.Name.ToLower().Trim()) { return(RedirectToAction("Index", "QT_Home")); } ViewBag.ID = user.ID; return(View(user)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult UpdateInformation(FormCollection fc, CSF_Users user) { try { CSF_Users_DAO objUsersDAO = new CSF_Users_DAO(); if (objUsersDAO.Update(user)) { SetAlert("Cập nhật thông tin thành công", AlertType.Success); ViewBag.ID = user.ID; return(View()); } else { ModelState.AddModelError("", "Cập nhật thông tin không thành công"); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult CreateBanDo(FormCollection fc, CMS_Maps obj) { try { if (ModelState.IsValid) { string strThumbnailDir = System.Configuration.ConfigurationManager.AppSettings["ThumbnailFileUrl"].ToString(); var item = Request.Files.AllKeys.Where(m => m.StartsWith("Thumbnail")).FirstOrDefault(); var imgThumbnail = Request.Files[item]; if (imgThumbnail != null && imgThumbnail.ContentLength > 0) { //var fileName = "thumbnail_" + DateTime.Now.ToString("yyyyMMddhhmmsstt") + Guid.NewGuid().ToString() + Path.GetExtension(imgThumbnail.FileName); //obj.Thumbnail = fileName; // Save file //var path = Path.Combine(Server.MapPath(strThumbnailDir), fileName); //imgThumbnail.SaveAs(path); } else { //obj.Thumbnail = "thumbnail_DEFAULT.jpg"; } CMS_MapService objMapService = new CMS_MapService(); CMS_Maps_DAO objDAO = new CMS_Maps_DAO(); CMS_MapService_DAO objDAOMapService = new CMS_MapService_DAO(); string strIDService = "0"; if (fc["ddlServices"] != null) { strIDService = fc["ddlServices"].ToString(); } if (strIDService == "0") { SetAlert("Chọn Services", AlertType.Error); return(View()); } CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { objMapService.MapID = ReturnID; objMapService.Orders = 0; objMapService.ServiceID = Convert.ToInt32(strIDService); objDAOMapService.Insert(objMapService); SetAlert("Thêm bản đồ thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Maps")); } else { ModelState.AddModelError("", "Thêm bản đồ không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }