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)); }
private async Task <PurchasingAgreementViewModel> CreatePurchasingAgreementViewModel(PurchasingAgreementPage currentPage, string customerNo, string priceAreaId = "", string productionItemId = "", string grainTypeId = "", string agreementId = "") { PricePeriod[] pricePeriods = null; var result = new PurchasingAgreementViewModel(currentPage); //#if DEBUG // customerNo = "1000000"; //#endif if (currentPage.AgreementType == AgreementType.PrissakringDepaavtal) { var storageAgreements = await _agreementRepository.GetStorageAgreementsForPriceProtectionAsync(customerNo); storageAgreements = storageAgreements ?? new StorageAgreement[0]; StorageAgreement selectedAgreement = null; if (storageAgreements.Any()) { selectedAgreement = string.IsNullOrEmpty(agreementId) ? storageAgreements.FirstOrDefault() : storageAgreements.FirstOrDefault(x => x.AgreementId == agreementId); result.SelectedAgreement = selectedAgreement; } if (!string.IsNullOrEmpty(priceAreaId) || !string.IsNullOrEmpty(productionItemId)) { #if DEBUG priceAreaId = "1"; productionItemId = "100160"; grainTypeId = "BRONS"; #endif pricePeriods = await GetPricePeriods(customerNo, priceAreaId, currentPage.AgreementType, productionItemId, grainTypeId); } else { result.StorageAgreements = storageAgreements.ToList(); if (selectedAgreement != null) { pricePeriods = await GetPricePeriods(customerNo, selectedAgreement.PriceArea.ToString(), currentPage.AgreementType, selectedAgreement.ProductItemId, selectedAgreement.GrainType); } } pricePeriods = pricePeriods ?? await Task.FromResult(new PricePeriod[0]); } else { var priceAreas = await _agreementRepository.GetPriceAreasAsync(customerNo); priceAreas = priceAreas ?? await Task.FromResult(new PriceArea[0]); var selectedPriceArea = priceAreas.FirstOrDefault(x => x.FavoritePriceAreaId) ?? priceAreas.FirstOrDefault(); pricePeriods = await GetPricePeriods(customerNo, selectedPriceArea?.PriceAreaId, currentPage.AgreementType); pricePeriods = pricePeriods ?? await Task.FromResult(new PricePeriod[0]); var productCategories = pricePeriods.Where(x => !string.IsNullOrEmpty(x.ProductItemHierarchy)) .GroupBy(x => x.ProductItemHierarchy) .Select(x => new ProductItemCategory() { ID = Guid.NewGuid().ToString(), Hierarchy = x.Key, ProductItems = x.ToList() }).ToList(); result.SelectedPriceArea = selectedPriceArea; result.PriceAreas = priceAreas.ToList(); result.ProductCategories = productCategories.ToList(); } result.PricePeriods = GetPricePeriodHeader(pricePeriods.FirstOrDefault(), currentPage.AgreementType); return(result); }