/// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 public static User CreateUser(global::System.String password, global::System.Guid userID)
 {
     User user = new User();
     user.Password = password;
     user.UserID = userID;
     return user;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
Ejemplo n.º 3
0
        //Method that creates new user
        public bool CreateNewUser(UserModelDTO NewUser)
        {
            bool check = false;
            using (TransactionScope Trans = new TransactionScope())
            {
                try
                {
                    using (var context = new CinemaEntities())
                    {

                        //Enetring into Users Table
                        try
                        {
                            User NewUserIn = new User();
                            NewUserIn.UserID = NewUser.UserID;
                            NewUserIn.Password = NewUser.Password;

                            if (NewUserIn.EntityState == EntityState.Detached)
                            {
                                context.Users.AddObject(NewUserIn);
                            }
                            context.SaveChanges();
                        }
                        catch { }

                        //Entering into Person Table
                        try
                        {
                            Person NewPersonIn = new Person();
                            NewPersonIn.FirstName = NewUser.FirstName;
                            NewPersonIn.LastName = NewUser.LastName;
                            NewPersonIn.PersonTypeID = NewUser.personTypeID;
                            NewPersonIn.PersonID = Guid.NewGuid();
                            if (NewPersonIn.EntityState == EntityState.Detached)
                            {
                                context.People.AddObject(NewPersonIn);
                            }
                            context.SaveChanges();

                        }
                        catch { }

                        ////Entering into Authonticated User Table
                        //try
                        //{
                        //    AuthenticatedUser NewAuthUser = new AuthenticatedUser();
                        //    NewAuthUser.PersonID = NewUser.PersonID;
                        //    NewAuthUser.UserID = NewUser.UserID;
                        //    NewAuthUser.AuthenticatedUserID = Guid.NewGuid();
                        //    if (NewAuthUser.EntityState == EntityState.Detached)
                        //    {
                        //        context.AuthenticatedUsers.AddObject(NewAuthUser);
                        //    }
                        //    context.SaveChanges();

                        //}
                        //catch { }

                    }

                }
                catch
                {
                    check = false;
                    Trans.Dispose();
                    return check;
                }

                check = true;
                Trans.Complete();
                return check;
            }
        }