public void SaveUpdateRecord(UserViewModel model) { UserDetail tblUserMaster = new UserDetail(); if (model.EditId <= 0) { tblUserMaster.UserID = model.ID; _context.UserDetails.Add(tblUserMaster); tblUserMaster.createdby = model.CreatedBy; tblUserMaster.createddate = DateTime.Now; } else { tblUserMaster = _context.UserDetails.Where(x => x.UserID == model.ID).FirstOrDefault(); } tblUserMaster.EmployeeName = model.EmployeeName; tblUserMaster.EmployeeCode = model.EmployeeCode; tblUserMaster.EmpAddress = model.Address; tblUserMaster.MobileNo = model.MobileNo; tblUserMaster.EmailId = model.EmailId; tblUserMaster.UserTypeID = model.UserCategoryId; tblUserMaster.UserName = model.UserName; tblUserMaster.Password = PasswordEncryptionDecryption.Encrypt(model.Password); tblUserMaster.updatedby = model.UpdatedBy; tblUserMaster.updateddate = DateTime.Now; _context.SaveChanges(); }
public ActionResult Login(LoginViewModel login) { if (ModelState.IsValid) { login.Password = PasswordEncryptionDecryption.Encrypt(login.Password); ViewBag.BranchList = new SelectList(_branchService.GetAllBranchMasters(), "BID", "BranchName"); ViewBag.FinancialYearList = new SelectList(_financialYearService.GetFinancialYearMasters(), "FinancialyearID", "Financialyear"); var branch = _context.Mst_UserBranch.Where(b => b.BranchID == login.BranchId && b.UserDetail.UserName.ToLower() == login.UserName.ToLower()).FirstOrDefault(); if (branch == null) { ModelState.AddModelError("", "Selected branch is not assigned to you."); return(View(login)); } var user = _context.UserDetails.Where(x => x.UserID == branch.UserID && x.Password == login.Password ).FirstOrDefault(); if (user != null) { FormsAuthentication.RedirectFromLoginPage(login.UserName, false); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login.UserName, DateTime.Now, DateTime.Now.AddMinutes(1051897), true, string.Empty, FormsAuthentication.FormsCookiePath); string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } Response.Cookies.Add(cookie); //get User Id on Login so that we will update this id for every page on insert ,update and delete entry Session["UserLoginId"] = user.UserID; Session["UserName"] = user.UserName; Session["UserCategory"] = user.UserTypeID; Session["BranchId"] = login.BranchId; Session["BranchCode"] = _context.tblCompanyBranchMasters.Where(x => x.BID == login.BranchId && x.Status == 1).Select(x => x.BranchCode).FirstOrDefault(); Session["FinancialYearId"] = login.FinancialYearId; Session["CompanyId"] = 1; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Please check user name and password."); } } return(View(login)); }
public ActionResult ResetPassword(ForgotPasswordViewModel objViewModel) { if (ModelState.IsValid) { int isverified = 1; _userService.SetUserFlag(objViewModel.EmailId, isverified); int userid = _context.UserDetails.Where(x => x.EmailId == objViewModel.EmailId).Select(x => x.UserID).SingleOrDefault(); string password = PasswordEncryptionDecryption.Encrypt(objViewModel.Password); _userService.UpdatePassword(userid, password); return(View("ResetPasswordSuccess")); } return(View()); }
public UserViewModel SetRecordinEdit(UserDetail tblUser) { UserViewModel user = new UserViewModel(); user.ID = tblUser.UserID; user.EditId = tblUser.UserID; user.EmployeeName = tblUser.EmployeeName; user.EmployeeCode = tblUser.EmployeeCode; user.Address = tblUser.EmpAddress; user.MobileNo = tblUser.MobileNo; user.EmailId = tblUser.EmailId; user.UserCategoryId = tblUser.UserTypeID; user.UserName = tblUser.UserName; user.Password = PasswordEncryptionDecryption.Decrypt(tblUser.Password); return(user); }