コード例 #1
0
        public BookingCostDto Cost(MakeBookingInfoDto makeBookingInfo)
        {
            Validate();
            DateTime from = makeBookingInfo.GetFromDateTime();
            DateTime to   = makeBookingInfo.GetToDateTime();

            return(_costEvaluationService.EvaluateBookingCost(from, to, makeBookingInfo.PromoCode));
        }
コード例 #2
0
ファイル: BookingService.cs プロジェクト: gerrkoff/studio404
        public int MakeBooking(MakeBookingInfoDto makeBookingInfo, CurrentUser user)
        {
            DateTime from = makeBookingInfo.GetFromDateTime();
            DateTime to   = makeBookingInfo.GetToDateTime();

            if (!user.PhoneConfirmed)
            {
                throw new ServiceException("User does not have such permissions");
            }

            if (from < _dateService.NowUtc.Date)
            {
                throw new ServiceException($"Booking is invalid for this action \r\n ____ from less than date now. From='{from}' Date='{_dateService.NowUtc.Date}'");
            }


            if (GetBookingsForPeriod(from, to).Any())
            {
                string bookingIds = GetBookingsForPeriod(from, to).Select(x => x.Id.ToString())
                                    .Aggregate((s1, s2) => s1 + "," + s2);
                throw new ServiceException($"Booking is invalid for this action \r\n ____ has bookings for period. From='{from}' To='{to}' Ids='{bookingIds}'");
            }

            // TODO: Implement checking schedule

            BookingCostDto bookingCost =
                _costEvaluationService.EvaluateBookingCost(from, to, makeBookingInfo.PromoCode);
            var booking = new BookingEntity
            {
                From        = from,
                To          = to,
                Status      = BookingStatusEnum.Unpaid,
                Guid        = Guid.NewGuid(),
                Cost        = bookingCost.TotalCost,
                PromoCodeId = bookingCost.PromoCode?.Id,
                UserId      = user.UserId
            };

            _bookingRepository.Save(booking);

            return(booking.Id);
        }