Esempio n. 1
0
        private IHttpActionResult _submitToDatabase(Reservation_DTO reservation_DTO)
        {
            IHttpActionResult result;

            try
            {
                Treatment   treatmentToUse   = _dbTreatment.GetTreatmentByID(reservation_DTO.TreatmentID);
                Reservation reservationToAdd = new Reservation(treatmentToUse, reservation_DTO.CustomerID, reservation_DTO.EmployeeID, reservation_DTO.StartTime);
                result = Ok(_dbReservation.InsertReservationToDatabase(reservationToAdd));
            }
            catch (SqlException)
            {
                result = Content(HttpStatusCode.InternalServerError, "Could not insert data into database.");
            }
            catch (NullReferenceException)
            {
                result = Content(HttpStatusCode.NotFound, $"The Treatment with the ID ({reservation_DTO.TreatmentID}) was not found.");
            }
            catch (ArgumentException)
            {
                result = Content(HttpStatusCode.Conflict, "There occurred a conflict with the selected time.");
            }

            return(result);
        }
Esempio n. 2
0
        // GET: api/Treatment/5
        public IHttpActionResult Get(int id)
        {
            IHttpActionResult result;
            Treatment         treatmentFound = _dbTreatment.GetTreatmentByID(id);

            if (treatmentFound != null)
            {
                result = Ok(treatmentFound);
            }
            else
            {
                result = Content(HttpStatusCode.NotFound, $"The id #{id} was not found!");
            }

            return(result);
        }