public ActionResult RoleDelete(int id) { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; string msg = ""; try { AT_Role role = db.AT_Role.Where(x => x.RoleID == id).FirstOrDefault(); if (role != null) { if (db.AT_Users.Where(x => x.RoleID == role.RoleID && x.IsDeleted != true).Count() > 0) { return(Json("Conflict")); } //role.RoleID = id; //role.IsDeleted = true; //role.UpdateBy = sess.User.UserID; //role.UpdateDate = DateTime.Now; //db.AT_Role.Attach(role); db.AT_RolePermissionJunc.RemoveRange(db.AT_RolePermissionJunc.Where(x => x.RoleID == role.RoleID)); db.AT_Role.Remove(role); db.SaveChanges(); msg = "Role deleted successfully!"; } } catch (Exception ex) { msg = ex.Message; } ViewBag.msg = msg; return(PartialView("_RoleIndex", db.AT_Role.Where(x => x.IsDeleted != true).ToList())); }
public ActionResult AgentDelete(int id) { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; string msg = ""; AT_Users usr = db.AT_Users.Where(x => x.UserID == id).FirstOrDefault(); try { if (usr != null) { usr.IsDeleted = true; usr.UpdateBy = sess.User.UserID; usr.UpdateDate = DateTime.Now; db.AT_Users.Attach(usr); db.UpdateOnly <AT_Users>(usr, x => x.IsDeleted, x => x.UpdateBy, x => x.UpdateDate); db.SaveChanges(); msg = "User Successfully Deleted."; } } catch (Exception ex) { msg = ex.Message; } db = new HRMSEntities(); ViewBag.msg = msg; return(PartialView("_AgentIndex", db.AT_Users.Where(a => a.IsDeleted != true).ToList())); }
public ActionResult SaveExtraPermission(string lst) { string msg = ""; Session_CRM sess = (Session_CRM)Session["CRM_Session"]; List <ExtraPermissions> lstEP = JsonConvert.DeserializeObject <List <ExtraPermissions> >(lst); foreach (var item in lstEP) { if (item.Allow) { var isexist = db.AT_UserExtraPermissionjunc.Where(x => x.UserID == item.UserID && x.PermissionGroupID == item.PermissionGroupID).FirstOrDefault(); if (isexist == null) { AT_UserExtraPermissionjunc jnc = new AT_UserExtraPermissionjunc(); jnc.PermissionGroupID = item.PermissionGroupID; jnc.UserID = item.UserID; // jnc.ClientID = sess.User.ClientID; db.Entry(jnc).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } } else { var isexist = db.AT_UserExtraPermissionjunc.Where(x => x.UserID == item.UserID && x.PermissionGroupID == item.PermissionGroupID).FirstOrDefault(); if (isexist != null) { db.AT_UserExtraPermissionjunc.Where(x => x.PermissionGroupID == item.PermissionGroupID && x.UserID == item.UserID).ToList().ForEach(tol => db.AT_UserExtraPermissionjunc.Remove(tol)); db.SaveChanges(); } } } return(Json(new { msg = msg }, JsonRequestBehavior.AllowGet)); }
public ActionResult _New(Branch branch) { string msg = ""; sess = (Session_CRM)Session["CRM_Session"]; var UserID = sess.User.UserID; if (branch.BranchID == 0 || branch.BranchID == null) { Branch _branch = new Branch(); _branch.Name = branch.Name; _branch.CreatedBy = UserID; _branch.CreateDate = DateTime.Now; _branch.IsActive = true; db.Branches.Add(_branch); db.SaveChanges(); } else { } List <Branch> brnch = new List <Branch>(); try { brnch = db.Branches.Where(x => x.IsActive == true).ToList(); } catch (Exception ex) { err.WriteError(ex); } return(PartialView("_Index", brnch)); }
public ActionResult Save(AT_Pages peg) { string msg = ""; try { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; if (peg.PageID > 0) { db.AT_Pages.Attach(peg); db.UpdateExcept <AT_Pages>(peg); } else { db.Entry(peg).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); msg = "Page saved successfully!"; } catch (Exception ex) { msg = ex.Message; } ViewBag.msg = msg; db = new HRMSEntities(); return(PartialView("_Index", db.AT_Pages.ToList())); }
public ActionResult Index() { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; sess = null; return(View()); }
public static bool CheckPermissions(string Permissions, string Page) { Session_CRM sess = (Session_CRM)HttpContext.Current.Session["CRM_Session"]; var Allow = sess.AllPermissions.Where(x => x.AT_Pages.Controller == Page && x.AT_Permission.Permission == Permissions).FirstOrDefault(); return(Allow == null ? false : true); }
public ActionResult PermissionSave(string strlstPermission, string strlstGroup, int RoleID) { string msg = ""; try { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; DataTable lstPermission = JsonConvert.DeserializeObject <DataTable>(strlstPermission); DataTable lstGroup = JsonConvert.DeserializeObject <DataTable>(strlstGroup); db.AT_RolePermissionJunc.Where(x => x.RoleID == RoleID).ToList().ForEach(tol => db.AT_RolePermissionJunc.Remove(tol)); db.SaveChanges(); foreach (DataRow Permission in lstPermission.Rows) { if (Convert.ToBoolean(Permission["Allow"])) { AT_RolePermissionJunc RP = new AT_RolePermissionJunc(); RP.ClientID = 1; RP.PermissionID = Convert.ToInt32(Permission["PermissionID"]); RP.RoleID = RoleID; RP.IsGroup = false; db.AT_RolePermissionJunc.Add(RP); } } foreach (DataRow Group in lstGroup.Rows) { if (Convert.ToBoolean(Group["Allow"])) { AT_RolePermissionJunc RP = new AT_RolePermissionJunc(); RP.ClientID = 1; RP.PermissionID = Convert.ToInt32(Group["PermissionGroupID"]); RP.RoleID = RoleID; RP.IsGroup = true; db.AT_RolePermissionJunc.Add(RP); } } db.SaveChanges(); msg = "Permission saved successfully!"; } catch (Exception ex) { msg = ex.Message; } ViewBag.msg = msg; return(PartialView("RoleIndex", db.AT_Role.Where(x => x.IsDeleted == false).ToList())); }
public ActionResult _PermissionGroupSave(AT_PermissionGroup pg) { string msg = ""; try { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; DataTable lstP = JsonConvert.DeserializeObject <DataTable>(pg.json_Permissions); if (pg.PermissionGroupID > 0) { // pg.ClientID = sess.User.ClientID; pg.UpdateBy = sess.User.UserID; pg.UpdateDate = DateTime.Now; db.AT_PermissionGroup.Attach(pg); db.UpdateExcept <AT_PermissionGroup>(pg, x => x.CreateBy, x => x.CreateDate); } else { // pg.ClientID = sess.User.ClientID; pg.CreateBy = sess.User.UserID; pg.CreateDate = DateTime.Now; db.Entry(pg).State = System.Data.Entity.EntityState.Added; } db.AT_PermissionGroupJunc.Where(x => x.PermissionGroupID == pg.PermissionGroupID).ToList().ForEach(tol => db.AT_PermissionGroupJunc.Remove(tol)); db.SaveChanges(); foreach (DataRow item in lstP.Rows) { if (Convert.ToBoolean(item["Allow"])) { AT_PermissionGroupJunc pgj = new AT_PermissionGroupJunc(); pgj.PermissionGroupID = pg.PermissionGroupID; pgj.PermissionID = Convert.ToInt32(item["PermissionID"]); pgj.ClientID = 1; db.AT_PermissionGroupJunc.Add(pgj); } } db.SaveChanges(); msg = "Permission Group saved successfully!"; } catch (Exception ex) { msg = ex.Message; } ViewBag.msg = msg; return(PartialView("_PermissionGroupIndex", db.AT_PermissionGroup.ToList())); }
public ActionResult UserProfileSave(AT_Users usr) { string msg = ""; Session_CRM sess = (Session_CRM)Session["CRM_Session"]; try { var modal = db.AT_Users.AsNoTracking().Where(x => x.UserID == usr.UserID).FirstOrDefault(); // usr.TypeID = modal.TypeID; usr.RoleID = modal.RoleID; usr.UserID = sess.User.UserID; usr.Password = usr.Password != modal.Password ? CRM_Common.Encrypt(usr.Password) : usr.Password; if (usr.upload != null && usr.upload.ContentLength > 0) { usr.PicName = usr.upload.FileName; Guid g; g = Guid.NewGuid(); string targetFolder = Server.MapPath("~/App_Data/Images"); string targetPath = Path.Combine(targetFolder, g.ToString() + Path.GetExtension(usr.upload.FileName)); usr.upload.SaveAs(targetPath); usr.PicName = "/App_Data/Images/" + g.ToString() + Path.GetExtension(usr.upload.FileName); usr.PicGuid = g.ToString(); db.AT_Users.Attach(usr); db.UpdateOnly <AT_Users>(usr, x => x.FirstName, x => x.LastName, x => x.PicName, x => x.PicGuid, x => x.Email, x => x.Phone, x => x.Password); if (sess != null) { sess.User.PicGuid = usr.PicGuid; sess.User.PicName = usr.PicName; } } else { db.AT_Users.Attach(usr); db.UpdateOnly <AT_Users>(usr, x => x.FirstName, x => x.LastName, x => x.Email, x => x.Phone, x => x.Password); } db.SaveChanges(); msg = "Update successfully!"; } catch (Exception ex) { msg = ex.Message; } ViewBag.msg = msg; return(PartialView("UserProfileIndex", db.AT_Users.Where(x => x.UserID == sess.User.UserID).FirstOrDefault())); }
public ActionResult _AgentSave(AT_Users usr) { string msg = ""; Session_CRM sess = (Session_CRM)Session["CRM_Session"]; try { // var UserType = db.AT_UserType.Where(x => x.UserType == "Agent").Select(x => x.TypeID).FirstOrDefault(); //usr.TypeID = UserType; // usr.ClientID = sess.User.ClientID; // AT_Agent det = usr.Agent; usr.Password = CRM_Common.Encrypt(usr.Password); if (usr.UserID > 0) { usr.UpdateBy = sess.User.UserID; usr.UpdateDate = DateTime.Now; db.AT_Users.Attach(usr); db.UpdateExcept <AT_Users>(usr, x => x.CreateBy, x => x.CreateDate); db.SaveChanges(); } else { usr.CreateBy = sess.User.UserID; usr.CreateDate = DateTime.Now; db.Entry(usr).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } msg = "User saved successfully!"; } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.ToString().Contains("UNIQUE")) { msg = "Conflict"; } else { msg = ex.Message; } } ViewBag.msg = msg; db = new HRMSEntities(); ViewBag.msg = msg; return(PartialView("_AgentIndex", db.AT_Users.Where(a => a.IsDeleted != true).ToList())); }
public JsonResult GetGroupPermission(string strlstPP) { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; DataTable lstPP = JsonConvert.DeserializeObject <DataTable>(strlstPP); List <int> gid = new List <int>(); foreach (DataRow item in lstPP.Rows) { if (Convert.ToBoolean(item["Allow"])) { gid.Add(Convert.ToInt32(item["PermissionGroupID"])); } } var lst = db.AT_PermissionGroupJunc.Where(x => gid.Contains(x.PermissionGroupID) && x.AT_Permission.IsActive == true).Select(x => x.AT_Permission.Permission).ToList(); return(Json(new { lst = lst }, JsonRequestBehavior.AllowGet)); }
public ActionResult _RoleSave(AT_Role role) { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; string msg = ""; try { if (role.RoleID > 0) { if (role.IsActive != true) { if (db.AT_Users.Where(x => x.RoleID == role.RoleID && x.IsDeleted != true).Count() > 0) { return(Json("Conflict")); } } role.UpdateBy = sess.User.UserID; role.UpdateDate = DateTime.Now; db.AT_Role.Attach(role); db.UpdateExcept <AT_Role>(role, x => x.CreateBy, x => x.CreateDate); } else { role.CreateBy = sess.User.UserID; role.CreateDate = DateTime.Now; db.Entry(role).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); msg = "Role saved successfully!"; } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.ToString().Contains("UNIQUE")) { msg = "Conflict"; } else { msg = ex.Message; } } ViewBag.msg = msg; return(PartialView("_RoleIndex", db.AT_Role.Where(x => x.IsDeleted != true).ToList())); }
public ActionResult Save(AT_Permission per) { string msg = ""; try { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; if (per.PermissionID > 0) { db.AT_Permission.Attach(per); db.UpdateExcept <AT_Permission>(per); } else { db.Entry(per).State = System.Data.Entity.EntityState.Added; } db.SaveChanges(); db.AT_PermissionActionJunc.Where(x => x.PermissionID == per.PermissionID).ToList().ForEach(tol => db.AT_PermissionActionJunc.Remove(tol)); db.SaveChanges(); string[] act = per.Actions.Split(','); for (int i = 0; i < act.Length; i++) { AT_PermissionActionJunc PA = new AT_PermissionActionJunc(); PA.PermissionID = per.PermissionID; PA.Action = act[i].ToString(); db.Entry(PA).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); } GenerateClass(); msg = "Permission saved successfully!"; } catch (Exception ex) { msg = ex.Message; } ViewBag.msg = msg; db = new HRMSEntities(); return(PartialView("_Index", db.AT_Permission.ToList())); }
public ActionResult AgentIndex() { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; return(PartialView("AgentIndex", db.AT_Users.Where(a => a.IsDeleted != true).ToList())); }
public BranchController() { sess = new Session_CRM(); err = new ErrorHandling(); }
public async Task <ActionResult> Index(string email, string password) { bool isTrailExist = false; int dayEnd = 0; int TotalDaysTrail = 0; string encpass = CRM_Common.Encrypt(password); AT_Users userlist = db.AT_Users.Where(x => x.Email == email && x.Password == encpass).FirstOrDefault <AT_Users>(); if (userlist != null) { if (userlist.IsActive) { if (db.AT_Role.Where(x => x.RoleID == userlist.RoleID).Select(x => x.IsActive).FirstOrDefault()) { Session_CRM sess = new Session_CRM(); List <Permissions> pplst = (from P in db.AT_Pages join PP in db.AT_Permission.Include("AT_PermissionActionJunc") on P.PageID equals PP.PageID join M in db.AT_Modules on P.ModuleID equals M.ModuleID join Per in db.AT_RolePermissionJunc on new { PermissionID = PP.PermissionID, IsGroup = false } equals new { PermissionID = Per.PermissionID, IsGroup = Per.IsGroup } where Per.RoleID == userlist.RoleID && P.IsActive == true && PP.IsActive == true select(new Permissions { AT_Pages = P, AT_Permission = PP, AT_Modules = M, AT_RolePermissionJunc = Per, AT_PermissionActionJunc = PP.AT_PermissionActionJunc.ToList() })).OrderBy(x => x.AT_Pages.PageOrder).ToList(); List <Permissions> pplst2 = (from P in db.AT_Pages join PP in db.AT_Permission.Include("AT_PermissionActionJunc") on P.PageID equals PP.PageID join M in db.AT_Modules on P.ModuleID equals M.ModuleID join Pj in db.AT_PermissionGroupJunc on PP.PermissionID equals Pj.PermissionID join Per in db.AT_RolePermissionJunc on new { PermissionID = Pj.PermissionGroupID, IsGroup = true } equals new { PermissionID = Per.PermissionID, IsGroup = Per.IsGroup } where Per.RoleID == userlist.RoleID && P.IsActive == true && PP.IsActive == true select(new Permissions { AT_Pages = P, AT_Permission = PP, AT_Modules = M, AT_RolePermissionJunc = Per, AT_PermissionActionJunc = PP.AT_PermissionActionJunc.ToList() })).OrderBy(x => x.AT_Pages.PageOrder).ToList(); List <Permissions> pplst3 = (from P in db.AT_Pages join PP in db.AT_Permission.Include("AT_PermissionActionJunc") on P.PageID equals PP.PageID join M in db.AT_Modules on P.ModuleID equals M.ModuleID join Pj in db.AT_PermissionGroupJunc on PP.PermissionID equals Pj.PermissionID join Per in db.AT_UserExtraPermissionjunc on new { PermissionGroupID = Pj.PermissionGroupID, IsExtrapermission = true } equals new { PermissionGroupID = Per.PermissionGroupID, IsExtrapermission = Per.AT_PermissionGroup.IsExtrapermission } where Per.UserID == userlist.UserID && P.IsActive == true && PP.IsActive == true select(new Permissions { AT_Pages = P, AT_Permission = PP, AT_Modules = M, AT_UserExtraPermissionjunc = Per, AT_PermissionActionJunc = PP.AT_PermissionActionJunc.ToList() })).OrderBy(x => x.AT_Pages.PageOrder).ToList(); List <Permissions> finallst = pplst.Union(pplst2).Union(pplst3).ToList <Permissions>(); if (finallst.Count() > 0) { sess.AllPermissions = finallst; var result = finallst.Select(z => z.AT_Modules).GroupBy(x => new { x.ModuleID }).Select(z => new AT_Modules { IsActive = z.FirstOrDefault().IsActive, ModuleIcon = z.FirstOrDefault().ModuleIcon, ModuleID = z.Key.ModuleID, ModuleName = z.FirstOrDefault().ModuleName, ModuleOrder = z.FirstOrDefault().ModuleOrder, ParentID = z.FirstOrDefault().ParentID, AT_Pages = z.FirstOrDefault().AT_Pages.ToList() }).ToList(); sess.AT_Modules = result; sess.User = userlist; sess.User.CRM_URL = Request.Url.AbsoluteUri; Session.Add("CRM_Session", sess); return(RedirectToAction("Index", "Home")); } else { ViewBag.msg = "You have not rights for login!"; return(View()); } } else { ViewBag.msg = "User role inactive!"; return(View()); } } else { ViewBag.msg = "User inactive!"; return(View()); } } else { ViewBag.msg = "Login Failed!"; return(View()); } }
public ActionResult RoleIndex() { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; return(PartialView("RoleIndex", db.AT_Role.Where(x => x.IsDeleted != true).ToList())); }
public ActionResult UserProfileIndex() { Session_CRM sess = (Session_CRM)Session["CRM_Session"]; return(PartialView("UserProfileIndex", db.AT_Users.Where(x => x.UserID == sess.User.UserID).FirstOrDefault())); }