コード例 #1
0
        public ServiceController(IServiceDomain serviceDomain) : base("/service")
        {
            Get["/"]     = parameters => new JsonResponse(serviceDomain.GetServices(), new DefaultJsonSerializer());
            Get["/{id}"] = parameters => new JsonResponse(serviceDomain.GetService(parameters.id), new DefaultJsonSerializer());
            Post["/"]    = parameters =>
            {
                var serviceModel = this.Bind <ServiceModel>();
                var response     = serviceModel.ValidateModel();
                if (response != null)
                {
                    return(response);
                }

                var service = new Service
                {
                    Name                       = serviceModel.Name,
                    Duration                   = TimeSpan.Parse(serviceModel.Duration),
                    MinimumRequiredAge         = serviceModel.MinimumRequiredAge,
                    RequiredCertificationLevel = serviceModel.MinimumRequiredAge
                };

                serviceDomain.CreateService(service);

                string url = string.Format("{0}/{1}", this.Context.Request.Url, service.Id);

                return(new Response()
                {
                    StatusCode = HttpStatusCode.Accepted
                }.WithHeader("Location", url));
            };
        }
コード例 #2
0
        public void SeedData()
        {
            var provider_one = new Provider
            {
                Name = "Dr. Oz",
                CertificationLevel = 10
            };

            var provider_two = new Provider
            {
                Name = "Dr. Jekyll",
                CertificationLevel = 10
            };

            var provider_three = new Provider
            {
                Name = "Dr. Houser",
                CertificationLevel = 1
            };

            var patient_one = new Patient
            {
                Name = "Dorothy",
                Age  = 16
            };

            var patient_two = new Patient
            {
                Name = "Glenda",
                Age  = 99
            };

            var service_one = new Service
            {
                Name                       = "A New Heart",
                Duration                   = TimeSpan.FromHours(5),
                MinimumRequiredAge         = 16,
                RequiredCertificationLevel = 10
            };

            var service_two = new Service
            {
                Name                       = "Consultation",
                Duration                   = TimeSpan.FromMinutes(30),
                MinimumRequiredAge         = 18,
                RequiredCertificationLevel = 10
            };

            provider_one   = _providerDomain.CreateProvider(provider_one);
            provider_two   = _providerDomain.CreateProvider(provider_two);
            provider_three = _providerDomain.CreateProvider(provider_three);
            patient_one    = _patientDomain.CreatePatient(patient_one);
            patient_two    = _patientDomain.CreatePatient(patient_two);
            service_one    = _serviceDomain.CreateService(service_one);
            service_two    = _serviceDomain.CreateService(service_two);

            var appointment = new Appointment
            {
                Patient                  = patient_one,
                Provider                 = provider_one,
                Service                  = service_one,
                ReasonForVisit           = "There's no place like home",
                RequestedAppointmentDate = DateTime.Parse("2000/01/01 09:00:00.000"),
            };

            _appointmentsDomain.SetAppointment(appointment);
        }