public ActionResult CreateEdit(user user, FormCollection frm, HttpPostedFileBase user_photo) { try { string rol_id = frm["rol_id"]; string hdnUserPhoto = frm["hdnUserPhoto"]; if (user_photo != null) { string AWSProfileName = STUtil.GetWebConfigValue("AWSProfileName"); string GenFileName = STUtil.GetTodayDate().ToString("yyyyMMdd") + "_" + SessionUtil.GetCompanyID().ToString() + "_" + Path.GetFileName(user_photo.FileName).Replace(" ", "_"); String companyFolderName = STUtil.GetSessionValue(UserInfo.CompanyFolderName.ToString()).ToString().Replace("/", ""); user.user_photo = GenFileName; } else { user.user_photo = hdnUserPhoto != null ? (hdnUserPhoto != "" ? hdnUserPhoto : user.gender + ".JPG") : user.gender + ".JPG"; } result = userUtil.PostCreateEdit(user, frm); ViewBag.Title = user == null ? "User Create" : "User Edit"; ViewBag.action_name = STUtil.GetListAllActionByController(""); switch (result.MessageType) { case MessageType.Success: return(RedirectToAction("Index", "User", new { id = rol_id, Result = result.Message, MessageType = result.MessageType })); default: return(RedirectToAction("CreateEdit", "User", new { id = user.user_id, Result = result.Message, MessageType = result.MessageType })); } return(View(user)); } catch (Exception ex) { return(View(user)); } }
public ActionResult Login(FormCollection frm) { String LoginResult = string.Empty; if (ModelState.IsValid) { try { String LoginID = frm["LoginID"]; String pwd = frm["password"]; LoginResult = RoleUtil.CheckUserFrofile(LoginID, pwd); if (LoginResult == "PASS") { var list = RoleUtil.GetMenusOfRoleId(Convert.ToInt32(STUtil.GetSessionValue(UserInfo.RoleID.ToString())), Convert.ToInt32(STUtil.GetSessionValue(UserInfo.CompanyID.ToString()))).ToList(); var menuObjects = (Session[UserInfo.MenuList.ToString()] as List <TreeNode>) ?? new List <TreeNode>(); menuObjects.AddRange(list); Session[UserInfo.MenuList.ToString()] = menuObjects; TempData["Login"] = "******"; return(RedirectToAction("Index/", "DashBoard")); } ViewBag.result = LoginResult; } catch (Exception ex) { // ExceptionLogging.SendErrorToText(ex); ViewBag.result = ex.Message; } } else { ViewBag.result = STUtil.GetValidationMessage(ModelState); } return(RedirectToAction("Login", new { Result = LoginResult, MessageType = "Error" })); //return View(); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { //filterContext.ActionDescriptor.ActionName.ToUpper().Equals("INDEX") && String ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToUpper(); String ActionName = filterContext.ActionDescriptor.ActionName.ToUpper(); List <TreeNode> AllList = Session[UserInfo.MenuList.ToString()] as List <TreeNode>; if (AllList != null) { var menuData = AllList.AsEnumerable().Where(x => (x.ControllerName ?? "").Trim().ToUpper() == ControllerName && (x.ActionName ?? "").Trim().ToUpper() == ActionName).FirstOrDefault(); string sludge = menuData == null ? "" : menuData.Sludge; string pageTitle = menuData == null ? "" : menuData.PageTitle; if (menuData != null) { STUtil.SetSessionValue(UserInfo.sludge.ToString(), sludge); STUtil.SetSessionValue(UserInfo.pageTitle.ToString(), pageTitle); } } if (STUtil.ListControllerExcluded().Contains(ControllerName)) { if (ControllerName == "ACCOUNT" && ActionName == "LOGIN" && STUtil.IsAuthenticated()) { filterContext.Result = new RedirectResult("/DashBoard/Index/"); } return; } else { if (STUtil.GetSessionValue(UserInfo.UserID.ToString()) == "") { filterContext.Result = null; filterContext.Result = new RedirectResult("/Account/Login/"); return; } if (!STUtil.CheckAuthentication(filterContext)) { filterContext.Result = null; filterContext.Result = new RedirectResult("/Home/AccessDenied/"); return; } //if (STUtil.IsAuthenticated() && STUtil.GetSessionValue(UserInfo.IsCompanySetup.ToString()) == "0" && ActionName != "COMPANYINDEX" && ActionName != "COMPANYCREATEEDIT") if (STUtil.IsAuthenticated() && STUtil.GetSessionValue(UserInfo.IsCompanySetup.ToString()) == "0" && ActionName != "COMPANYACCOUNT") { filterContext.Result = null; filterContext.Result = new RedirectResult("/Settings/CompanyAccount/"); return; } return; } }
public static bool IsInRole(Role role, Int64 RoleBit = 0, Boolean IsGetFromSession = true) { bool isRole = false; string roleValue = string.Empty; roleValue = IsGetFromSession ? STUtil.GetSessionValue(role.ToString()) : string.Empty; if (!string.IsNullOrEmpty(roleValue)) { isRole = Convert.ToString(roleValue).ToUpper() == "TRUE" ? true : false; return(isRole); } else { //return GetRoles(RoleBit).Where(x => x.Contains(role.ToString().ToUpper())).Count() > 0 ? true : false; var r = GetRoles(RoleBit); return(GetRoles(RoleBit).Where(x => x == (role.ToString().ToUpper())).Count() > 0 ? true : false); } }
public static List <string> GetRoles(Int64 RoleBit) { List <Int64> authlevels = new List <Int64>(); List <string> roles = new List <string>(); try { string roleBit = RoleBit == 0 ? STUtil.GetSessionValue(UserInfo.RoleBit.ToString()) : RoleBit.ToString(); if (!string.IsNullOrEmpty(roleBit)) { Int64 Value = Convert.ToInt64(roleBit); Int64 result = 0; for (Int64 i = 0; Value >= (Int64)Math.Pow(2, i); i++) { result = Value & (Int64)Math.Pow(2, i); authlevels.Add(result); } foreach (var item in authlevels) { var au = (from R in db.roles where R.role_bit == item select new { ROLE_BIT = R.role_bit, ROLE_NAME = R.role_name.Trim().ToUpper() } ).FirstOrDefault(); if (au != null) { roles.Add(au.ROLE_NAME); } } } } catch (Exception ex) { throw ex; } return(roles); }
public Result PostCreteEditJob(job job ,string Jobcomment,string jobCode ="100") { try { var createdBy = STUtil.GetSessionValue(UserInfo.FullName.ToString()); job.job_status_id = job.job_status_id == 0 ? 1 : job.job_status_id; var JobStatus = db.job_status.Find(job.job_status_id); if (job.job_id > 0) { string comment = "<div class ='container left'><div class='content'><b>Update By :" + createdBy + "</b></br><b>Updated ON:" + System.DateTime.Now.ToString("dd-MMM-yyyy") + "</b></br> <p>Job Update Successfully and Job Status is <b>"+ JobStatus.job_status_name+ "</b></p><b>Comment: </b><p>"+ job.comment + "</p></div></div>"; job.comment = comment +( string.IsNullOrEmpty(Jobcomment) ? "": Jobcomment); db.Entry(job).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); result.Message = string.Format(BaseConst.MSG_SUCCESS_UPDATE, "Job"); } else { string comment = "<div class ='container left'><div class='content'><b>Created By :" + createdBy + "</b></br><b>Created ON:" + System.DateTime.Now.ToString("dd-MMM-yyyy") + "</b></br> <p>Job Create Successfully and Job Status is <b>" + JobStatus.job_status_name + "</b></p><b>Comment: </b><p>" + job.comment + "</p></div></div>"; job.job_status_id = 1; job.comment = comment; job.job_code = "FG-"; db.jobs.Add(job); db.SaveChanges(); var jobObj = db.jobs.Find(job.job_id); jobObj.job_code = "FG-" + jobObj.job_id.ToString(); db.Entry(jobObj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); result.Message = string.Format(BaseConst.MSG_SUCCESS_CREATE, "Job"); } result.Id = job.job_id; } catch (Exception ex) { result.MessageType = MessageType.Error; result.Message = ex.Message; } return result; }
public ActionResult EditProfile(user user, HttpPostedFileBase user_photo) { try { if (user_photo != null) { string AWSProfileName = STUtil.GetWebConfigValue("AWSProfileName"); string GenFileName = STUtil.GetTodayDate().ToString("yyyyMMdd") + "_" + SessionUtil.GetCompanyID().ToString() + "_" + Path.GetFileName(user_photo.FileName).Replace(" ", "_"); String companyFolderName = STUtil.GetSessionValue(UserInfo.CompanyFolderName.ToString()).ToString().Replace("/", ""); UploadFile(SessionUtil.GetCompanyFolderName().ToString(), user_photo); user.user_photo = GenFileName; } else { } result = userUtil.PostProfileEdit(user); ViewBag.action_name = STUtil.GetListAllActionByController(""); switch (result.MessageType) { case MessageType.Success: STUtil.SetSessionValue(UserInfo.FullName.ToString(), Convert.ToString(user.user_name)); STUtil.SetSessionValue(UserInfo.Mobile.ToString(), Convert.ToString(user.mobile)); STUtil.SetSessionValue(UserInfo.UserPhoto.ToString(), Convert.ToString(user.user_photo)); STUtil.SetSessionValue(UserInfo.Gender.ToString(), Convert.ToString(user.gender)); return(RedirectToAction("MyProfile", "MyProfile", new { Result = result.Message, MessageType = result.MessageType })); default: return(RedirectToAction("MyProfile", "MyProfile", new { Result = result.Message, MessageType = result.MessageType })); } return(View(user)); } catch { return(View(user)); } }
public ActionResult UserResetPassword(FormCollection frm) { try { Int32 userID = Convert.ToInt32(frm["userID"]); String key = frm["key"]; //String LoginID = frm["LoginID"]; String Password = frm["password"]; //String BusinessName = frm["BusinessName"]; var userInfo = db.users.AsEnumerable().Where(x => x.user_id == userID && x.activation_reset_key == key && x.is_active == true).FirstOrDefault(); if (userInfo != null) { if (userInfo.reset_password_link_expire_date_time > STUtil.GetCurrentDateTime()) { userUtil.ResetUser(userID, key, Password); String LoginResult = RoleUtil.CheckUserFrofile("", "", userInfo.user_id); if (LoginResult == "PASS") { var list = RoleUtil.GetMenusOfRoleId(Convert.ToInt32(STUtil.GetSessionValue(UserInfo.RoleID.ToString())), Convert.ToInt32(STUtil.GetSessionValue(UserInfo.RoleID.ToString()))).ToList(); var menuObjects = (Session[UserInfo.MenuList.ToString()] as List <TreeNode>) ?? new List <TreeNode>(); menuObjects.AddRange(list); Session[UserInfo.MenuList.ToString()] = menuObjects; return(RedirectToAction("Index/", "DashBoard")); } else { return(RedirectToAction("Login", "Account", new { result = "Invalid Request", MessageType = "Error" })); } } else { ViewBag.result = "Your password reset link has been expired!!!"; return(RedirectToAction("Login", "Account", new { result = "Your password reset link has been expired!!!", MessageType = "Error" })); } } else { ViewBag.result = "Invalid Request"; return(RedirectToAction("Login", "Account", new { result = "Invalid Request", MessageType = "Error" })); } } catch (Exception ex) { ViewBag.result = ex.Message; return(RedirectToAction("Login", "Account", new { result = ex.Message, MessageType = "Error" })); } return(View()); }
public ActionResult UserAuthenticate(FormCollection frm) { try { Int32 userID = Convert.ToInt32(frm["userID"]); String key = frm["key"]; String LoginID = frm["LoginID"]; String Password = frm["password"]; String BusinessName = frm["BusinessName"]; Boolean isLoginIDExist = userUtil.IsLoginIDExist(LoginID) == null ? false : true; if (!isLoginIDExist) { var userInfo = db.users.AsEnumerable().Where(x => x.user_id == userID && x.activation_reset_key == key && x.is_active == false).FirstOrDefault(); if (userInfo != null) { userUtil.ActivateUser(userID, key, LoginID, Password, BusinessName); String LoginResult = RoleUtil.CheckUserFrofile("", "", userInfo.user_id); if (LoginResult == "PASS") { var list = RoleUtil.GetMenusOfRoleId(Convert.ToInt32(STUtil.GetSessionValue(UserInfo.RoleID.ToString())), Convert.ToInt32(STUtil.GetSessionValue(UserInfo.CompanyID.ToString()))).ToList(); var menuObjects = (Session[UserInfo.MenuList.ToString()] as List <TreeNode>) ?? new List <TreeNode>(); menuObjects.AddRange(list); Session[UserInfo.MenuList.ToString()] = menuObjects; return(RedirectToAction("Index/", "DashBoard")); } } else { ViewBag.result = "Invalid Request"; } } else { ViewBag.result = "LoginID '" + LoginID + " already exist!!"; } } catch (Exception ex) { ViewBag.result = ex.Message; return(RedirectToAction("Login", "Account", new { result = ex.Message, MessageType = "Error" })); } return(View()); }