/// <author>Kenneth Søhrmann</author> /// <summary> /// See the interface specification of the method in IRentIt.cs for documentation /// of this method. /// </summary> public bool CreateNewUser(Account newAccount) { if (newAccount == null) { throw new FaultException<ArgumentException>( new ArgumentException("The newAccount-parameter is a null reference.")); } // All information must be longer than 0 characters. if (newAccount.UserName.Length == 0 || newAccount.FullName.Length == 0 || newAccount.HashedPassword.Length == 0) throw new FaultException<UserCreationException>( new UserCreationException("One or more pieces of information were empty.")); // The e-mail address must adhere to a regex found on http://www.regular-expressions.info/email.html (reduced official standard) string emailRegex = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"; if (!Regex.IsMatch(newAccount.Email, emailRegex)) throw new FaultException<UserCreationException>( new UserCreationException("The e-mail address is not valid.")); DatabaseDataContext db; try { db = new DatabaseDataContext(); } catch (Exception) { throw new FaultException<Exception>( new Exception("An internal error has occured. This is not related to the input.")); } // If there exist an account with the submitted user name... if (db.Accounts.Exists(ac => ac.user_name.Equals(newAccount.UserName))) { // ...the request is told so. throw new FaultException<UserCreationException>( new UserCreationException("The specified user name is already in use.")); } // The user name is free, create a new instance with the data provided. var baseAccount = new RentItDatabase.Account { user_name = newAccount.UserName, full_name = newAccount.FullName, email = newAccount.Email, password = newAccount.HashedPassword.ToUpper(), active = true }; var userAccount = new User_account { credit = 0, Account = baseAccount }; try { db.User_accounts.InsertOnSubmit(userAccount); db.SubmitChanges(); } catch (Exception) { throw new FaultException<Exception>( new Exception("An internal error has occured. This is not related to the input.")); } return true; }
partial void UpdateAccount(Account instance);
partial void DeleteAccount(Account instance);
partial void InsertAccount(Account instance);