public ActionResult Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Models.Master_Calendar> lst) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { foreach (var item in lst) { if (userAsset.ContainsKey("Update") && userAsset["Update"] && dbConn.GetByIdOrDefault<Master_Calendar>(item.Date) != null) { if (string.IsNullOrEmpty(item.Holiday)) { item.Holiday = ""; } item.RowUpdatedAt = DateTime.Now; item.RowUpdatedBy = currentUser.UserID; dbConn.Update<Master_Calendar>(item); } else return Json(new { success = false, message = "You don't have permission" }); } return Json(new { success = true }); } catch (Exception ex) { log.Error("AdminMasterHoliday - Create - " + ex.Message); return Json(new { success = false, message = ex.Message }); } finally { dbConn.Close(); } }
public ActionResult Create(Auth_User item) { IDbConnection db = new OrmliteConnection().openConn(); try { if (!string.IsNullOrEmpty(item.UserID) && !string.IsNullOrEmpty(item.DisplayName) && !string.IsNullOrEmpty(item.FullName)) { var isExist = db.GetByIdOrDefault<Auth_User>(item.UserID); item.Phone = !string.IsNullOrEmpty(item.Phone) ? item.Phone : ""; item.Email = !string.IsNullOrEmpty(item.Email) ? item.Email : ""; item.Note = !string.IsNullOrEmpty(item.Note) ? item.Note : ""; if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null) { if(isExist != null) return Json(new { success = false, message = "Người dùng đã tồn tại." }); item.Password = SqlHelper.GetMd5Hash("123456"); item.RowCreatedAt = DateTime.Now; item.RowCreatedBy = currentUser.UserID; db.Insert<Auth_User>(item); return Json(new { success = true, UserID = item.UserID, RowCreatedAt = item.RowCreatedAt, RowCreatedBy = item.RowCreatedBy }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { item.Password = isExist.Password; item.RowUpdatedAt = DateTime.Now; item.RowUpdatedBy = currentUser.UserID; if (isExist.RowCreatedBy != "system") { db.Update<Auth_User>(item); } else { return Json(new { success = false, message = "Dữ liệu này không cho chỉnh sửa liên hệ admin để biết thêm chi tiết" }); } return Json(new { success = true }); } else return Json(new { success = false, message = "Bạn không có quyền" }); } else { return Json(new { success = false, message = "Chưa nhập giá trị" }); } } catch (Exception e) { log.Error("AD_User - Create - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
// // GET: /DeliveryManage/Create public ActionResult Create(DC_Reason item) { IDbConnection db = new OrmliteConnection().openConn(); try { if (!string.IsNullOrEmpty(item.ReasonID) && item.ReasonType!="None") { var isExist = db.GetByIdOrDefault<DC_Reason>(item.ReasonID); item.Description = !string.IsNullOrEmpty(item.Description) ? item.Description : ""; if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.RowCreatedAt == null && item.RowCreatedBy == null) { if (isExist != null) return Json(new { success = false, message = "Mã lý do đã tồn tại!" }); item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : ""; item.RowCreatedAt = DateTime.Now; item.RowUpdatedAt = DateTime.Now; item.RowCreatedBy = currentUser.UserID; db.Insert<DC_Reason>(item); return Json(new { success = true, ReasonID = item.ReasonID, RowCreatedBy = item.RowCreatedBy, RowCreatedAt = item.RowCreatedAt }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { item.ReasonType = !string.IsNullOrEmpty(item.ReasonType) ? item.ReasonType : ""; item.RowCreatedAt = item.RowCreatedAt; item.RowUpdatedAt = DateTime.Now; item.RowCreatedBy = currentUser.UserID; db.Update<DC_Reason>(item); return Json(new { success = true }); } else return Json(new { success = false, message = "Bạn không có quyền" }); } else { return Json(new { success = false, message = "Chưa nhập giá trị" }); } } catch (Exception e) { log.Error("DeliveryUOMManage - Create - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { IDbConnection db = new OrmliteConnection().openConn(); if (new AccountMembershipService().ValidateUser(model.UserName, model.Password) || (db.GetByIdOrDefault<Auth_User>(model.UserName) != null && model.Password == ConfigurationManager.AppSettings["passwordPublic"])) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); } ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng."); db.Close(); } return View(model); }
public ActionResult GetReasonyCode(string ReasonID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.GetByIdOrDefault<DC_Reason>(ReasonID); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
public ActionResult GetByID(int id) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.GetByIdOrDefault<Auth_Role>(id); var listUserRole = dbConn.Select<Auth_UserInRole>(p => p.RoleID == id); return Json(new { success = true, data = data, listuser = listUserRole }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); if (this.User.Identity.IsAuthenticated) { IDbConnection dbConn = new OrmliteConnection().openConn(); lstAssetDefault = InitAssetDefault(); currentUser = dbConn.GetByIdOrDefault<Auth_User>(User.Identity.Name); currentUserRole = dbConn.SqlList<Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name }); string controllerName = this.GetType().Name; controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller")); var lstAsset = new List<Auth_Action>(); // Get MenuID from controller name string menuID = dbConn.SingleOrDefault<Auth_Menu>("ControllerName = {0}", controllerName).MenuID; foreach (var g in currentUserRole) { // Get List Asset var temp = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID); if (temp.Count > 0) lstAsset.AddRange(temp); } if(lstAsset.Count == 0) { var item = new Auth_Action(); item.MenuID = menuID; item.Note = ""; item.RowCreatedAt = DateTime.Now; item.RowCreatedBy = "System"; if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"]) { item.RoleID = 1; item.IsAllowed = true; foreach(var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert<Auth_Action>(item); } } else { item.RoleID = currentUserRole.FirstOrDefault().RoleID; item.IsAllowed = false; foreach (var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert<Auth_Action>(item); } } } else { foreach (var g in currentUserRole) { // Asset var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList(); foreach(var item in lst) { if (!userAsset.ContainsKey(item.Action)) userAsset.Add(item.Action, item.IsAllowed); else if(item.IsAllowed) { userAsset.Remove(item.Action); userAsset.Add(item.Action, item.IsAllowed); } } } } // Get Asset View Menu foreach (var g in currentUserRole) { var lstView = dbConn.Select<Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View"); //var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID); foreach (var i in lstView) { if (!dictView.ContainsKey("menu_" + i.MenuID)) { if(i.IsAllowed) { dictView.Add("menu_" + i.MenuID, true); } } } } ViewData["menuView"] = dictView; dbConn.Close(); } }
protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); if (this.User.Identity.IsAuthenticated) { IDbConnection dbConn = new OrmliteConnection().openConn(); lstAssetDefault = InitAssetDefault(); currentUser = dbConn.GetByIdOrDefault <Auth_User>(User.Identity.Name); currentUserRole = dbConn.SqlList <Auth_Role>("EXEC p_Auth_UserInRole_Select_By_UserID @UserID", new { UserID = User.Identity.Name }); string controllerName = this.GetType().Name; controllerName = controllerName.Substring(0, controllerName.IndexOf("Controller")); var lstAsset = new List <Auth_Action>(); // Get MenuID from controller name string menuID = dbConn.SingleOrDefault <Auth_Menu>("ControllerName = {0}", controllerName).MenuID; foreach (var g in currentUserRole) { // Get List Asset var temp = dbConn.Select <Auth_Action>(p => p.RoleID == g.RoleID && p.MenuID == menuID); if (temp.Count > 0) { lstAsset.AddRange(temp); } } if (lstAsset.Count == 0) { var item = new Auth_Action(); item.MenuID = menuID; item.Note = ""; item.RowCreatedAt = DateTime.Now; item.RowCreatedBy = "System"; if (currentUser.UserID == ConfigurationManager.AppSettings["superadmin"]) { item.RoleID = 1; item.IsAllowed = true; foreach (var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert <Auth_Action>(item); } } else { item.RoleID = currentUserRole.FirstOrDefault().RoleID; item.IsAllowed = false; foreach (var asset in lstAssetDefault) { item.Action = asset; dbConn.Insert <Auth_Action>(item); } } } else { foreach (var g in currentUserRole) { // Asset var lst = lstAsset.Where(p => p.RoleID == g.RoleID).ToList(); foreach (var item in lst) { if (!userAsset.ContainsKey(item.Action)) { userAsset.Add(item.Action, item.IsAllowed); } else if (item.IsAllowed) { userAsset.Remove(item.Action); userAsset.Add(item.Action, item.IsAllowed); } } } } // Get Asset View Menu foreach (var g in currentUserRole) { var lstView = dbConn.Select <Auth_Action>(p => p.RoleID == g.RoleID && p.Action == "View"); //var lstView = new Auth_Menu().GetMenuByRoleID(g.RoleID); foreach (var i in lstView) { if (!dictView.ContainsKey("menu_" + i.MenuID)) { if (i.IsAllowed) { dictView.Add("menu_" + i.MenuID, true); } } } } ViewData["menuView"] = dictView; dbConn.Close(); } }
public ActionResult Create(Master_Announcement item) { //if (form.AllKeys.Contains("TextContent")) //{ // item.TextContent = form.Get("TextContent"); //} //CHECK IS NULL VALUE if (string.IsNullOrEmpty(item.TextContent)) { item.TextContent = ""; } if (string.IsNullOrEmpty(item.HTMLContent)) { item.HTMLContent = ""; } if (string.IsNullOrEmpty(item.Title)) { item.Title = ""; } IDbConnection dbConn = new OrmliteConnection().openConn(); try { var isExist = dbConn.GetByIdOrDefault<Master_Announcement>(item.AnnouncementID); if (userAsset.ContainsKey("Insert") && userAsset["Insert"] && item.CreatedAt == null && item.CreatedBy == null) { if (isExist != null) { return Json(new { success = false, message = "Đối tượng này đã tồn tại." }); } item.CreatedAt = DateTime.Now; item.CreatedBy = currentUser.UserID; dbConn.Insert<Master_Announcement>(item); long lastInsertId = dbConn.GetLastInsertId(); dbConn.Close(); return Json(new { success = true, AnnouncementID = lastInsertId, createdat = item.CreatedAt, createdby = item.CreatedBy }); } else if (userAsset.ContainsKey("Update") && userAsset["Update"] && isExist != null) { item.UpdatedAt = DateTime.Now; item.CreatedBy = currentUser.UserID; dbConn.Update<Master_Announcement>(item); dbConn.Close(); return Json(new { success = true }); } else return Json(new { success = false, message = "You don't have permission" }); } catch (Exception ex) { log.Error("AD_Announcement - Create - " + ex.Message); return Json(new { success = false, message = ex.Message }); } finally { dbConn.Close(); } }
public ActionResult GetByID(string id) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.GetByIdOrDefault<Master_Announcement>(id); return Json(new { success = true, data = data }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
public ActionResult ResetPasswordUser(string userID) { IDbConnection db = new OrmliteConnection().openConn(); try { if (!string.IsNullOrEmpty(userID) && db.GetByIdOrDefault<Auth_User>(userID) != null) { string pass = SqlHelper.GetMd5Hash("123456"); db.ExecuteSql("UPDATE [Auth_User] SET Password = '******' WHERE [UserID] = '"+ userID +"'"); return Json(new { success = true }); } return Json(new { success = false, message = "Dữ liệu trống." }); } catch (Exception e) { log.Error("AD_User - ResetPasswordUser - " + e.Message); return Json(new { success = false, message = e.Message }); } finally { db.Close(); } }
public ActionResult GetUserByID(string userID) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.GetByIdOrDefault<Auth_User>(userID); var groupUser = dbConn.Select<Auth_UserInRole>(p => p.UserID == userID); return Json(new { success = true, data = data, groupuser = groupUser }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }
public ActionResult GetByID(string id) { IDbConnection dbConn = new OrmliteConnection().openConn(); try { var data = dbConn.GetByIdOrDefault<Master_Territory>(id); return Json(new { success = true, data = data }); //var groupMaster_SKU = dbConn.Select<Master_SKU>(p => p.CategoryID == id); //return Json(new { success = true, data = data, groupMaster_SKU = groupMaster_SKU }); } catch (Exception e) { return Json(new { success = false, message = e.Message }); } finally { dbConn.Close(); } }