Пример #1
0
        public static ModelWrapper Calculate(PenaltyCalculationInModel model)
        {
            var result = new ModelWrapper();

            try
            {
                var cultureInfo = new CultureInfo(model.CultureCode);

                var businessDaysCount = CalculateBusinessDays(model);

                var totalLatency = businessDaysCount > Daylimit ? businessDaysCount - Daylimit : 0;

                var totalPenalty = model.Amount * totalLatency;


                var resultModel = new PenaltyCalculationResultOutModel()
                {
                    TotalDays    = businessDaysCount.ToString(cultureInfo),
                    TotalPenalty = totalPenalty.ToString("C", cultureInfo)
                };

                result.Result = resultModel;
            }
            catch (Exception)
            {
                result.IsSuccess = false;
                result.Message   = "An error occured. Please try again.";
            }
            return(result);
        }
Пример #2
0
        private static int CalculateBusinessDays(PenaltyCalculationInModel model)
        {
            var cultureInfo = new CultureInfo(model.CultureCode);

            var checkOutDate = Convert.ToDateTime(model.CheckOutDate, cultureInfo);
            var returnDate   = Convert.ToDateTime(model.ReturnDate, cultureInfo);

            var totalDays = GetDateRange(checkOutDate, returnDate);

            var daysWithoutWeekends = ExcludeWeekendDays(totalDays, model.WeekendDays);

            var daysWithoutHolidays = ExcludeHolidays(daysWithoutWeekends, model.Holidays);

            return(daysWithoutHolidays.Count());
        }
Пример #3
0
        public JsonResult GetResult(PenaltyCalculationInModel data)
        {
            var model = new PenaltyCalculationInModel();

            var country = ctx.Countries.FirstOrDefault(a => a.Id.Equals(data.CountryId));

            if (country != null)
            {
                model.CultureCode  = country.CultureCode;
                model.CheckOutDate = data.CheckOutDate;
                model.ReturnDate   = data.ReturnDate;
                model.Holidays     = country.Holidays.Select(a => a.HolidayDate).ToList();
                model.Amount       = country.PenaltyAmount;
                model.WeekendDays  = country.WeekendDays.Select(a => a.DayOfWeek).ToList();
            }

            var result = Facilities.Facilities.Calculate(model);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }