public bool InsertGroupFeature(Guid UserGroupID, Guid SystemFeatureID) { bool bReturn = false; ApplicationDbContext db = new ApplicationDbContext(); if (UserGroupID == null || UserGroupID.ToString() == "") { return(false); } if (SystemFeatureID == null || SystemFeatureID.ToString() == "") { return(false); } GroupFeature groupFeature = new GroupFeature(); groupFeature.GroupFeatureID = Guid.NewGuid(); groupFeature.UserGroupID = UserGroupID; groupFeature.SystemFeatureID = SystemFeatureID; groupFeature.CreateDateTime = DateTime.Now; db.GroupFeatures.Add(groupFeature); db.SaveChanges(); bReturn = true; return(bReturn); }
public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model, string getuserid) { eSPP.Models.GroupFeature groupFeature = new eSPP.Models.GroupFeature(); List <Guid> userGroupIDList = new List <Guid>(); List <eSPP.Models.GroupFeaturesDisplay> groupFeatureDisplayList = new List <eSPP.Models.GroupFeaturesDisplay>(); if (User.Identity.IsAuthenticated) { UserGroup userGroup = new UserGroup(); userGroupIDList = userGroup.GetGroupByLoginUser(); groupFeatureDisplayList = groupFeature.GetFeatureListByGroup(userGroupIDList); } MajlisContext mc = new MajlisContext(); if (getuserid == null) { getuserid = User.Identity.GetUserId(); } ApplicationDbContext db = new ApplicationDbContext(); if (!ModelState.IsValid) { return(RedirectToAction("ChangePassword", "Manage", new { getuserid = getuserid, Message = ManageMessageId.ErrorPassword })); } var userid = await UserManager.FindByIdAsync(getuserid); var result = await UserManager.ChangePasswordAsync(userid.Id, model.OldPassword, model.NewPassword); if (result.Succeeded) { var user = await UserManager.FindByIdAsync(getuserid); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } var pokemon = User.Identity.Name; var user1 = db.Users.Where(s => s.UserName == pokemon).SingleOrDefault(); var emel = db.Users.Where(s => s.Email == user1.Email).SingleOrDefault(); var role1 = db.UserRoles.Where(d => d.UserId == user1.Id).SingleOrDefault(); IdentityRole role = new IdentityRole(); if (role != null) { role = db.Roles.Where(e => e.Id == role1.RoleId).SingleOrDefault(); } ApplicationUser ui = db.Users.SingleOrDefault(s => s.Id == getuserid); PRUSER pruser = mc.PRUSER.SingleOrDefault(s => s.USERNAME == ui.UserName); string password = model.NewPassword; string hPassword = ComputeHash(password, new MD5CryptoServiceProvider()); pruser.USERPASSWORD = hPassword; mc.Entry(pruser).State = EntityState.Modified; mc.SaveChanges(); ui.PasswordUpdate = DateTime.Now; db.Entry(ui).State = EntityState.Modified; db.SaveChanges(); new AuditTrailModels().Log(emel.Email, emel.UserName, System.Web.HttpContext.Current.Request.UserHostAddress, role.Name, emel.UserName + " Telah Menukar Katalaluan", System.Net.Dns.GetHostName(), emel.PhoneNumber, Request.RawUrl, "ChangePassword"); var username = User.Identity.Name; HR_MAKLUMAT_PERIBADI name = db.HR_MAKLUMAT_PERIBADI.FirstOrDefault(s => s.HR_NO_KPBARU == username); return(RedirectToAction("Index", "Home", new { id = name.HR_NO_PEKERJA, Message = ManageMessageId.ChangePasswordSuccess })); } AddErrors(result); return(RedirectToAction("ChangePassword", "Manage", new { getuserid = getuserid, Message = ManageMessageId.ErrorPassword })); }