/// <summary> /// Gets /// </summary> public static CustomerBankDetail GetCustomerBankDetailFromCustomer(Customer aCustomer) { PortugalVillasContext db = new PortugalVillasContext(); CustomerBankDetail theBankDetailsToReturn = db.CustomerBankDetails.Where(x => x.CustomerID == aCustomer.CustomerID).FirstOrDefault(); return theBankDetailsToReturn; }
// // GET: /DocumentMangementService/ public ActionResult CreateDocumentAndSaveToLocation() { var db = new PortugalVillasContext(); var parentContainer = new BookingParentContainer(); //dependenceies var dc = new DocumentGenerationController(); var customer = db.Customers.Find(1); var booking = db.Bookings.Find(4); var type = PRCDocument.PRCDocumentType.UK_WineTasting; //create a document with all parsed variables var document = dc.CreateDocumentToFileSystem(customer, type, booking); /* db.Documents.Add(new Document { CustomerID = customer.CustomerID, DocumentBLOB = document, EventID = 2 }); db.SaveChanges();*/ //save it to the DB or the FileSystem return RedirectToAction("Dashboard", "Admin"); }
//get all the booking extra types public static List<BookingExtraType> GetBookingExtraTypes() { List<BookingExtraType> theList = new List<BookingExtraType>(); PortugalVillasContext _db = new PortugalVillasContext(); return theList = _db.BookingExtraTypes.ToList(); }
public static List<BookingExtraAttribute> GetBookingExtraAttributesByBookingExtraID(long? bookingExtraID) { List<BookingExtraAttribute> theListOfAttributes = new List<BookingExtraAttribute>(); PortugalVillasContext _db = new PortugalVillasContext(); return theListOfAttributes = _db.BookingExtraAttributes.Where(x => x.BookingExtraID == bookingExtraID).ToList(); }
public static int CreateAccountsForOwnersWithoutAccount(PortugalVillasContext db) { //get all ownersIDs var owners = db.PropertyOwners.ToList(); //checks they all have an account is accounts var accounts = db.PropertyOwnerAccounts.ToList(); List<PropertyOwnerAccount> accountsToCreate = new List<PropertyOwnerAccount>(); foreach (var propertyOwner in owners) { var account = accounts.Where(x => x.PropertyOwnerID == propertyOwner.PropertyOwnerID).FirstOrDefault(); if (account == null) { db.PropertyOwnerAccounts.Add(new PropertyOwnerAccount { AccountBalance = 0.00M, PropertyOwnerID = propertyOwner.PropertyOwnerID }); } } return db.SaveChanges(); }
private static List<BookingAndRelatedTransactions> ReturnAllBookingsAndTransactions(long AccountID, PortugalVillasContext db) { var owner = db.PropertyOwnerAccounts.Where(x => x.AccountID == AccountID).First(); var props = db.Properties.Where(x => x.PropertyOwnerID == owner.PropertyOwnerID).ToList(); var bookings = new List<Booking>(); foreach (var property in props) { bookings.AddRange(db.Bookings.Where(booking => booking.PropertyID == property.PropertyID).Include(x=>x.Property).ToList()); } var transactions = db.AccountTransactions.Where(x => x.AccountID == AccountID).Where(x=>x.Voided != true); List<BookingAndRelatedTransactions> bookingAndTrans = new List<BookingAndRelatedTransactions>(); foreach (var booking in bookings) { bookingAndTrans.Add(new BookingAndRelatedTransactions { booking = booking, transactions = transactions.Where(x=>x.BookingID == booking.BookingID).ToList() }); } return bookingAndTrans; }
public static List<Comment> GetRandomTopRatedComments() { try { PortugalVillasContext _db = new PortugalVillasContext(); List<Comment> theCommentsList = new List<Comment>(); return theCommentsList = _db.Comments.Where(x => x.StarRating > 2) .Where(x => x.Approved == true).Take(10) .ToList(); } catch (Exception ex) { throw ex; } throw new Exception(); }
public Property() { this.Bookings = new List<Booking>(); this.Comments = new List<Comment>(); this.Packages = new List<Package>(); this.PropertyEntities = new List<PropertyEntity>(); this.PropertyPricingSeasonalInstances = new List<PropertyPricingSeasonalInstance>(); this.PropertySecurityItems = new List<PropertySecurityItem>(); this.PropertyStaffTaskAssignments = new List<PropertyStaffTaskAssignment>(); //set up datasets using (var _db = new PortugalVillasContext()) { var pricesForThisProp = _db.PropertyPricingSeasonalInstances.Where(x => x.PropertyID == this.PropertyID).ToList(); if (pricesForThisProp.Count() > 0) { this.PropertyPricingSeasonalInstances = _db.PropertyPricingSeasonalInstances.Where(x => x.PropertyID == this.PropertyID).ToList(); } } switch (this.Active) { case true: CreatePriceRange(); break; } }
//get individual booking by ID -- NEED TO TEST FOR EMPTY RESULT public static Booking GetBookingByID(int bookingID) { PortugalVillasContext _db = new PortugalVillasContext(); var aBooking = _db.Bookings.Include(x => x.Property).FirstOrDefault(x => x.BookingID == bookingID); return aBooking; }
///////////////////////////// //// STATIC METHODS ///////////////////////////// //INT or STRING methods to get a list of properties- all return List<Property> ////////////////////////////////////////////////////////// ////These methods pull back Properties based on given criteria ////////////////////////////////////////////////////////// public static List<Property> GetAllProperties() { PortugalVillasContext _db = new PortugalVillasContext(); var allProperties = _db.Properties.ToList(); return allProperties; }
public static Customer GetSingleCustomer(long? CustomerID) { PortugalVillasContext _db = new PortugalVillasContext(); var aCustomer = (_db.Customers .Where(x => x.CustomerID == CustomerID).First()); return (Customer) aCustomer; }
//get all the booking extras - return list public static List<BookingExtra> GetBookingExtras() { List<BookingExtra> theList = new List<BookingExtra>(); PortugalVillasContext _db = new PortugalVillasContext(); return theList = _db.BookingExtras .Where(x => x.TopLevelItem == true) .ToList(); }
protected DateTime? GetMaxBooking() { PortugalVillasContext _db = new PortugalVillasContext(); DateTime? maxBooking = _db.Bookings .Max(x => x.StartDate); return maxBooking; }
public static List<CommentSection> GetAllCommentSectionsForComment(Comment aComment) { PortugalVillasContext _db = new PortugalVillasContext(); List<CommentSection> theCommentSections = new List<CommentSection>(); theCommentSections = _db.CommentSections.Where(x => x.CommentID == aComment.CommentID).ToList(); return theCommentSections; }
//////////TITLES////////////////// ////////////////////////////////// //GET the title public static List<Title> GetTitles() { using(PortugalVillasContext _db = new PortugalVillasContext()){ List<Title> TitleList = _db.Titles.ToList(); return TitleList; } }
public static PRCInformation GetPRCInformation() { using (var db = new PortugalVillasContext()) { return db.PRCInformations.FirstOrDefault(); } }
// // GET: /Document/ public FileContentResult ReturnPDFDocument(long id) { using (var db = new PortugalVillasContext()) { var doc = db.Documents.First(c => c.DocumentID == id); //.DocumentTable.First(p => p.DocumentUID == id); byte[] data = doc.DocumentBLOB; return File(data, "application/pdf", doc.DocumentName); } }
public static List<CommentReply> GetCommentReplies() { PortugalVillasContext _db = new PortugalVillasContext(); List<CommentReply> theCommentReplies = new List<CommentReply>(); theCommentReplies = _db.CommentReplies.Where(x => x.Approved == true).ToList(); return theCommentReplies; }
public static long GetBookingExtraIDByPRCReference(string prcRef) { PortugalVillasContext _db = new PortugalVillasContext(); long theID = _db.BookingExtras .Where(x => x.LegacyReference == prcRef.Trim()) .Select(x => x.BookingExtraID).First(); return theID; }
public static List<BookingExtra> GetBookingExtrasFromBookingExtraSelection(BookingExtraSelection aBookingExtraSelection) { List<BookingExtra> aBookingExtra = new List<BookingExtra>(); PortugalVillasContext _db = new PortugalVillasContext(); aBookingExtra = _db.BookingExtras.Where(x => x.BookingExtraID == aBookingExtraSelection.BookingExtraID).ToList(); return aBookingExtra; }
//////////////////////////////// ///// INSTANCE Methods //////////////////////////////// //////////////////////////////// ///// STATIC Methods //////////////////////////////// public static List<PropertyPricing> GetPricingByPropertyID(long? propertyID) { PortugalVillasContext _db = new PortugalVillasContext(); var thePriceRange= _db.PropertyPricings .OrderByDescending(x => x.PricingStartDate) .Where(x => x.PropertyID == propertyID).ToList(); return thePriceRange; }
public static List<Comment> GetComments(Property aProperty) { PortugalVillasContext _db = new PortugalVillasContext(); List<Comment> theCommentsList = new List<Comment>(); theCommentsList = _db.Comments.Where(x => x.PropertyID == aProperty.PropertyID).ToList(); return theCommentsList; }
public static List<EntityCommonField> GetAllCommonFields() { using (PortugalVillasContext _db = new PortugalVillasContext()) { List<EntityCommonField> theList = _db.EntityCommonFields.ToList(); return theList; } }
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 GetBookingExtraByID(long? ID) { PortugalVillasContext _db = new PortugalVillasContext(); BookingExtra bookingExtra = _db.BookingExtras .Where(x => x.BookingExtraID == ID) .First(); return bookingExtra; }
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; }
//gets town ID from property, gets regionID from townID public static PropertyRegion GetPropertyRegionByProperty(Property aProperty) { PortugalVillasContext _db = new PortugalVillasContext(); var propertyTown = _db.PropertyTowns.Where(x => x.PropertyTownID == aProperty.PropertyTownID).Select(x => x).FirstOrDefault(); var propertyRegion = _db.PropertyRegions.Where(x => x.PropertyRegionID == propertyTown.PropertyRegionID).FirstOrDefault(); return propertyRegion; }
///////////////////////////// //// STATIC METHODS ///////////////////////////// public static PropertyVacationType GetVacationTypeByProperty(Property aProperty) { PortugalVillasContext _db = new PortugalVillasContext(); PropertyVacationType aPropertyVacationType = _db.PropertyVacationTypes .Where(x => x.PropertyVacationTypeID == aProperty.PropertyVacationTypeID) .First(); return aPropertyVacationType; }
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; }
//get all the booking extras of a specific extra type - passed a BookingExtraTypeID public static List<BookingExtra> GetBookingExtrasOfType(long? BookingExtraTypeID) { List<BookingExtra> theList = new List<BookingExtra>(); PortugalVillasContext _db = new PortugalVillasContext(); theList = _db.BookingExtras.Where(x => x.BookingExtraTypeID == BookingExtraTypeID) .Where(x => x.TopLevelItem == true) .ToList(); return theList; }
//overload 1 public static int CountEntitiesForProperty(Property aProperty, long?aPropertyEntityID) { PortugalVillasContext _db = new PortugalVillasContext(); int count = 0; count = _db.PropertyEntities .Where(x => x.PropertyEntityTypeID == aPropertyEntityID) .Where(x => x.PropertyID == aProperty.PropertyID) .Select(x => x.PropertyEntityID).Count(); return(count); }
protected static List <Customer> GetCustomerByFirstName(string firstName) { //may return a list of customers with same first name PortugalVillasContext _db = new PortugalVillasContext(); List <Customer> customerList; customerList = (from customers in _db.Customers where customers.FirstName == firstName select customers).ToList(); return(customerList); }
public static BookingExtraSelection GetSingleBookingExtraSelection(long id) { using (PortugalVillasContext _db = new PortugalVillasContext()) { //get the booking extra BookingExtraSelection BookingExtra = _db.BookingExtraSelections.Include(x => x.BookingExtra).Where(x => x.BookingExtraSelectionID == id).FirstOrDefault(); return(BookingExtra); } }
//insert a booking private static bool CreateBooking(Booking aBooking) { PortugalVillasContext _db = new PortugalVillasContext(); _db.Bookings.Add(aBooking); if (_db.SaveChanges() > 0) { return(true); } ; return(false); }
public static long GetPropertyRegionIDByProperty(Property aProperty) { PortugalVillasContext _db = new PortugalVillasContext(); IQueryable <long> regionID = from towns in _db.PropertyTowns where towns.PropertyTownID == aProperty.PropertyTownID select towns.PropertyRegionID; // whereropertyID == aProperty.PropertyID) // .Select(x => x.PropertyTown); return(regionID.FirstOrDefault()); }
protected static List <Customer> GetCustomerByPostcode(string postcode) { //may return a list of customers with same last name PortugalVillasContext _db = new PortugalVillasContext(); List <Customer> customerList; //Clean up postcode within LINQ customerList = (from customers in _db.Customers where customers.FirstName.ToLower().TrimEnd().TrimStart().Replace(" ", "") == postcode.ToLower().TrimEnd().TrimStart().Replace(" ", "") select customers).ToList(); return(customerList); }
public void GetBookingExtraAttributesDescriptionsOnly() { if (this.BookingExtraAttributes.Count == 0) { // List<BookingExtraAttribute> theListOfAttributes = new List<BookingExtraAttribute>(); PortugalVillasContext _db = new PortugalVillasContext(); //assign to this instance's collection this.BookingExtraAttributes = _db.BookingExtraAttributes .Where(x => x.AttributeName == "Description") .Where(x => x.BookingExtraID == this.BookingExtraID).ToList(); } }
/// <summary> /// Helper method used in Booking Creation that returns the property price for any one night /// </summary> //public decimal GetPropertyPriceForANight(DateTime aDate) //{ // decimal priceForThatNight = 0.00M; // PortugalVillasContext _db = new PortugalVillasContext(); // //create a container with price, startdate, enddate List<dates> - which are all the dates between start and end date // //these are concrete dates, with the year taken from the passed in date and appended. // //cycle through every date until we find a match // //return the price associated with that date // //make a container class which takes a list of dates then calls this method - the container returns the overall price // // decimal thePrice = //} public bool CalculateBookingPricingForAPropertyBooking(PortugalVillasContext db) { BookingPrice = 0.00M; try { decimal?theCalculatedBookingPrice = 0.00M; if (this.StartDate == null || this.EndDate == null || this.BookingPRCReference == "") { throw new ArgumentNullException(); } //we need the property ID, let's get it if (this.PropertyID != 0 && this.PropertyID != null) { Property theProp = db.Properties.Where(x => x.PropertyID == this.PropertyID).First(); this.PropertyID = theProp.PropertyID; } //get a list of nights they have booked List <DateTime> BookingNIGHTS = GetListOfNIGHTSForThisBooking(); foreach (var night in BookingNIGHTS) { BookingDateRangeAndPriceCalculator calculator = new BookingDateRangeAndPriceCalculator(night, this.PropertyID); theCalculatedBookingPrice += calculator.ReturnPriceForDateOfBooking(); } this.BookingPrice = decimal.Round((decimal)theCalculatedBookingPrice, 2); return(true); //get the nightly pricing for each night they have booked by checking against propertyPRicing //add them all together //calculate all the breakage deposits (check what is executed in the DB already via defualts) } catch (Exception) { return(false); //ignore,you won't have a price } }
public static IEnumerable <PropertyTypeServicesChargeInstance> GetExtraTypeServicesChargeInstances() { using (var _db = new PortugalVillasContext()) { var extras = _db.PropertyTypeServices.Where(x => x.Property1OrExtraType2 == 2).ToList(); List <PropertyTypeServicesChargeInstance> instances = _db.PropertyTypeServicesChargeInstances.ToList(); List <PropertyTypeServicesChargeInstance> instancesToReturn = new List <PropertyTypeServicesChargeInstance>(); foreach (var propertyTypeService in extras) { instancesToReturn.AddRange(instances.Where(x => x.PropertyTypeServicesID == propertyTypeService.PropertyTypeServicesID) .ToList()); } return(instancesToReturn); } }
//get an individual booking by Booking Reference -- NEED TO TEST FOR EMPTY RESULT public static Booking GetBookingByRef(string bookingRef) { PortugalVillasContext _db = new PortugalVillasContext(); Booking theBooking = null; var aBooking = (from booking in _db.Bookings where booking.BookingPRCReference == bookingRef select booking); if (aBooking != null) { theBooking = (Booking)aBooking; return(theBooking); } return(theBooking); }
public static string GetPropertyRegionbyID(long propertyRegionID) { PortugalVillasContext _db = new PortugalVillasContext(); if (propertyRegionID != 0) { string theRegionName = _db.PropertyRegions .Find(propertyRegionID) .RegionName; return(theRegionName); } else { return("No region found"); } }
//return linklist of types public static LinkedList <PropertyVacationType> GetPropertyVacationTypes() { PortugalVillasContext _db = new PortugalVillasContext(); LinkedList <PropertyVacationType> vacationTypeList = new LinkedList <PropertyVacationType>(); var vType = (from vacType in _db.PropertyVacationTypes orderby vacType.PropertyVacationTypeID descending select vacType); foreach (var propertyVacationType in vType) { //add the latest key to the earliest element so every time you add a new one, it becomes the earliest, //ending up with the first being the first vacationTypeList.AddFirst(propertyVacationType); } return(vacationTypeList); }
/// <summary> /// Gets all Bookings / Extras and Sums Their Prices /// </summary> /// <returns></returns> public decimal CalculateTotalBookingPrice() { try { PortugalVillasContext _db = new PortugalVillasContext(); decimal?runningTotal = 0.00M; runningTotal += _db.Bookings.Where(x => x.BookingParentContainerID.Equals(this.BookingParentContainerID)).Sum(x => x.BookingPrice); runningTotal += _db.BookingExtraSelections.Where(x => x.BookingParentContainerID.Equals(this.BookingParentContainerID)).Sum(x => x.BESPrice); this.TotalBookingContainerPrice = runningTotal; return((decimal)runningTotal); } catch (Exception ex) { throw new Exception("There has been an exception in CalculateTotalBookingPrice"); } }
public static List <DateTime?> GetLastDayOfAllFutureConfirmedBookings(long propertyID) { using (var db = new PortugalVillasContext()) { var dates = db.Bookings .Where(x => x.Confirmed == true) .Where(x => x.Cancelled == false) .Where(x => x.PropertyID == propertyID) .ToList(); var lastdayeachBooking = new List <DateTime?>(); foreach (var date in dates) { lastdayeachBooking.Add(date.EndDate); } return(lastdayeachBooking); } }
public static List <Comment> GetRandomTopRatedComments() { try { PortugalVillasContext _db = new PortugalVillasContext(); List <Comment> theCommentsList = new List <Comment>(); return(theCommentsList = _db.Comments.Where(x => x.StarRating > 2) .Where(x => x.Approved == true).Take(10) .ToList()); } catch (Exception ex) { throw ex; } throw new Exception(); }
/////////////////////////////////////////// ////Static Methods for binding to Dropdown/other list types ////////////////////////////////////////// //get pool types public static List <string> GetSwimmingPoolTypes() { PortugalVillasContext _db = new PortugalVillasContext(); List <string> swimmingPoolTypeList = new List <string>(); var poolList = (from props in _db.Properties where props.SwimmingPoolType != null && props.SwimmingPoolType != "" select props.SwimmingPoolType).Distinct(); foreach (var poolType in poolList) { if (poolType != null && poolType != "") { swimmingPoolTypeList.Add(poolType); } else { swimmingPoolTypeList.Add("NULL was returned from GetSwimmingPoolTypes()"); } } return(swimmingPoolTypeList); }
/// <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; } }
internal void CalculateExtrasPriceForAPropertyBooking(Property property, Booking booking, PortugalVillasContext db) { var allTheServices = db.PropertyTypeServicesChargeInstances.Where(x => x.PropertyTypeID == property.PropertyTypeID).ToSafeReadOnlyCollection(); var weeks = booking.NumberOfNights / 7; if (weeks == 0) { weeks = 1; } //towels try { booking.TowelsPrice = (booking.NoOfTowelsRequested * allTheServices.First(x => x.PropertyTypeServicesID.Equals(5)).ServicePriceGBP) * weeks; } catch (Exception) { } //cleans try { booking.MidVactionCleaningPrice = booking.MidVactionCleaning * allTheServices.First(x => x.PropertyTypeServicesID.Equals(1)).ServicePriceGBP; } catch (Exception) { } //heating try { booking.HeatingPrice = booking.HeatingNoNights * allTheServices.First(x => x.PropertyTypeServicesID.Equals(3)).ServicePriceGBP; } catch (Exception) { } //cleaning laundry post visit try { booking.CleaningPostVisitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(4)).ServicePriceGBP; } catch (Exception) { } try { //swimming pool heating booking.SwimmingPoolHeatingPrice = booking.SwimmingPoolHeating * allTheServices.First(x => x.PropertyTypeServicesID.Equals(6)).ServicePriceGBP; } catch (Exception) { } try { //linen set booking.ExtraLininSetPrice = (booking.ExtraLininSet * allTheServices.First(x => x.PropertyTypeServicesID.Equals(7)).ServicePriceGBP); } catch (Exception) { } //add all unit prices try { booking.CleaningPostVisitUnitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(4)).ServicePriceGBP; booking.ExtraLininSetUnitPrice = (allTheServices.First(x => x.PropertyTypeServicesID.Equals(7)).ServicePriceGBP); booking.HeatingUnitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(3)).ServicePriceGBP; booking.MidVactionCleaningUnitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(1)).ServicePriceGBP; booking.SwimmingPoolHeatingUnitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(6)).ServicePriceGBP; booking.TowelsUnitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(5)).ServicePriceGBP; booking.FirewoodUnitPrice = allTheServices.First(x => x.PropertyTypeServicesID.Equals(16)).ServicePriceGBP; } catch (Exception) { } }
public static List <BookingAndRelatedTransactions> GetBookingsPaid(long AccountID, PortugalVillasContext db) { var bookingAndTrans = ReturnAllBookingsAndTransactions(AccountID, db); List <BookingAndRelatedTransactions> paidTrans = new List <BookingAndRelatedTransactions>(); foreach (var booking in bookingAndTrans) { var sumOfTransactions = booking.transactions.Sum(x => x.TransactionAmount); if (sumOfTransactions >= booking.booking.RemittanceAmount) { paidTrans.Add(booking); } } return(paidTrans); }
private static List <BookingAndRelatedTransactions> ReturnAllBookingsAndTransactions(long AccountID, PortugalVillasContext db) { var owner = db.PropertyOwnerAccounts.Where(x => x.AccountID == AccountID).First(); var props = db.Properties.Where(x => x.PropertyOwnerID == owner.PropertyOwnerID).ToList(); var bookings = new List <Booking>(); foreach (var property in props) { bookings.AddRange(db.Bookings.Where(booking => booking.PropertyID == property.PropertyID).Include(x => x.Property).ToList()); } var transactions = db.AccountTransactions.Where(x => x.AccountID == AccountID).Where(x => x.Voided != true); List <BookingAndRelatedTransactions> bookingAndTrans = new List <BookingAndRelatedTransactions>(); foreach (var booking in bookings) { bookingAndTrans.Add(new BookingAndRelatedTransactions { booking = booking, transactions = transactions.Where(x => x.BookingID == booking.BookingID).ToList() }); } return(bookingAndTrans); }
public static decimal CalculateBookingExtraAdditionalCostsAndAssignToThisBooking(BookingExtraSelection bookingExtraSelection, PortugalVillasContext _db) { /*Extra services * 8 = Detours * 9 = Child seats * 10 = extra luggage * 12 = Car rental child seats * */ var serviceChargeInstances = PropertyTypeServicesChargeInstance.GetExtraTypeServicesChargeInstances(); decimal additionalCost = 0.00M; switch (bookingExtraSelection.GetBookingExtraTypeIDFromBookingExtraSelection()) { //specialist only for cars // it's PER DAY case 1: { additionalCost += (bookingExtraSelection.NumberOfChildseats * serviceChargeInstances.First(x => x.PropertyTypeServicesID == 12).ServicePriceGBP) * bookingExtraSelection.NumberOfDays ?? 0.00M; break; } // it's EACH WAY case 2: { additionalCost += (bookingExtraSelection.NumberOfChildseats * serviceChargeInstances.First(x => x.PropertyTypeServicesID == 9).ServicePriceGBP) * 2 ?? 0.00M; break; } // it's EACH WAY case 3: { additionalCost += (bookingExtraSelection.NumberOfChildseats * serviceChargeInstances.First(x => x.PropertyTypeServicesID == 9).ServicePriceGBP) * 2 ?? 0.00M; break; } // it's EACH WAY case 4: { additionalCost += (bookingExtraSelection.NumberOfChildseats * serviceChargeInstances.First(x => x.PropertyTypeServicesID == 9).ServicePriceGBP) * 2 ?? 0.00M; break; } } //calcs across the board //detours // straight billing additionalCost += (bookingExtraSelection.Detours * serviceChargeInstances.First(x => x.PropertyTypeServicesID == 10).ServicePriceGBP) ?? 0.00M; //extra luggage // it's EACH WAY additionalCost += (bookingExtraSelection.PiecesOfLuggage * serviceChargeInstances.First(x => x.PropertyTypeServicesID == 8).ServicePriceGBP) * 2 ?? 0.00M; return((decimal)additionalCost); }
internal static decimal?GetBookingExtraTotalServicesPrice(BookingExtraSelection bookingExtraSelection, PortugalVillasContext db) { return(bookingExtraSelection.BESPrice + bookingExtraSelection.BESExtraServicesPrice); }