Пример #1
0
        internal static BookingBill GetBookingBill(IEnumerable<RestaurantMenuItem> restaurantMenuItems, IEnumerable<RestaurantTable> restaurantTables, SeasonalOffer restaurantOffer, Coupon restaurantcoupon, int bookedslots)
        {
            var discountamt = 0M;
            decimal grossamount = restaurantTables.Sum(restaurantTable => restaurantTable.Price * bookedslots);
            grossamount = restaurantMenuItems.Aggregate(grossamount, (current, restaurantMenuItem) => (int)(current + restaurantMenuItem.Price));

            var offer = (restaurantcoupon as OfferBase) ?? (restaurantOffer);

            var netamount = grossamount;
            if (offer != null)
            {
                switch (offer.Type)
                {
                    case OfferBase.OfferType.DiscountAmount:
                        {
                            discountamt = offer.Value;
                            netamount = grossamount - discountamt;
                            if (netamount < 0) netamount = 0;
                            break;
                        }
                    case OfferBase.OfferType.DiscountPercent:
                        {
                            discountamt = (grossamount * offer.Value) / 100M;
                            netamount = grossamount - discountamt;
                            break;
                        }
                    case OfferBase.OfferType.FreeServing:
                        {
                            discountamt = new RestaurantMenuItemRepository().Find(offer.Value).Price;
                            netamount = grossamount - discountamt;
                            break;
                        }
                }
            }

            if (netamount < 0)
                throw new InvalidOperationException("Discount amount cannot be more than the total amount of the Bill");
            return new BookingBill
                       {
                           DiscountAmount = discountamt,
                           GrossAmount = grossamount,
                           NetAmount = netamount
                       };
        }
Пример #2
0
 internal static void ValidateModel(Controller controller, BookingViewModel model, int? offerid, string couponcode, out IEnumerable<RestaurantMenuItem> restaurantMenuItems,
                                  out IEnumerable<RestaurantTable> restaurantTables, out SeasonalOffer restaurantOffer, out Coupon restaurantCoupon)
 {
     ValidateModel(controller, model, offerid, out restaurantMenuItems, out restaurantTables, out restaurantOffer);
     restaurantCoupon = null;
     if (couponcode.IsNullOrEmpty()) return;
     var result = new OfferBaseRepository().FindCouponByCode(couponcode.Trim());
     if (result != null)
     {
         if (result.ValidTill.ToUniversalTime() > DateTime.UtcNow)
         {
             restaurantCoupon = result;
             return;
         }
         controller.ModelState.AddModelError("addstatus", "Coupon Code has expired !");
         return;
     }
     controller.ModelState.AddModelError("addstatus", "Invalid Coupon code provided.");
 }