private void SetAllowPaymentPeriodSetting(HealthwiseCustomerListItemModel model, int hwMaxPeriod) { foreach (var period in model.Periods) { period.AllowPayment = !period.PaidDate.HasValue && period.OrdersCount >= hwMaxPeriod; } }
public async Task <Result <HealthwiseCustomerListItemModel> > GetHealthwisePeriod(int id) { var item = await _healthwiseService.GetVHealthwisePeriodAsync(id); HealthwiseCustomerListItemModel toReturn; if (item != null) { var hwMaxPeriod = _appSettings.HealthwisePeriodMaxItemsCount; toReturn = new HealthwiseCustomerListItemModel(new List <VHealthwisePeriod>() { item }); SetAllowPaymentPeriodSetting(toReturn, hwMaxPeriod); } else { toReturn = new HealthwiseCustomerListItemModel(null); } return(toReturn); }
public async Task <Result <ICollection <HealthwiseCustomerListItemModel> > > GetHealthwiseCustomersWithPeriods( [FromBody] VHealthwisePeriodFilter filter) { var toReturn = new List <HealthwiseCustomerListItemModel>(); var items = await _healthwiseService.GetVHealthwisePeriodsAsync(filter); var periodGroups = items.GroupBy(p => p.IdCustomer).Select(p => new { IdCustomer = p.Key, Periods = p.ToList() }).ToList(); var hwMaxPeriod = _appSettings.HealthwisePeriodMaxItemsCount; foreach (var periodGroup in periodGroups) { var item = new HealthwiseCustomerListItemModel(periodGroup.Periods); SetAllowPaymentPeriodSetting(item, hwMaxPeriod); toReturn.Add(item); } return(toReturn); }