public async Task <ActionResult> Index(PriceHedgePage currentPage, string pArea, string period, string priskey, string grain, string pItemId, string pItem, string agreement, string pid, string agreementId = "") { var supplier = UserManager.GetActiveCustomer(HttpContext); if (SiteUser == null || supplier == null) { ViewData["NotLoggedIn"] = true; return(View("~/Views/AppPages/PriceHedgePage/PriceHedge.cshtml", new PriceHedgeViewModel(currentPage))); } if (string.IsNullOrEmpty(pArea) || string.IsNullOrEmpty(period) || string.IsNullOrEmpty(priskey) || string.IsNullOrEmpty(pid)) { ViewData["IncorrectParams"] = true; return(View("~/Views/AppPages/PriceHedgePage/PriceHedge.cshtml", new PriceHedgeViewModel(currentPage))); } agreement = string.IsNullOrWhiteSpace(agreement) ? AgreementType.SportAndForwardAvtal : agreement; var purchaseDateObject = GenerateFromDatePeriod(period); int agrId; int.TryParse(agreementId, out agrId); var model = new PriceHedgeViewModel(currentPage) { PriceLow = SettingPage.PurchasePriceLow, CommitQuantityMin = 12, //Need to get from service instead of TimeWithClock = $"{DateTime.Now:dd MMM yyyy} klockan {DateTime.Now:HH:mm}", SelectedPriceArea = (await _agreementRepository.GetSelectedPriceArea(supplier.CustomerNo)), AgreementTypeName = GetAgreementTypeName(priskey, agreement), AgreementHeading = GetAgreementHeading(agreement), ProductItemName = pItem, DeliveryPeriod = $"{purchaseDateObject.ValidFrom:yyyy-MM-dd} - {purchaseDateObject.ValidTo:yyyy-MM-dd}", RegisterDate = $"{DateTime.Now:yyyy-MM-dd}", Customer = (await _agreementRepository.GetCustomerAsync(supplier.CustomerNo)) ?? new Customer(), PurchaseAgreementUrl = string.IsNullOrEmpty(pid) ? "#" : GetPurchaseAgreementPageUrl(pid), PriceHedgeForm = new PriceHedgeFormModel { PriceArea = int.Parse(pArea), ProductItemId = pItemId, GrainType = grain, PriceType = priskey, PriceWatchEndDate = DateTime.Now, HarvestYear = purchaseDateObject.HarvestYear, ValidTo = purchaseDateObject.ValidTo, ValidFrom = purchaseDateObject.ValidFrom, AgreementType = string.IsNullOrEmpty(agreement) ? AgreementType.SportAndForwardAvtal : agreement, AgreementId = agrId }, User = SiteUser, }; return(View("~/Views/AppPages/PriceHedgePage/PriceHedge.cshtml", model)); }
private async Task <PurchasingAgreementViewModel> CreateViewModel(PurchasingAgreementPage currentPage, string customerNo, string productionItemId = "", string grainTypeId = "", string agreementId = "") { var viewModel = new PurchasingAgreementViewModel(currentPage); Dictionary <string, string> periods = new Dictionary <string, string>(); var selectedPriceArea = await _agreementRepository.GetSelectedPriceArea(customerNo); var priceAreaId = selectedPriceArea != null ? selectedPriceArea.PriceAreaId : string.Empty; if (currentPage.AgreementType == AgreementType.PrissakringDepaavtal) { var storageAgreements = await _agreementRepository.GetStorageAgreementsForPriceProtectionAsync(customerNo); storageAgreements = storageAgreements ?? new StorageAgreement[0]; var selectedStorageAgreement = storageAgreements.Any() && !string.IsNullOrEmpty(agreementId) ? storageAgreements.FirstOrDefault(x => x.AgreementId == agreementId) : null; periods = ConvertPeriodToMonthRange(await _agreementRepository.GetPeriodsPriceProtectingStorageAgreementAsync(priceAreaId, productionItemId, grainTypeId)); viewModel.StorageAgreements = storageAgreements.ToList(); viewModel.SelectedAgreement = selectedStorageAgreement; } else if (currentPage.AgreementType == AgreementType.SportAndForwardAvtal) { var products = _agreementRepository.GetProductsSpotAndForwardAgreement(priceAreaId); var grainTypes = !string.IsNullOrEmpty(productionItemId) ? await _agreementRepository.GetGrainTypesSpotAndForwardAgreementAsync(productionItemId, priceAreaId) : new Product[0]; periods = ConvertPeriodToMonthRange(await _agreementRepository.GetPeriodsSpotAndForwardAgreementAsync(priceAreaId)); viewModel.Products = products; viewModel.GrainTypes = grainTypes; } else if (currentPage.AgreementType == AgreementType.Poolavtal || currentPage.AgreementType == AgreementType.Depaavtal) { if (currentPage.AgreementType == AgreementType.Poolavtal) { viewModel.Header = "Teckna Poolavtal"; viewModel.Products = await _agreementRepository.GetProductsPoolAgreementAsync(priceAreaId); viewModel.ModesOfDelivery = await _agreementRepository.GetModesOfDeliveryPoolAgreementAsync(); periods = ConvertPeriodToMonthRange(await _agreementRepository.GetPeriodsPoolAgreementAsync(priceAreaId)); } else if (currentPage.AgreementType == AgreementType.Depaavtal) { viewModel.Header = "Teckna depåavtal"; viewModel.Products = await _agreementRepository.GetProductsStorageAgreementAsync(priceAreaId); viewModel.ModesOfDelivery = await _agreementRepository.GetModesOfDeliveryStorageAgreementAsync(); periods = ConvertPeriodToMonthRange(await _agreementRepository.GetPeriodsStorageAgreementAsync(priceAreaId)); viewModel.DepaPeriod = GetDepaPeriod(periods.FirstOrDefault()); } } viewModel.SelectedPriceArea = selectedPriceArea; viewModel.Periods = periods; viewModel.FormModel = new PurchasingAgreementFormModel(); viewModel.ReferencePrice = GetReferencePrice(); viewModel.MinPrice = SettingPage.PurchasePriceLow; viewModel.CommitQuantityMin = 12; return(viewModel); }