コード例 #1
0
        public Town Create(string name)
        {
            Town town = new Town()
            {
                Name = name
            };

            this.townRepos.Add(town);
            this.townRepos.Save();

            return town;
        }
コード例 #2
0
        /// <summary>
        /// Adds a Supplier
        /// Level: Logic
        /// </summary>
        /// <param name="Supplier">The Supplier Name</param>
        /// <param name="Email">The Supplier Email</param>
        /// <param name="Postcode">The Postcode</param>
        /// <param name="StreetAddress">The Street Address</param>
        /// <param name="Town">The Town</param>
        /// <param name="Country">The Country</param>
        public void AddSupplier(string Supplier, string Email, string Postcode, string StreetAddress,
            string Town, string Country)
        {
            try
            {
                SuppliersRepository myRepository = new SuppliersRepository();

                Supplier mySupplier = new Supplier();

                mySupplier.Supplier1 = Supplier;
                mySupplier.Email = Email;
                mySupplier.Postcode = Postcode;
                mySupplier.StreetAddress = StreetAddress;

                Town myTown = myRepository.RetrieveTown(Town, Country);

                //If Town Exists
                if (myTown != null)
                {
                    //Assigning Existent Town to Supplier
                    mySupplier.Town = myTown;
                }
                else
                {
                    //Instanciating New Town
                    myTown = new Town();
                    myTown.Town1 = Town;
                    myTown.Country = myRepository.RetrieveCountry(Country);

                    //Assigning New Town to Supplier
                    mySupplier.Town = myTown;
                }

                myRepository.AddSupplier(mySupplier);
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #3
0
 /// <summary>
 /// Create a new Town object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="countryID">Initial value of the CountryID property.</param>
 public static Town CreateTown(global::System.Int32 id, global::System.String name, global::System.Int32 countryID)
 {
     Town town = new Town();
     town.ID = id;
     town.Name = name;
     town.CountryID = countryID;
     return town;
 }
コード例 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Town EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTown(Town town)
 {
     base.AddObject("Town", town);
 }
コード例 #5
0
        /// <summary>
        /// Updates a Supplier
        /// Level: Data
        /// </summary>
        /// <param name="mySupplier">The Supplier to Be Updated</param>
        public void UpdateSupplier(SuppliersView mySupplier)
        {
            try
            {
                Supplier myOriginalSupplier = RetrieveSupplierByID(mySupplier.Id);

                myOriginalSupplier.Supplier1 = mySupplier.Supplier;
                myOriginalSupplier.Email = mySupplier.Email;
                myOriginalSupplier.StreetAddress = mySupplier.StreetAddress;
                myOriginalSupplier.Postcode = mySupplier.Postcode;

                Town myTown = RetrieveTown(mySupplier.Town, mySupplier.Country);

                //If Town Exists
                if (myTown != null)
                {
                    //Assigning Existent Town to Supplier
                    myOriginalSupplier.Town = myTown;
                }
                else
                {
                    //Instanciating New Town
                    myTown = new Town();
                    myTown.Town1 = mySupplier.Town;
                    myTown.Country = RetrieveCountry(mySupplier.Country);

                    //Assigning New Town to Supplier
                    myOriginalSupplier.Town = myTown;
                }

                Entities.SaveChanges();
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
コード例 #6
0
        /// <summary>
        /// Finalises user signup
        /// Level: Logic
        /// </summary>
        /// <param name="Name">The Name</param>
        /// <param name="Surname">The Surname</param>
        /// <param name="DateOfBirth">The Date of Birth</param>
        /// <param name="Address">The Address</param>
        /// <param name="Email">The Email</param>
        /// <param name="Town">The Town</param>
        /// <param name="Postcode">The Postcode</param>
        /// <param name="Country">The Country</param>
        /// <param name="Username">The Username</param>
        /// <param name="Password">The Password</param>
        /// <returns>UserSignupEnum</returns>
        public UserSignup FinalizeSignUp(string Name, string Surname, DateTime DateOfBirth, string Address, string Email, string Town,
            string Postcode, string Country, string Username, string Password)
        {
            try
            {
                UsersRepository myRepository = new UsersRepository(false);

                try
                {
                    //Checking if Username Exists
                    if ((myRepository.UsernameExists(Username)) && (myRepository.EmailExists(Email)))
                    {
                        return UserSignup.UsernameAndEmailExist;
                    }
                    else if (myRepository.UsernameExists(Username))
                    {
                        return UserSignup.UsernameExists;
                    }
                    else if (myRepository.EmailExists(Email))
                    {
                        return UserSignup.EmailExists;
                    }
                    else
                    {
                        //Instanciating User
                        User myUser = new User();

                        myUser.Id = Guid.NewGuid();
                        myUser.Name = Name;
                        myUser.Surname = Surname;
                        myUser.DateOfBirth = DateOfBirth;
                        myUser.StreetAddress = Address;
                        myUser.Postcode = Postcode;
                        myUser.Email = Email;

                        //Retrieving UserType
                        myUser.UserType = myRepository.RetrieveUserTypeByName("Retailer");

                        //Retrieving Possible Same Town
                        Town myTown = myRepository.RetrieveTown(Town, Country);

                        //If Town Exists
                        if (myTown != null)
                        {
                            //Assigning Existent Town to User
                            myUser.Town = myTown;
                        }
                        else
                        {
                            //Instanciating New Town
                            myTown = new Town();
                            myTown.Town1 = Town;
                            myTown.Country = myRepository.RetrieveCountry(Country);

                            //Assigning New Town to User
                            myUser.Town = myTown;
                        }

                        //Instanciating User Details
                        UserDetail myUserDetails = new UserDetail();

                        myUserDetails.Id = Guid.NewGuid();
                        myUserDetails.Username = Username;
                        myUserDetails.Password = Password;

                        //Assigning User Details to User
                        myUser.UserDetail = myUserDetails;

                        //Assigning User Role to User
                        myUser.Roles.Add(myRepository.RetrieveRoleByName("User"));

                        //Saving Changes
                        myRepository.FinalizeSignUp(myUser);

                        //Returning Successful
                        return UserSignup.Successful;
                    }
                }
                catch (Exception Exception)
                {
                    //Throwing Exception
                    throw Exception;
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
 /// <summary>
 /// Create a new Town object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="town1">Initial value of the Town1 property.</param>
 /// <param name="countryFK">Initial value of the CountryFK property.</param>
 public static Town CreateTown(global::System.Int32 id, global::System.String town1, global::System.Int32 countryFK)
 {
     Town town = new Town();
     town.Id = id;
     town.Town1 = town1;
     town.CountryFK = countryFK;
     return town;
 }