/// <summary> /// Save the user's data into the database using the Entity Framework /// </summary> /// <param name="wizard">The wizard that took the user's details</param> protected void PersistUserData(CreateUserWizard wizard) { TextBox FirstNameInput = wizard.CreateUserStep.ContentTemplateContainer.FindControl("FirstName") as TextBox; TextBox LastNameInput = wizard.CreateUserStep.ContentTemplateContainer.FindControl("LastName") as TextBox; using (DMSContext database = new DMSContext()) { // Check whether this user already exists first... // Create a new row if it doesn't exist or update the old one if it does. var existingUser = database.Users.SingleOrDefault( u => u.UserName == wizard.UserName); if (existingUser == null) { User user = new User(); user.UserName = wizard.UserName; user.Email = wizard.Email; user.FirstName = FirstNameInput.Text; user.LastName = LastNameInput.Text; database.Users.Add(user); database.SaveChanges(); } else { existingUser.UserName = wizard.UserName; existingUser.Email = wizard.Email; existingUser.FirstName = FirstNameInput.Text; existingUser.LastName = LastNameInput.Text; database.SaveChanges(); } } }
/// <summary> /// Creates a new user and account /// </summary> /// <param name="user">The user</param> /// <param name="password">The account</param> public void AddUserAndAccount(User user, string password) { var db = new ReScrumEntities(); var newUser = new data.User { EmployeeNumber = user.EmployeeNumber, Forename = user.Forename, Surname = user.Surname, Email = user.Email, JobTitle = user.JobTitle, IsLineManager = user.IsLineManager, IsAdministrator = user.IsAdministrator, }; db.Users.Add(newUser); var team = db.Teams.Where(t => t.TeamId == user.Team).FirstOrDefault(); newUser.Teams.Add(team); var account = new data.Account { User = newUser, Password = Encoding.UTF8.GetBytes(password), }; db.Accounts.Add(account); db.SaveChanges(); }
public wrapper.User ConvertDataUserToWrapper(data.User entry) { var user = new wrapper.User { UserId = entry.UserId, EmployeeNumber = entry.EmployeeNumber, Forename = entry.Forename, Surname = entry.Surname, Email = entry.Email, JobTitle = entry.JobTitle, IsLineManager = entry.IsLineManager, IsAdministrator = entry.IsAdministrator, }; return(user); }