//get all extra attributes for an extra ID
        public static List<BookingExtraAttribute> GetBookingExtraAttributesByBookingExtra(BookingExtra aBookingExtra)
        {
            List<BookingExtraAttribute> theListOfAttributes = new List<BookingExtraAttribute>();
            PortugalVillasContext _db = new PortugalVillasContext();

            return theListOfAttributes = _db.BookingExtraAttributes.Where(x => x.BookingExtraID == aBookingExtra.BookingExtraID)
              .ToList();
        }
Пример #2
0
        public static string GetBookingExtraPRCReferenceFromID(BookingExtraSelection aBookingExtraSelection)
        {
            BookingExtra aBookingExtra = new BookingExtra();

            PortugalVillasContext _db = new PortugalVillasContext();

            aBookingExtra = _db.BookingExtras.Where(x => x.BookingExtraID == aBookingExtraSelection.BookingExtraID).FirstOrDefault();

            return(aBookingExtra.LegacyReference);
        }
Пример #3
0
        public static BookingExtra GetBookingExtrasFromBookingExtraSelection(BookingExtraSelection aBookingExtraSelection)
        {
            BookingExtra aBookingExtra = new BookingExtra();

            PortugalVillasContext _db = new PortugalVillasContext();

            aBookingExtra = _db.BookingExtras.Where(x => x.BookingExtraID == aBookingExtraSelection.BookingExtraID).FirstOrDefault();

            return(aBookingExtra);
        }
Пример #4
0
        public static BookingExtra GetBookingExtraByID(long?ID)
        {
            PortugalVillasContext _db = new PortugalVillasContext();

            BookingExtra bookingExtra = _db.BookingExtras
                                        .Where(x => x.BookingExtraID == ID)
                                        .First();


            return(bookingExtra);
        }
Пример #5
0
        public long?GetBookingExtraTypeIDFromBookingExtraSelection()
        {
            PortugalVillasContext _db = new PortugalVillasContext();

            //get the booking extra

            BookingExtra BookingExtra = _db.BookingExtras.Where(x => x.BookingExtraID == this.BookingExtraID).FirstOrDefault();


            return(BookingExtra.BookingExtraTypeID);
        }
        public static string GetBookingExtraPRCReferenceFromID(BookingExtraSelection aBookingExtraSelection)
        {
            BookingExtra aBookingExtra = new BookingExtra();

            PortugalVillasContext _db = new PortugalVillasContext();

            aBookingExtra = _db.BookingExtras.Where(x => x.BookingExtraID == aBookingExtraSelection.BookingExtraID).FirstOrDefault();

            return aBookingExtra.LegacyReference;

        }
        public static BookingExtra GetBookingExtrasFromBookingExtraSelection(BookingExtraSelection aBookingExtraSelection)
        {
            BookingExtra aBookingExtra = new BookingExtra();

            PortugalVillasContext _db = new PortugalVillasContext();

            aBookingExtra = _db.BookingExtras.Where(x => x.BookingExtraID == aBookingExtraSelection.BookingExtraID).FirstOrDefault();

            return aBookingExtra;

        }
        public ActionResult Create(BookingExtra bookingextra)
        {
            if (ModelState.IsValid)
            {
                db.BookingExtras.Add(bookingextra);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return View(bookingextra);
        }
        public string GenerateBESReference(BookingExtraSelection bes, BookingExtra extra)
        {
            string reference = "";

          
            reference += extra.LegacyReference;
            reference += "/" + bes.BookingExtraSelectionID;
            reference += "/" + ((DateTime)bes.ExtraRentalDate).ToString("ddMMyyyy").Replace("/", "").Replace("-", "");


            return reference;
        }
        public ActionResult Create(BookingExtra bookingextra)
        {
            bookingextra.WhenCreated = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.BookingExtras.Add(bookingextra);
                db.SaveChanges();
                ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
                return RedirectToAction("SingleBookingExtraIndex", "BookingExtra", new { bookingextraID = bookingextra.BookingExtraID });
            }

            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return View(bookingextra);
        }
 public ActionResult Edit(BookingExtra bookingextra)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookingextra).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
     return View(bookingextra);
 }
        public BookingExtraSelection CreateBookingExtraSelection(BookingExtraSelection bookingExtraSelection, BookingExtra extra, Customer theCustomer, PortugalVillasContext db)
        {
            bookingExtraSelection.BESCurrencyConversionSymbol = theCustomer.PreferredCurrencySymbol;
            bookingExtraSelection.BESPreferredCurrency = theCustomer.PreferredCurrency;

            var cc = new CurrencyConverterController();


            long? currentBookingTypeID = bookingExtraSelection.GetBookingExtraTypeIDFromBookingExtraSelection();
            bookingExtraSelection.CustomerID = theCustomer.CustomerID;

            //the price already needs to be assigned
            bookingExtraSelection.BESPrice = BookingExtraSelection.GetBookingExtraPrice(bookingExtraSelection, db);
            bookingExtraSelection.BESExtraServicesPrice = BookingExtraSelection.CalculateBookingExtraAdditionalCostsAndAssignToThisBooking(bookingExtraSelection, db);

            bookingExtraSelection.BESTotalServicesPrice = BookingExtraSelection.GetBookingExtraTotalServicesPrice(bookingExtraSelection, db);


            bookingExtraSelection.WhenCreated = DateTime.Now;

            //calc number of guests
            if (bookingExtraSelection.NumberOfGuests == null || bookingExtraSelection.NumberOfGuests == 0)
            {
                bookingExtraSelection.CalculateNoOfGuests();
            }

            //if not UK need to do currency conversion
            if (theCustomer.Country.ToLower() != "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP")
            {
                var baseCurrency = "GBP";
                var newCurrency = "EUR";

                var exchangeRateFromDB =
                    db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-EUR");

                try
                {
                    bookingExtraSelection.BESPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESPrice);
                    bookingExtraSelection.BESCurrencyConversionPrice = bookingExtraSelection.BESPrice;
                    bookingExtraSelection.BESExtraServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESExtraServicesPrice);
                    bookingExtraSelection.BESTotalServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESTotalServicesPrice);

                

                    //set exchange rate
                    bookingExtraSelection.BESCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    bookingExtraSelection.BESCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate;
                    bookingExtraSelection.BESPreferredCurrency = "EUR";
                }
                catch (Exception)
                {

                    throw;
                }

            }

            else if (ConfigurationManager.AppSettings["defaultCurrency"] == "USD")
            {
                var baseCurrency = "GBP";
                var newCurrency = "USD";

                var exchangeRateFromDB =
                    db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-USD");

                try
                {
                    bookingExtraSelection.BESPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESPrice);
                    bookingExtraSelection.BESCurrencyConversionPrice = bookingExtraSelection.BESPrice;
                    bookingExtraSelection.BESExtraServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESExtraServicesPrice);
                    bookingExtraSelection.BESTotalServicesPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESTotalServicesPrice);


                    //set exchange rate
                    bookingExtraSelection.BESCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    bookingExtraSelection.BESCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate;
                    bookingExtraSelection.BESPreferredCurrency = "USD";
                }
                catch (Exception)
                {

                    throw;
                }
            }

            //generate reference
            var refGenService = new ReferenceGenerationService();
            bookingExtraSelection.BookingExtraPRCReference = refGenService.GenerateBESReference(bookingExtraSelection, extra);


            if (ModelState.IsValid)
            {
                db.BookingExtraSelections.Add(bookingExtraSelection);
                if (db.SaveChanges() > 0)
                {
                    //generate reference with ID
                    bookingExtraSelection.BookingExtraPRCReference = refGenService.GenerateBESReference(bookingExtraSelection, extra);

                    db.Entry(bookingExtraSelection).State = EntityState.Modified;
                    db.SaveChanges();
                    return bookingExtraSelection;

                }


            }
            throw new Exception();

        }
Пример #13
0
        //get all extra attributes for an extra ID

        public static List <BookingExtraAttribute> GetBookingExtraAttributesByBookingExtra(BookingExtra aBookingExtra)
        {
            List <BookingExtraAttribute> theListOfAttributes = new List <BookingExtraAttribute>();
            PortugalVillasContext        _db = new PortugalVillasContext();

            return(theListOfAttributes = _db.BookingExtraAttributes.Where(x => x.BookingExtraID == aBookingExtra.BookingExtraID)
                                         .ToList());
        }
        public ActionResult Edit(BookingExtra bookingextra)
        {
            var oldExtra = db.BookingExtras.Where(x => x.BookingExtraID == bookingextra.BookingExtraID).First();
            bookingextra.WhenCreated = oldExtra.WhenCreated;
            bookingextra.WhenModified = oldExtra.WhenModified;

            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.BookingExtras.Attach(bookingextra);
                    _db.Entry(bookingextra).State = EntityState.Modified;
                    _db.SaveChanges();
                    ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID",
                        "ExtraTypeName", bookingextra.BookingExtraTypeID);
                    return RedirectToAction("SingleBookingExtraIndex", "BookingExtra",
                        new {bookingextraID = bookingextra.BookingExtraID});
                }
            }
            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return View(bookingextra);
        }
Пример #15
0
        /// <summary>
        /// Assigns Price To This Booking Extra Selection
        /// Check how many days for each booking (make sure the rental is done by days and not nights)
        /// Check which season each day falls under (e.g. the price)
        /// Divide that price by the requite amount and add that amount to the running total
        ///
        ///
        /// </summary>
        ///
        public static decimal GetBookingExtraPrice(BookingExtraSelection bes, PortugalVillasContext _db)
        {
            decimal BESPrice = 0.00M; //reset any existing price

            var thisBookingExtraType   = BookingExtraSelection.GetBookingExtrasFromBookingExtraSelection(bes);
            var thisBookingExtraTypeID = thisBookingExtraType.BookingExtraTypeID;

            try
            {
                //need to know what type it is - car rental prices by the day, rest have flat fee
                if (thisBookingExtraTypeID == 1)
                {
                    /*Low season Nov - Mar
                     * Mid season Apr, May and Oct
                     * High Season June and Sept
                     * Peak season July and August
                     *
                     */


                    decimal runningTotal = 0.00M;

                    List <DateTime> DatesToCalulcuatePriceFor = new List <DateTime>();


                    DateTime CurrentDate = (DateTime)bes.ExtraRentalDate;

                    //we don't add the last day, because it needs to be returned on that day (they don't get charged)

                    while (CurrentDate < bes.ExtraReturnDate)
                    {
                        DatesToCalulcuatePriceFor.Add(CurrentDate);
                        CurrentDate = CurrentDate.AddDays(1);
                    }



                    foreach (var day in DatesToCalulcuatePriceFor)
                    {
                        int monthThatTheRentalIsIn = ((DateTime)day).Month;

                        //check where the start date is - that's the season it's in
                        string SeasonOfRental = bes.GetRentalSeasonFromMonth(monthThatTheRentalIsIn);


                        switch (SeasonOfRental)
                        {
                        case "LowSeason":
                            bes.BESPrice = thisBookingExtraType.LowSeasonPrice;
                            break;

                        case "MidSeason":
                            bes.BESPrice = thisBookingExtraType.MidSeasonPrice;
                            break;

                        case "HighSeason":
                            bes.BESPrice = thisBookingExtraType.HighSeasonPrice;
                            break;

                        case "PeakSeason":
                            bes.BESPrice = thisBookingExtraType.PeakSeasonPrice;
                            break;

                        default:
                            bes.BESPrice = 0.00M;
                            break;
                        }

                        //now get the price per day
                        runningTotal += Convert.ToDecimal(bes.BESPrice / 7);
                    }

                    //all done, assign and exit
                    return(Decimal.Round(runningTotal, 2));
                }


                //airport = nothing to do, fixed price

                //end airport

                //wine tours and tours - price is per person and depends on how many people are going
                else if (((new[] { 2, 4 }).Contains(Convert.ToInt32(thisBookingExtraTypeID))))
                {
                    int monthThatTheRentalIsIn = ((DateTime)bes.ExtraRentalDate).Month;

                    //check where the start date is - that's the season it's in
                    string SeasonOfRental = bes.GetRentalSeasonFromMonth(monthThatTheRentalIsIn);


                    var noOfPeopleOnThisTour = (bes.NumberOfAdults + bes.NumberOfChildren);


                    //get the list of all types for that and order correctly so lowest is first
                    List <BookingExtra> potentialPrices =
                        _db.BookingExtras.Where(
                            a => a.BookingExtraSubTypeID == thisBookingExtraType.BookingExtraSubTypeID).OrderBy(d => d.MaxPersons).ToList();


                    BookingExtra theCorrectPricing = null;

                    foreach (var potentialPrice in potentialPrices)
                    {
                        //get the minimum no of people left
                        if (noOfPeopleOnThisTour <= potentialPrice.MaxPersons)
                        {
                            theCorrectPricing = potentialPrice;
                            break;
                        }
                    }

                    decimal?individualPrice = 0.00M;

                    //get the correct season
                    switch (SeasonOfRental)
                    {
                    case "LowSeason":
                        individualPrice = theCorrectPricing.LowSeasonPrice;
                        break;

                    case "MidSeason":
                        individualPrice = theCorrectPricing.MidSeasonPrice;
                        break;

                    case "HighSeason":
                        individualPrice = theCorrectPricing.HighSeasonPrice;
                        break;

                    case "PeakSeason":
                        individualPrice = theCorrectPricing.PeakSeasonPrice;
                        break;

                    default:
                        individualPrice = 0.00M;
                        break;
                    }



                    // multiply number of people by price and we have a final price - for tours and wine tours


                    decimal?totalPriceToReturn = 0.00M;

                    if (thisBookingExtraType.BookingExtraTypeID == 2 || thisBookingExtraType.BookingExtraTypeID == 4)
                    {
                        totalPriceToReturn += noOfPeopleOnThisTour * individualPrice;
                    }
                    if (thisBookingExtraType.BookingExtraTypeID == 3)
                    {
                        totalPriceToReturn += individualPrice;
                    }

                    return(Decimal.Round((decimal)totalPriceToReturn, 2));

                    //else return the group price (for airport transfers) - do nothing
                }

                //airport transfers
                else if (((new[] { 3 }).Contains(Convert.ToInt32(thisBookingExtraTypeID))))
                {
                    int monthThatTheRentalIsIn = ((DateTime)bes.ExtraRentalDate).Month;

                    //check where the start date is - that's the season it's in
                    string SeasonOfRental = bes.GetRentalSeasonFromMonth(monthThatTheRentalIsIn);


                    var noOfPeopleOnThisTour = (bes.NumberOfAdults + bes.NumberOfChildren);


                    //get the list of all types for that and order correctly so lowest is first
                    List <BookingExtra> potentialPrices =
                        _db.BookingExtras
                        .Where(x => x.BookingExtraTypeID == thisBookingExtraType.BookingExtraTypeID)
                        .Where(x => x.AirportPickupLocationID == bes.AirportPickupLocationID)
                        .OrderBy(d => d.MaxPersons).ToList();


                    BookingExtra theCorrectPricing = null;

                    foreach (var potentialPrice in potentialPrices)
                    {
                        //get the minimum no of people left
                        if (noOfPeopleOnThisTour <= potentialPrice.MaxPersons)
                        {
                            theCorrectPricing = potentialPrice;
                            break;
                        }
                    }

                    decimal?totalPriceToReturn = 0.00M;

                    //get the correct season
                    switch (SeasonOfRental)
                    {
                    case "LowSeason":
                        totalPriceToReturn = theCorrectPricing.LowSeasonPrice;
                        break;

                    case "MidSeason":
                        totalPriceToReturn = theCorrectPricing.MidSeasonPrice;
                        break;

                    case "HighSeason":
                        totalPriceToReturn = theCorrectPricing.HighSeasonPrice;
                        break;

                    case "PeakSeason":
                        totalPriceToReturn = theCorrectPricing.PeakSeasonPrice;
                        break;

                    default:
                        totalPriceToReturn = 0.00M;
                        break;
                    }

                    return(Decimal.Round((decimal)totalPriceToReturn, 2));
                }
                //default
                else
                {
                    throw new Exception("Couldn't calculate a price for this BookingExtraSelection!!!");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }