Example #1
0
        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);
        }
Example #2
0
 partial void DeleteUserAllergy(UserAllergy instance);
Example #3
0
 partial void UpdateUserAllergy(UserAllergy instance);
Example #4
0
 partial void InsertUserAllergy(UserAllergy instance);
Example #5
0
 private void detach_UserAllergies(UserAllergy entity)
 {
     this.SendPropertyChanging();
     entity.Allergy = null;
 }
Example #6
0
 private void attach_UserAllergies(UserAllergy entity)
 {
     this.SendPropertyChanging();
     entity.Allergy = this;
 }