public async Task <ActionResult> Index(PriceGrainPage currentPage) { var model = new PriceGrainPageViewModel(currentPage); var supplier = _usersManagementService.GetActiveCustomer(HttpContext); if (supplier == null) { return(View("~/Views/AppPages/PriceGrain/Index.cshtml", model)); } var resultPriceAreas = await _agreementRepository.GetPriceAreasAsync(); if (resultPriceAreas == null || resultPriceAreas.Length == 0) { return(View("~/Views/AppPages/PriceGrain/Index.cshtml", model)); } model.PriceAreaList = resultPriceAreas.ToList(); var resultPricePeriod = await _agreementRepository.GetPricePeriodsGrainPriceAsync(resultPriceAreas[0].PriceAreaId); if (resultPricePeriod?.Length > 0) { DateTime parsedDate; var parsedDateStr = string.Empty; if (DateTime.TryParse(resultPricePeriod[0].PriceType, out parsedDate)) { parsedDateStr = parsedDate.ToString("yyyy-MM-dd"); } resultPricePeriod[0].PriceType = parsedDateStr; model.PricePeriodFirst = resultPricePeriod.ToList(); } else { model.PricePeriodFirst = new List <PricePeriod>(); } return(View("~/Views/AppPages/PriceGrain/Index.cshtml", model)); }