Beispiel #1
0
        public ActionResult <Treatment> GetTreatment(int id, int treatmentId)
        {
            Hairdresser hairdresser = _hairdresserRepository.GetBy(id);

            if (hairdresser == null)
            {
                return(NotFound());
            }

            Treatment treatment = hairdresser.GetTreatment(treatmentId);

            if (treatment == null)
            {
                return(NotFound());
            }

            return(Ok(treatment));
        }
Beispiel #2
0
        public ActionResult <AppointmentDTO> PostAppointment(int id, AppointmentDTO appointment)
        {
            Hairdresser hairdresser = _hairdresserRepository.GetBy(id);

            if (hairdresser == null)
            {
                return(NotFound());
            }

            if (appointment.StartMoment < DateTime.Now)
            {
                return(BadRequest());
            }

            IList <Treatment> treatments = new List <Treatment>();

            foreach (Treatment tr in appointment.Treatments)
            {
                treatments.Add(hairdresser.GetTreatment(tr.Id));
            }

            Appointment appointmentToCreate = new Appointment(treatments, appointment.StartMoment, appointment.Firstname, appointment.Lastname);

            bool result = hairdresser.AddAppointment(appointmentToCreate);

            if (result == false)
            {
                return(BadRequest());
            }

            _hairdresserRepository.SaveChanges();

            _hub.Clients.All.SendAsync("appointments", hairdresser.Appointments.Select(a => new AppointmentDTO()
            {
                Id = a.Id, Firstname = a.Firstname, Lastname = a.Lastname, StartMoment = a.StartMoment, Treatments = a.Treatments.Select(tr => tr.Treatment).ToList()
            }).ToList());

            return(Ok(new AppointmentDTO()
            {
                StartMoment = appointmentToCreate.StartMoment, Treatments = appointmentToCreate.Treatments.Select(tr => tr.Treatment).ToList()
            }));                                                                                                                                                                // CreatedAtAction() not possible --> bug
        }
        public ActionResult DeleteTreatment(int id)
        {
            Hairdresser hairdresser = _hairdresserRepository.GetByEmail(User.Identity.Name);

            if (hairdresser == null)
            {
                return(NotFound());
            }

            Treatment treatment = hairdresser.GetTreatment(id);

            if (treatment == null)
            {
                return(NotFound());
            }

            hairdresser.RemoveTreatment(treatment);
            _hairdresserRepository.SaveChanges();

            return(NoContent());
        }
Beispiel #4
0
        public ActionResult <IList <DateTime> > GetAvailableTimes(int id, DateTime date, IEnumerable <Treatment> selectedTreatments)
        {
            Hairdresser hairdresser = _hairdresserRepository.GetBy(id);

            if (hairdresser == null)
            {
                return(NotFound());
            }

            IList <Treatment> treatments = new List <Treatment>();

            foreach (Treatment tr in selectedTreatments)
            {
                treatments.Add(hairdresser.GetTreatment(tr.Id));
            }

            if (treatments.Count < 1)
            {
                return(BadRequest());
            }

            return(Ok(hairdresser.GiveAvailableTimesOnDate(date, treatments)));
        }