public int SaveRecord(SECURITY_User pRow_NewData) { int li_ReturnValue = 0; try { SCMSDataContext dbSCMS = Connection.Create(); SECURITY_User lRow_ExistingData = dbSCMS.SECURITY_Users.Where(c => c.User_Id.Equals(pRow_NewData.User_Id)).SingleOrDefault(); if (lRow_ExistingData != null) { lRow_ExistingData.User_Title = pRow_NewData.User_Title; lRow_ExistingData.UsrGrp_Id = pRow_NewData.UsrGrp_Id; lRow_ExistingData.User_Password = pRow_NewData.User_Password; lRow_ExistingData.User_Login = pRow_NewData.User_Login; } else { dbSCMS.SECURITY_Users.InsertOnSubmit(pRow_NewData); } dbSCMS.SubmitChanges(); li_ReturnValue = Convert.ToInt32(pRow_NewData.User_Id); } catch { return 0; } return li_ReturnValue; }
public static UserModel Map(this SECURITY_User original) { if (original == null) { return(null); } var model = new UserModel() { ID = original.UserId, LastLogin = original.LastLogin, ResetPassword = original.ResetPassword, EmailAddress = original.EmailAddress, FirstName = original.FirstName, LastName = original.LastName, Password = EncryptionHelper.EncryptData(original.Password) }; return(model); }
public ActionResult SaveRecord(string ps_Code, string ps_Title, string ps_GroupId, string ps_Login, string ps_Password) { DALUser objDal = new DALUser(); Int32 li_ReturnValue = 0; try { SECURITY_User lrow_Data = new SECURITY_User(); if (String.IsNullOrEmpty(ps_Code)) { if (DALCommon.AutoCodeGeneration("SECURITY_User") == 1) { ps_Code = DALCommon.GetMaximumCode("SECURITY_User"); } } if (!String.IsNullOrEmpty(ps_Code)) { lrow_Data.User_Id = ps_Code; lrow_Data.User_Code = ps_Code; lrow_Data.UsrGrp_Id = ps_GroupId; lrow_Data.User_Title = ps_Title; lrow_Data.User_Login = ps_Login; lrow_Data.User_Password = ps_Password; lrow_Data.User_Active = 1; li_ReturnValue = objDal.SaveRecord(lrow_Data); ViewData["SaveResult"] = li_ReturnValue; } return PartialView("GridData"); } catch { return PartialView("GridData"); } }
public UserModel SaveUser(UserModel user) { using (var context = new FleetConnectAssessmentEntities()) { if (user.ID <= 0) { var newUser = new SECURITY_User() { DateAdded = DateTime.Now, EmailAddress = user.EmailAddress, FirstName = user.FirstName, IsLocked = false, LastName = user.LastName, Password = EncryptionHelper.EncryptData(user.Password) }; context.SECURITY_User.Add(newUser); context.SaveChanges(); var role = context.SECURITY_Role.FirstOrDefault(x => x.Name.ToLower() == user.Roles.ToLower()); var roleID = role != null ? role.RoleId : 0; var userRole = new SECURITY_UserRole() { UserId = newUser.UserId, RoleId = roleID }; context.SECURITY_UserRole.Add(userRole); context.SaveChanges(); return(newUser.Map()); } else { var userToUpdate = context.SECURITY_User.FirstOrDefault(x => x.UserId == user.ID); if (userToUpdate == null) { return(null); } userToUpdate.EmailAddress = user.EmailAddress; userToUpdate.FirstName = user.FirstName; userToUpdate.LastName = user.LastName; userToUpdate.IsLocked = user.isLocked; userToUpdate.Password = EncryptionHelper.EncryptData(user.Password); context.SaveChanges(); var role = context.SECURITY_Role.FirstOrDefault(x => x.Name.ToLower() == user.Roles.ToLower()); var roleID = role != null ? role.RoleId : 0; var userRole = new SECURITY_UserRole() { UserId = userToUpdate.UserId, RoleId = roleID }; context.SECURITY_UserRole.Add(userRole); context.SaveChanges(); return(userToUpdate.Map()); } } }