Exemple #1
0
 public SeedDataDomain()
 {
     _appointmentsDomain = new AppointmentsDomain(new AppointmentsRepository());
     _patientDomain      = new PatientDomain(new PatientsRepository());
     _providerDomain     = new ProviderDomain(new ProvidersRepository());
     _serviceDomain      = new ServiceDomain(new ServicesRepository());
 }
        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));
            };
        }
 public PositionsController(ILogger <PositionsController> logger, IServiceDomain <Position> service)
 {
     _logger  = logger;
     _service = service;
 }
        public AppointmentController(IAppointmentsDomain appointmentsDomain, IPatientDomain patientDomain, IProviderDomain providerDomain, IServiceDomain serviceDomain) : base("/appointments")
        {
            Get["/"]              = parameters => new JsonResponse(appointmentsDomain.GetAppointments(), new DefaultJsonSerializer());
            Get["/{id}"]          = parameters => new JsonResponse(appointmentsDomain.GetAppointment(parameters.id), new DefaultJsonSerializer());
            Get["/patient/{id}"]  = parameters => new JsonResponse(appointmentsDomain.GetPatientAppointments(parameters.id), new DefaultJsonSerializer());
            Get["/provider/{id}"] = parameters => new JsonResponse(appointmentsDomain.GetProviderAppointments(parameters.id), new DefaultJsonSerializer());
            Post["/"]             = parameters =>
            {
                var appointmentModel = this.Bind <AppointmentModel>();
                var response         = appointmentModel.ValidateModel();
                if (response != null)
                {
                    return(response);
                }

                var appointment = new Appointment
                {
                    Patient                  = patientDomain.GetPatient(appointmentModel.PatientId),
                    Provider                 = providerDomain.GetProvider(appointmentModel.ProviderId),
                    Service                  = serviceDomain.GetService(appointmentModel.ServiceId),
                    ReasonForVisit           = appointmentModel.ReasonForVisit,
                    RequestedAppointmentDate = DateTime.Parse(appointmentModel.RequestedAppointmentDate)
                };

                try
                {
                    var validationResponse = ValidateInputModel(appointment);
                    if (validationResponse != null)
                    {
                        return(validationResponse);
                    }
                    appointmentsDomain.SetAppointment(appointment);
                }
                catch (ApplicationException ex)
                {
                    return(new Response()
                    {
                        StatusCode = HttpStatusCode.BadRequest
                    }.WithHeader("Error", ex.Message));
                }


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

                return(new Response()
                {
                    StatusCode = HttpStatusCode.Accepted
                }.WithHeader("Location", url));
            };
        }