public ActionResult ChangePassword() { if (Session["UserID"] != null) { int UserID = Convert.ToInt32(Session["UserID"].ToString()); var UserInfo = _secUserInfoService.All().ToList().FirstOrDefault(x => x.UserID == UserID); if (UserInfo != null) { ViewBag.OldPassword = UserInfo.Password; } } return(View("~/Views/Security/ChangePassword.cshtml")); }
public SelectList PermittedBranch() { var UserId = _secUserInfoService.All().Where(x => x.UserName == Session["UserName"].ToString()).FirstOrDefault().UserID; List <Branch> branchs = _BranchService.All().ToList(); List <UserBranch> userbranch = _userbranchService.All().ToList(); var branchInfo = (from ii in userbranch join i in branchs on ii.BranchCode equals i.BranchCode where ii.Userid == UserId.ToString() select new { BranchCode = ii.BranchCode, BranchName = i.BranchName }).ToList(); if (branchInfo.Count == 1) { return(new SelectList(branchInfo.OrderBy(x => x.BranchCode), "BranchCode", "BranchName")); } else if (branchInfo.Count > 1) { branchInfo.Insert(0, new { BranchCode = "0", BranchName = "All" }); return(new SelectList(branchInfo.OrderBy(x => x.BranchCode), "BranchCode", "BranchName")); } else { return(null); } }
public ActionResult SaveSecUserInfo(SecUserInfo SecUsrInfo) { RBACUser rUser = new RBACUser(Session["UserName"].ToString()); if (!rUser.HasPermission("SecUserInfo_Insert")) { return(Json("X", JsonRequestBehavior.AllowGet)); } string eCode = ""; using (var transaction = new TransactionScope()) { try { var UserInfo = _secUserInfoService.All().ToList().FirstOrDefault(x => x.UserName == SecUsrInfo.UserName); if (UserInfo == null) { SecUserInfo SecUinf = new SecUserInfo(); SecUinf.UserName = SecUsrInfo.UserName; SecUinf.Password = SHA1.Encode(SecUsrInfo.Password); SecUinf.Email = SecUsrInfo.Email; SecUinf.CreateDate = System.DateTime.Now; _secUserInfoService.Add(SecUinf); _secUserInfoService.Save(); //For user branch table by Farhad var userId = _secUserInfoService.All().ToList().Where(x => x.UserName == SecUsrInfo.UserName).Select(s => s.UserID).FirstOrDefault(); UserBranch UB = new UserBranch(); UB.Userid = userId.ToString(); UB.BranchCode = "01"; _userBranchService.Add(UB); _userBranchService.Save(); eCode = "1"; } else { eCode = "2"; } transaction.Complete(); return(Json(eCode, JsonRequestBehavior.AllowGet)); } catch (Exception) { transaction.Dispose(); return(Json("0", JsonRequestBehavior.AllowGet)); } } }
//Add User To Security Group public ActionResult GetSecUsrInfoToAddInGroup() { try { var SecGrp = _secUserInfoService.All().ToList().Select(x => new { x.UserID, x.UserName, x.Email }).ToList(); //var serializerSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }; //string json = JsonConvert.SerializeObject(SecGrp, Formatting.Indented, serializerSettings); if (SecGrp != null) { return(Json(SecGrp, JsonRequestBehavior.AllowGet)); } else { return(Json(new EmptyResult(), JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json("0", JsonRequestBehavior.AllowGet)); } }
public ActionResult Login(VMLogin user) { try { string Pass = SHA1.Encode(user.Password); var UserInfo = (from mi in _secUserInfoService.All().ToList() where mi.UserName == user.UserName && mi.Password == SHA1.Encode(user.Password) select new { UserID = mi.UserID, UserName = mi.UserName, Password = mi.Password, Email = mi.Email }).FirstOrDefault(); var HasBranch = _sysSetService.All().FirstOrDefault().HasBranch; if (HasBranch == true) { if (UserInfo != null) { Session["ProjCode"] = "01"; Session["UserID"] = UserInfo.UserID; Session["UserName"] = UserInfo.UserName; Session["FinYear"] = user.FinYear; var sysSet = _sysSetService.All().FirstOrDefault(); if (sysSet.HasSale == true) { string token = GetToken(ConfigurationManager.AppSettings["ApiUrl"], UserInfo.UserName, UserInfo.Password); Session["token"] = token; } return(RedirectToAction("LogInWithBranch", "SecUserLogin")); } else { ViewBag.Message = "Login data is incorrect!"; return(RedirectToAction("SecUserLogin", "SecUserLogin")); } } else { if (UserInfo != null) { Session["ProjCode"] = "01"; Session["UserID"] = UserInfo.UserID; Session["UserName"] = UserInfo.UserName; Session["FinYear"] = user.FinYear; Session["BranchCode"] = _branchService.All().FirstOrDefault().BranchCode; var sysSet = _sysSetService.All().FirstOrDefault(); if (sysSet.HasSale == true) { string token = GetToken(ConfigurationManager.AppSettings["ApiUrl"], UserInfo.UserName, UserInfo.Password); Session["token"] = token; } return(RedirectToAction("Index", "Home")); } else { ViewBag.Message = "Login data is incorrect!"; return(RedirectToAction("SecUserLogin", "SecUserLogin")); } } } catch (System.Exception) { throw; } }