public EventCalendarDetailsData() { try { this.CreatedBy = CmsContext.currentWebPortalUser.FullName; } catch { } this.StartDateTime = DateTime.Now.AddDays(1); this.StartDateTime = StartDateTime.AddHours(-StartDateTime.Hour); this.StartDateTime = StartDateTime.AddMinutes(-StartDateTime.Minute); this.StartDateTime = StartDateTime.AddSeconds(-StartDateTime.Second); this.StartDateTime = StartDateTime.AddHours(CmsConfig.getConfigValue("EventCalendar.DefaultEventStartHour", 8)); this.EndDateTime = DateTime.Now.AddDays(1); this.EndDateTime = EndDateTime.AddHours(-EndDateTime.Hour); this.EndDateTime = EndDateTime.AddMinutes(-EndDateTime.Minute); this.EndDateTime = EndDateTime.AddSeconds(-EndDateTime.Second); this.EndDateTime = EndDateTime.AddHours(CmsConfig.getConfigValue("EventCalendar.DefaultEventEndHour", 17)); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var results = new List <ValidationResult>(); if (Status == default) { results.Add(new ValidationResult($"{nameof(Status)} is required", new[] { nameof(Status) })); } if (string.IsNullOrWhiteSpace(Name)) { results.Add(new ValidationResult($"{nameof(Name)} cannot be null, empty or consist of whitespace only", new[] { nameof(Name) })); } else if (Name.Length > 50) { results.Add(new ValidationResult($"{nameof(Name)} is greater than max length of 50", new[] { nameof(Name) })); } if (StartDateTime == default) { results.Add(new ValidationResult($"{nameof(StartDateTime)} is required", new[] { nameof(StartDateTime) })); } if (EndDateTime == default) { results.Add(new ValidationResult($"{nameof(EndDateTime)} is required", new[] { nameof(EndDateTime) })); } if (EndDateTime < StartDateTime) { results.Add(new ValidationResult($"{nameof(EndDateTime)} cannot be before {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) })); } else if (EndDateTime < StartDateTime.AddMinutes(10)) { results.Add(new ValidationResult($"{nameof(EndDateTime)} must be atleast 10 minutes after {nameof(StartDateTime)}", new[] { nameof(StartDateTime), nameof(EndDateTime) })); } return(results); }
// ReSharper disable once InconsistentNaming public List <AppliedKPI> GetVisibleKPIs() { // ReSharper disable InconsistentNaming var visibleKPIs = new List <AppliedKPI>(); // ReSharper restore InconsistentNaming var kpiRules = FewzionReport.Models.KPIs.GetKPIs(); foreach (var kpi in KPIs) { var rule = kpiRules.FirstOrDefault(x => x.ShortCode == kpi.ShortCode); if (rule == null || !rule.Visible) { continue; } var clone = (AppliedKPI)kpi.Clone(); if (rule.FieldType == "Time") { if (clone.Target != null && clone.Target > -1000000000) { if (rule.TransformMethod == "MinutesFromStart") { clone.TargetString = StartDateTime.AddMinutes((double)clone.Target).TimeOfDay.ToString(@"hh\:mm"); } if (rule.TransformMethod == "MinutesFromEnd") { clone.TargetString = EndDateTime.AddMinutes(0 - (double)clone.Target).TimeOfDay.ToString(@"hh\:mm"); } } if (clone.Actual != null && clone.Actual > -1000000000) { if (rule.TransformMethod == "MinutesFromStart") { clone.ActualString = StartDateTime.AddMinutes((double)clone.Actual).TimeOfDay.ToString(@"hh\:mm"); } if (rule.TransformMethod == "MinutesFromEnd") { clone.ActualString = EndDateTime.AddMinutes(0 - (double)clone.Actual).TimeOfDay.ToString(@"hh\:mm"); } } } else { var maxDecimals = rule.MaxDecimalDigits; if (clone.Actual != null && clone.Actual > -1000000000) { var actual = Math.Round((decimal)clone.Actual, maxDecimals); if (rule.FieldType == "Percentage") { clone.ActualString = actual + "%"; } else { clone.Actual = actual; } } if (clone.Target != null && clone.Target > -1000000000) { var target = Math.Round((decimal)clone.Target, maxDecimals); if (rule.FieldType == "Percentage") { clone.TargetString = target + "%"; } else { clone.Target = target; } } } visibleKPIs.Add(clone); } return(visibleKPIs); }
public async Task <AppointmentAvailabilityResponse> IsAvailableAsync() { DateTime nowDateTime = DateTime.UtcNow.AddHours(ShopHours.UTC_to_PST_Hours); if (StartDateTime < nowDateTime) { var response = new AppointmentAvailabilityResponse() { IsAvailable = false }; response.ValidationResults.Add(new ValidationResult() { Message = "That date and time is in the past." }); return(response); } StartDateTime = await roundingRules.RoundDateTimeAsync(StartDateTime); TimeSpan difference = nowDateTime - StartDateTime; // we need to adjust the rounding for any rounding to a few minutes in the past. while (StartDateTime < nowDateTime && difference < TimeSpan.FromMinutes(1)) { StartDateTime = await roundingRules.RoundDateTimeAsync(StartDateTime.AddMinutes(5)); } var shopResponse = await Shop.IsAvailableAsync(this); BarberAvailabilityResponse barberResponse = await RequestedBarber.IsAvailableAsync(this); if (RequestedBarber != barberResponse.Barber) { // this happens if the user requests "Anyone" RequestedBarber = barberResponse.Barber; } if (shopResponse.IsAvailable && barberResponse.IsAvailable) { return(new AppointmentAvailabilityResponse() { IsAvailable = true, SuggestedRequest = this }); } else if (shopResponse.IsAvailable && !barberResponse.IsAvailable) { // barber is not available // we could either suggest the next available barber's time // and we could find when the barber is available next AppointmentRequest suggestedRequest = await RequestedBarber.NextAvailableRequestAsync(this); var response = new AppointmentAvailabilityResponse() { IsAvailable = false, SuggestedRequest = suggestedRequest }; response.ValidationResults.AddRange(barberResponse.ValidationResults); return(response); } else { // shop is not available // show the hours for the week and suggest the next available appointment AppointmentRequest nextRequest = null; AppointmentAvailabilityResponse response = new AppointmentAvailabilityResponse() { IsAvailable = false }; if (!shopResponse.IsAvailable) { nextRequest = new AppointmentRequest(Shop); nextRequest.CopyFrom(this); if (nextRequest.StartDateTime < nowDateTime) { int attempts = 0; while (!await Shop.CanAcceptCustomersAsync(nextRequest.StartDateTime) && attempts < 5) { nextRequest.StartDateTime = nextRequest.StartDateTime.AddDays(1); nextRequest.StartDateTime = await Shop.OpeningDateTimeAsync(nextRequest.StartDateTime); attempts++; } } nextRequest = await Shop.NextAvailableBarberAsync(nextRequest); response.ValidationResults.AddRange(shopResponse.ValidationResults); } else if (!barberResponse.IsAvailable) { nextRequest = new AppointmentRequest(Shop); nextRequest.CopyFrom(this); if (nextRequest.StartDateTime < nowDateTime) { int attempts = 0; nextRequest.StartDateTime = nextRequest.StartDateTime.AddDays(1); await RequestedBarber.Hours.LoadAsync(RequestedBarber, nextRequest.StartDateTime); while (!await Shop.IsOpenAsync(nextRequest.StartDateTime) && !RequestedBarber.Hours.IsWithinHours(nextRequest.StartDateTime) && attempts < 5) { nextRequest.StartDateTime = nextRequest.StartDateTime.AddDays(1); nextRequest.StartDateTime = await Shop.OpeningDateTimeAsync(nextRequest.StartDateTime); attempts++; } } nextRequest = await RequestedBarber.NextAvailableRequestAsync(nextRequest); response.ValidationResults.AddRange(barberResponse.ValidationResults); } response.SuggestedRequest = nextRequest; return(response); } }