Ejemplo n.º 1
0
        public BookingValidation ValidateBooking(BookingRequest bookingRequest, IEnumerable <Agent> allAgents, IEnumerable <Property> allProperties)
        {
            if (string.IsNullOrEmpty(bookingRequest.Name))
            {
                return(BookingValidation.InValid("You must provide a name"));
            }

            if (string.IsNullOrEmpty(bookingRequest.EmailAddress))
            {
                return(BookingValidation.InValid("You must provide an email address"));
            }

            var agent = FindAgentForBooking(bookingRequest, allAgents);

            if (agent == null)
            {
                return(BookingValidation.InValid("Sorry - we couldn't find a matching agent."));
            }

            var property = FindPropertyForBooking(bookingRequest, allProperties);

            if (property == null)
            {
                return(BookingValidation.InValid("Sorry - we couldn't find a matching property."));
            }

            return(BookingValidation.Valid());
        }
        public async Task <IHttpActionResult> PutBookingModels(int id, BookingRequestDTO bookingRequest)
        {
            var bookingValidator = new BookingValidation();
            var errorList        = bookingValidator.ValidateBookingRequestDTO(bookingRequest);

            if (!errorList.All(x => x == true))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "The Booking Request is invalid or otherwise incomplete.")));
            }

            bookingRequest = await bookingServices.UpdateSingleBooking(id, bookingRequest);

            return(Ok(bookingRequest));
        }
Ejemplo n.º 3
0
 public BookingValidation ValidateBooking(BookingRequest bookingRequest, IEnumerable <Agent> allAgents, IEnumerable <Property> allProperties)
 {
     if (string.IsNullOrWhiteSpace(bookingRequest.Name))
     {
         return(BookingValidation.Invalid("You must provide a name"));
     }
     if (string.IsNullOrWhiteSpace(bookingRequest.PhoneNumber))
     {
         return(BookingValidation.Invalid("You must provide a valid phone number"));
     }
     return(new BookingValidation
     {
         IsValid = true, ErrorMessage = ""
     });
 }
        public async Task <IHttpActionResult> PostBookingModels(BookingRequestDTO bookingRequest)
        {
            if (bookingRequest == null)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "The Booking Request is invalid or otherwise incomplete.")));
            }
            var bookingValidator = new BookingValidation();
            var errorList        = bookingValidator.ValidateBookingRequestDTO(bookingRequest);

            if (!errorList.All(x => x == true))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "The Booking Request is invalid or otherwise incomplete.")));
            }
            // kalla på service layer valideringsmetod(bookingRequest);

            bookingRequest = await bookingServices.AddBookingRequest(bookingRequest);

            // TO DO returnera fel om en sådan booking redan finns

            await mailservices.NotifyBookingByMail(bookingRequest);

            return(CreatedAtRoute("DefaultApi", new { id = bookingRequest.Id }, bookingRequest));
        }