public bool DeleteUser(decimal UserID) { //ICollection<CM_USER_ROLE_XREF> UserRoleColl = new Collection<CM_USER_ROLE_XREF>(); CM_USER_PROFILE up = new CM_USER_PROFILE(); CM_USER_ROLE_XREF urx = new CM_USER_ROLE_XREF(); try { //First Delete Rec from UserRoleRef CM_USER_ROLE_XREF objDelUserRoleRef = (from Profile in db.CM_USER_ROLE_XREF where Profile.USER_ID == UserID select Profile).FirstOrDefault(); db.CM_USER_ROLE_XREF.Remove(objDelUserRoleRef); db.SaveChanges(); //First Delete Rec from MakerCheckerRef //CM_MAKER_CHECKER_XREF objDelMakerCheckerRef = (from MCX in db.CM_MAKER_CHECKER_XREF where MCX.CHECKER_ID == UserID || MCX.MAKER_ID == UserID select MCX).FirstOrDefault(); //db.CM_MAKER_CHECKER_XREF.Remove(objDelMakerCheckerRef); //db.SaveChanges(); CM_USER_PROFILE objDeleteUser = (from Profile in db.CM_USER_PROFILE where Profile.PROFILE_ID == UserID select Profile).FirstOrDefault(); db.CM_USER_PROFILE.Remove(objDeleteUser); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool CreateUser(string username, string password, string RoleId, string FName, string LName, string Email) { string salt = null; ICollection <CM_USER_ROLE_XREF> UserRoleColl = new Collection <CM_USER_ROLE_XREF>(); CM_USER_PROFILE up = new CM_USER_PROFILE(); string passwordHash = pwdManager.GeneratePasswordHash(password, out salt); int profileId = 0; using (var cdma = new AppDbContext()) { var usr = new CM_USER_PROFILE { COD_PASSWORD = passwordHash, PASSWORDSALT = salt, USER_ID = username, ISLOCKED = false, //isLoggedin CREATED_DATE = DateTime.Now, ROLE_ID = Convert.ToInt32(RoleId), FIRSTNAME = FName, LASTNAME = LName, DISPLAY_NAME = (FName.Substring(0, 1) + LName).ToLower(), EMAIL_ADDRESS = Email, ISAPPROVED = true, LASTLOGINDATE = DateTime.Now, LASTLOCKOUTDATE = DateTime.Now, LASTPASSWORDCHANGEDDATE = DateTime.Now }; cdma.CM_USER_PROFILE.Add(usr); cdma.SaveChanges(); profileId = usr.PROFILE_ID; } CM_USER_ROLE_XREF urx = new CM_USER_ROLE_XREF(); urx.USER_ID = profileId; urx.ROLE_ID = Convert.ToInt32(RoleId); UserRoleColl.Add(urx); up.CM_USER_ROLE_XREF = UserRoleColl; db.CM_USER_ROLE_XREF.Add(urx); db.SaveChanges(); if (up.PROFILE_ID == null) { return(false); } else { return(true); } }