Esempio n. 1
0
        private static void Version2()
        {
            var tom  = v2.StaffMember.Register("Tom");
            var jack = v2.StaffMember.Register("Jack");

            Repository <v2.StaffMember>().Add(tom);
            Repository <v2.StaffMember>().Add(jack);

            var customer = v2.Customer.Register("John", "Smith", "*****@*****.**");

            var job         = v2.Job.Create(customer, "1 George Street");
            var appointment = v2.Appointment.ScheduleNew(DateTime.Now, DateTime.Now.AddHours(2), tom);

            job.Appointments = new List <v2.Appointment> {
                appointment
            };

            customer.Name       = new v2.FullName("Michael", "Harris");
            customer.Email      = "*****@*****.**";
            customer.Phone      = "123456";
            customer.CreditCard = new v2.CreditCardDetails("Michael", "123 456 789");

            appointment             = job.Appointments.Single(a => a.Id == appointment.Id);
            appointment.StaffMember = jack;
            appointment.TimeSlot    = new v2.TimeSlot(DateTime.Now.AddDays(1), DateTime.Now.AddDays(1).AddHours(2));

            Repository <v2.Customer>().Add(customer);
            Repository <v2.Job>().Add(job);

            appointment.Status = Status.InProgress;
            job.Status         = Status.InProgress;

            appointment.Status = Status.Completed;
            if (job.Appointments.All(a => a.Status != Status.InProgress))
            {
                job.Status = Status.Completed;
            }

            var creditValidator = new CreditValidationService();

            if (creditValidator.IsValid(customer.CreditCard.NameOnCard, customer.CreditCard.CardNumber))
            {
                new BillingService().Pay(customer.CreditCard.NameOnCard, customer.CreditCard.CardNumber);
                new NotificationService().SendEmail(customer.Email, "Invoice charged", "Bla bla bla");
            }
            else
            {
                new NotificationService().SendEmail(customer.Email, "Credit not valid", "Bla bla bla");
            }
        }
Esempio n. 2
0
        private static void Version1()
        {
            var tom = new v1.StaffMember {
                Id = Guid.NewGuid(), Name = "Tom"
            };
            var jack = new v1.StaffMember {
                Id = Guid.NewGuid(), Name = "Jack"
            };

            Repository <v1.StaffMember>().Add(tom);
            Repository <v1.StaffMember>().Add(jack);

            var customer = new v1.Customer
            {
                Id         = Guid.NewGuid(),
                FirstName  = "John",
                FamilyName = "Smith"
            };

            var job = new v1.Job
            {
                Id       = Guid.NewGuid(),
                Status   = Status.Initiated,
                Customer = customer,
                Location = "1 George Street, blablabla"
            };

            job.Appointments = new List <v1.Appointment>
            {
                new v1.Appointment
                {
                    Id          = Guid.NewGuid(),
                    From        = DateTime.Now,
                    To          = DateTime.Now.AddHours(2),
                    StaffMember = tom
                }
            };

            customer.FirstName        = "Michael";
            customer.FamilyName       = "Harris";
            customer.Email            = "*****@*****.**";
            customer.Phone            = "123456";
            customer.NameOnCreditCard = "Michael";
            customer.CreditCardNumber = "123 456 789";

            var appointment = job.Appointments.First();

            appointment.StaffMember = jack;
            appointment.From        = DateTime.Now.AddDays(1);
            appointment.To          = DateTime.Now.AddDays(1).AddHours(2);

            Repository <v1.Customer>().Add(customer);
            Repository <v1.Job>().Add(job);

            appointment.Status = Status.InProgress;
            job.Status         = Status.InProgress;

            appointment.Status = Status.Completed;
            if (job.Appointments.All(a => a.Status != Status.InProgress))
            {
                job.Status = Status.Completed;
            }

            var creditValidator = new CreditValidationService();

            if (creditValidator.IsValid(customer.NameOnCreditCard, customer.CreditCardNumber))
            {
                new BillingService().Pay(customer.NameOnCreditCard, customer.CreditCardNumber);
                new NotificationService().SendEmail(customer.Email, "Invoice charged", "Bla bla bla");
            }
            else
            {
                new NotificationService().SendEmail(customer.Email, "Credit not valid", "Bla bla bla");
            }
        }