public void RegisterUser(string firstName, string lastName, string email, string password) { if (String.IsNullOrEmpty(firstName)) { throw new IntiGeneralException("Du måste ange ett förnamn"); } if (String.IsNullOrEmpty(lastName)) { throw new IntiGeneralException("Du måste ange ett efternamn"); } if (String.IsNullOrEmpty(email)) { throw new IntiGeneralException("Du måste ange en epostadress"); } if (String.IsNullOrEmpty(password)) { throw new IntiGeneralException("Du måste ange ett lösenord"); } using (var db = new IntiDataContext(_connectionString)) { //username/email must be unique var users = from u in db.Sys_User where u.UserName.ToLower() == email.ToLower() select u; if (users.ToList().Count > 0) { throw new IntiGeneralException("Det finns redan en användare med den epostadressen"); } var user = new Sys_User { FirstName = firstName, LastName = lastName, UserName = email, Password = password }; db.Sys_User.InsertOnSubmit(user); //default permissions var defaultPermissions = from p in db.Sys_Permission where p.Name == "USER" || p.Name == "USER_PVTTOUR" select p; foreach (var perm in defaultPermissions.ToList()) { var userPerm = new Sys_UserPermission(); userPerm.UserGUID = user.GUID; userPerm.PermissionGUID = perm.GUID; db.Sys_UserPermission.InsertOnSubmit(userPerm); } db.SubmitChanges(); } }
partial void DeleteSys_User(Sys_User instance);
partial void UpdateSys_User(Sys_User instance);
partial void InsertSys_User(Sys_User instance);
public void RegisterUser(string firstName, string lastName, string email, string password) { if (String.IsNullOrEmpty(firstName)) throw new IntiGeneralException("Du måste ange ett förnamn"); if (String.IsNullOrEmpty(lastName)) throw new IntiGeneralException("Du måste ange ett efternamn"); if (String.IsNullOrEmpty(email)) throw new IntiGeneralException("Du måste ange en epostadress"); if (String.IsNullOrEmpty(password)) throw new IntiGeneralException("Du måste ange ett lösenord"); using (var db = new IntiDataContext(_connectionString)) { //username/email must be unique var users = from u in db.Sys_User where u.UserName.ToLower() == email.ToLower() select u; if (users.ToList().Count > 0) throw new IntiGeneralException("Det finns redan en användare med den epostadressen"); var user = new Sys_User { FirstName = firstName, LastName = lastName, UserName = email, Password = password }; db.Sys_User.InsertOnSubmit(user); //default permissions var defaultPermissions = from p in db.Sys_Permission where p.Name == "USER" || p.Name == "USER_PVTTOUR" select p; foreach (var perm in defaultPermissions.ToList()) { var userPerm = new Sys_UserPermission(); userPerm.UserGUID = user.GUID; userPerm.PermissionGUID = perm.GUID; db.Sys_UserPermission.InsertOnSubmit(userPerm); } db.SubmitChanges(); } }