Exemple #1
0
        private bool IsValidBooking(BookingModel booking, Result result)
        {
            if (TypeValidator.Validate(booking) == FlowOptions.Failed)
            {
                result.AddMessageToList(BookingResource.NotValidBooking);
            }
            else
            {
                if (booking.StartDate >= booking.EndDate)
                {
                    result.AddMessageToList(BookingResource.DatesNotValid);
                }
                if (TypeValidator.Validate(booking.IdHotel) == FlowOptions.Failed)
                {
                    result.AddMessageToList(BookingResource.HotelRequired);
                }
                if (TypeValidator.Validate(booking.IdRoom) == FlowOptions.Failed)
                {
                    result.AddMessageToList(BookingResource.RoomRequired);
                }
                if (TypeValidator.Validate(booking.ApplicantName) == FlowOptions.Failed)
                {
                    result.AddMessageToList(BookingResource.ApplicantRequired);
                }
                if (TypeValidator.Validate(booking.Email) == FlowOptions.Failed)
                {
                    result.AddMessageToList(BookingResource.EmailRequired);
                }
                if (TypeValidator.Validate(booking.ContactName) == FlowOptions.Failed)
                {
                    result.AddMessageToList(BookingResource.ContactNameRequired);
                }
                if (TypeValidator.Validate(booking.ContactPhone) == FlowOptions.Failed)
                {
                    result.AddMessageToList(BookingResource.ContactPhoneRequired);
                }

                foreach (GuestModel guest in booking.Guests)
                {
                    if (TypeValidator.Validate(guest) == FlowOptions.Failed)
                    {
                        result.AddMessageToList(BookingResource.NotValidGuest);
                    }
                    else
                    {
                        if (TypeValidator.Validate(guest.Name) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestNameRequired);
                        }
                        if (TypeValidator.Validate(guest.LastName) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestLastNRequired);
                        }
                        if (TypeValidator.Validate(guest.BirtDate) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestBirtRequired);
                        }
                        if (TypeValidator.Validate(guest.Name) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestNameRequired);
                        }
                        if (TypeValidator.Validate(guest.LastName) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestLastNRequired);
                        }
                        if (TypeValidator.Validate(guest.BirtDate) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestBirtRequired);
                        }
                        if (TypeValidator.Validate(guest.Genre) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestGenreRequired);
                        }
                        if (TypeValidator.Validate(guest.Identification) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestIdRequired);
                        }
                        if (TypeValidator.Validate(guest.IdentificationType) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestIdTypeRequired);
                        }
                        if (TypeValidator.Validate(guest.Email) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuesEmailRequired);
                        }
                        if (TypeValidator.Validate(guest.PhoneNumber) == FlowOptions.Failed)
                        {
                            result.AddMessageToList(BookingResource.GuestPhoneRequired);
                        }
                    }
                }
            }
            return((result.Messages.Count == 0) ? true : false);
        }
Exemple #2
0
        public Result CreateBooking(BookingModel booking)
        {
            Result result = new Result();

            if (!IsValidBooking(booking, result))
            {
                result.Message     = result.GetMessages(" - ");
                result.Data        = booking;
                result.FlowControl = FlowOptions.Failed;
                return(result);
            }
            RoomModel  room  = BookingRepository.GetRoom(booking.IdHotel, booking.IdRoom);
            HotelModel hotel = BookingRepository.GetHotel(booking.IdHotel);

            if (room != null && hotel != null)
            {
                booking.Price       = room.Price;
                booking.Tax         = hotel.Tax;
                booking.SubTotal    = room.Price * (booking.EndDate - booking.StartDate).Days;
                booking.Total       = booking.SubTotal * 1 + (booking.SubTotal * 100 / booking.Tax);
                booking.EmailSended = false;
                if (IsRoomAvailable(booking.IdRoom, booking.StartDate, booking.EndDate))
                {
                    BookingModel newBooking = BookingRepository.CreateBooking(booking);
                    if (newBooking != null)
                    {
                        result.Data        = newBooking;
                        result.FlowControl = FlowOptions.Success;
                        // TODO: send email here
                    }
                }
                else
                {
                    result.Message     = result.GetMessages(" - ");
                    result.Data        = booking;
                    result.FlowControl = FlowOptions.Failed;
                }
            }
            else
            {
                if (room == null)
                {
                    result.AddMessageToList(BookingResource.RoomNotFound);
                }
                if (hotel == null)
                {
                    result.AddMessageToList(BookingResource.HotelNotFound);
                }
                result.Message     = result.GetMessages(" - ");
                result.Data        = booking;
                result.FlowControl = FlowOptions.Failed;
            }
            return(result);

            bool IsRoomAvailable(long roomId, DateTime startDate, DateTime endDate)
            {
                var available = BookingRepository.IsRoomAvailable(roomId, startDate, endDate);

                if (available.Item2 != null)
                {
                    result.AddMessageToList(String.Format(BookingResource.RoomNoAvailableIntro, BookingResource.RoomNotAvailable, available.Item2.StartDate, available.Item2.EndDate));
                }
                return(available.Item1);
            }
        }