/// <summary> /// Create an entry in the membership table and the user (unless the second item already exists). /// </summary> public static LogonUserDal CreateUser(string userName, string password, string name, bool? gender, DateTime? dateOfBirth, bool? isMailingListMember, bool isLogOnUser) { if (isLogOnUser) { // Create ASP.NET user. Membership.CreateUser(userName, password, userName); } // Create custom user to match. LogonUserDal user; user = GetUserByUsername(userName); bool isNewUser = user==null; if (isNewUser) { user = new LogonUserDal(); user.DateCreated = DateTime.Now; user.UserName = userName; user.EmailAddress = user.UserName; } if (isLogOnUser) { user.ExternalId = Membership.GetUser(user.UserName).ProviderUserKey.ToString(); } user.UserName = name; // Read date of birth, and parse with dutch locale (assuming format 'dd-MM-yyyy'enforced in UI). user.DateOfBirth = dateOfBirth; user.Gender = gender; user.IsMailingListMember = isMailingListMember; user.IsActive = isLogOnUser; if (isNewUser) { user.Save(); } // DB.SaveChanges(); if (isLogOnUser) { //Make sure the user stays logged in and has a session by setting the (persisted) authorization cookie\ // (NB Session is stored via URL param if user has cookies disabled if web.config configured correctly). FormsAuthentication.SetAuthCookie(userName, true); } return user; }
/// <summary> /// Retrieve an InschrijvingModel for a user and a certain event (determined by externalIdentifier). /// </summary> /// <param name="logonUser"></param> /// <param name="eventNr"></param> /// <returns></returns> public static InschrijvingModel GetInschrijving(LogonUserDal logonUser, string eventNr) { return SelectEntries(eventNr, true, logonUser.Id).FirstOrDefault(); }