예제 #1
0
        /// <summary>
        /// Creates a given user account
        /// </summary>
        /// <param name="firstname">Fristname of new user</param>
        /// <param name="surname">Surname of new user</param>
        /// <param name="street">Street</param>
        /// <param name="zip">Zip</param>
        /// <param name="city">City</param>
        /// <param name="country">The country (ISO code)</param>
        /// <param name="email">Email address</param>
        /// <param name="password">The password of the user</param>
        /// <param name="newTitleId">The users title ID</param>
        /// <returns>ID of new user</returns>
        public int CreateUser(string firstname,
            string surname,
            string street,
            string zip,
            string city,
            string country,
            string email,
            string password,
            int? newTitleId)
        {
            using (MediathekEntities context = new MediathekEntities())
            {
                User user = new User();

                // set nav properites
                if (newTitleId != null)
                {
                    user.Title = context.Titles.FirstOrDefault(t => t.TitleId == newTitleId);
                }
                else
                {
                    user.Title = null;
                }

                // set normal properties
                user.Firstname = firstname;
                user.Surname = surname;
                user.Street = street;
                user.Zip = zip;
                user.City = city;
                user.CountryIso = country;
                user.Email = email;
                user.Password = password;

                // add to context and save
                context.AddToUsers(user);
                context.SaveChanges();

                return user.UserId;
            }
        }