コード例 #1
0
 //In the future the method should be done that customers cannot
 //be added if admins fills out a email and/or a username that already exists in the database.
 public void AddCustomer(CustomerInformation newCustomer)
 {
     using (db)
     {
         db.Customer.Add(new Customer
         {
             Firstname = newCustomer.Firstname, Surname = newCustomer.Surname,
             Password  = newCustomer.Password, Username = newCustomer.Username,
             Email     = newCustomer.Email, Street = newCustomer.Street, ZipCode = newCustomer.ZipCode
         });
         db.SaveChanges();
     }
 }
コード例 #2
0
        //Admins should be able to edit most properties of customers
        //This if a customer should mail or call the business (HappyTails) and want help to change some information about them
        public void EditCustomer(CustomerInformation customer)
        {
            using (db)
            {
                Customer editedCustomer = db.Customer.Find(customer.Id);

                //The username should not be able for admins to alter

                if (customer.Firstname != null)
                {
                    editedCustomer.Firstname = customer.Firstname;
                }

                if (customer.Password != null)
                {
                    editedCustomer.Password = customer.Password;
                }

                if (customer.Surname != null)
                {
                    editedCustomer.Surname = customer.Surname;
                }

                if (customer.Email != null)
                {
                    editedCustomer.Email = customer.Email;
                }

                if (customer.Street != null)
                {
                    editedCustomer.Street = customer.Street;
                }

                if (customer.ZipCode != null)
                {
                    editedCustomer.ZipCode = customer.ZipCode;
                }

                db.Entry(editedCustomer).State = EntityState.Modified;
                db.SaveChanges();
            }
        }