private static int WeekdayDifference(DateTime StartDate, DateTime EndDate, IHolidayRepository holidayRepository) { DateTime thisDate = StartDate; int weekDays = 0; while (thisDate <= EndDate) { if (thisDate.DayOfWeek != DayOfWeek.Saturday && thisDate.DayOfWeek != DayOfWeek.Sunday) { if (!holidayRepository.GetAllHolidays().Any(d => d.DateOfHoliday == thisDate)) { weekDays++; } } if (EndDate >= StartDate) { thisDate = thisDate.AddDays(1); } else { thisDate = thisDate.AddDays(-1); } } return(weekDays); }
public List <PriceComponent> CalculatePrice(PlaceInRun placeInRun) { var components = new List <PriceComponent>(); var holidayList = _holidayRepository.GetAllHolidays(); var run = _runRepository.GetRunDetails(placeInRun.RunId); var train = _trainRepository.GetTrainDetails(run.TrainId); var place = train.Carriages .Select(car => car.Places.SingleOrDefault(pl => pl.Number == placeInRun.Number && car.Number == placeInRun.CarriageNumber)) .SingleOrDefault(x => x != null); var placeComponent = new PriceComponent() { Name = "Main price" }; placeComponent.Value = place.Carriage.DefaultPrice * place.PriceMultiplier; components.Add(placeComponent); if (run.Date.DayOfWeek == (DayOfWeek)0 || run.Date.DayOfWeek == (DayOfWeek)6) { var cashDeskComponent = new PriceComponent() { Name = "Holiday tax", Value = placeComponent.Value * 1.25m }; components.Add(cashDeskComponent); } for (int i = 1; i < holidayList.Count; i++) { if (run.Date.Day == holidayList[i].Day && run.Date.Month == holidayList[i].Month) { var cashDeskComponent = new PriceComponent() { Name = "Holiday tax", Value = placeComponent.Value * 1.25m }; components.Add(cashDeskComponent); break; } } if (placeComponent.Value > 30) { var cashDeskComponent = new PriceComponent() { Name = "Cash desk service tax", Value = placeComponent.Value * 0.2m }; components.Add(cashDeskComponent); } return(components); }
public async Task <IActionResult> Index() { HolidayIndexViewModel model = new HolidayIndexViewModel { holidays = holidayRepository.GetAllHolidays() }; if (!model.holidays.Any()) { await noHolidaysAlert(); } return(View(model)); }