public int AddUser(UserModel user) { db.Connection.Open(); var users = db.Users; string passkey = Membership.GeneratePassword(user.Password.Length, 0); var userToInsert = new User { Address = user.Address, City = user.City, CPR = user.CPR, Email = user.Email, LastName = user.LastName, FirstName = user.FirstName, GuidLine = user.GuidLine, ZipCode = user.ZipCode, PassKey = passkey }; try { users.InsertOnSubmit(userToInsert); db.SubmitChanges(); } catch (Exception e) { return(0); } var password = new Password { Password1 = user.Password, UserPassKey = passkey }; try { db.Passwords.InsertOnSubmit(password); db.SubmitChanges(); } catch (Exception e) { return(0); } foreach (var a in user.Allergies) { UserAllergy allergy = new UserAllergy { AllergyID = a, UserID = users.Single(x => x.CPR == user.CPR).ID }; db.UserAllergies.InsertOnSubmit(allergy); db.SubmitChanges(); } db.Connection.Close(); return(1); }
partial void DeleteUserAllergy(UserAllergy instance);
partial void UpdateUserAllergy(UserAllergy instance);
partial void InsertUserAllergy(UserAllergy instance);
private void detach_UserAllergies(UserAllergy entity) { this.SendPropertyChanging(); entity.Allergy = null; }
private void attach_UserAllergies(UserAllergy entity) { this.SendPropertyChanging(); entity.Allergy = this; }