private async Task <AgreementResponse> SaveStorageAgreementAgreement(PriceHedgeFormModel formModel, Customer customer) { var storageAgreement = new StorageAgreement() { //AgreementId = CustomerId = customer.CustomerId, GrainType = formModel.GrainType, HarvestYear = formModel.HarvestYear, ModeOfDelivery = formModel.DeliveryMode, PriceArea = formModel.PriceArea, ProductItemId = formModel.ProductItemId, Quantity = formModel.CommitQuantity, ValidFrom = formModel.ValidFrom, ValidTo = formModel.ValidTo, }; return(await _agreementRepository.SaveStorageAgreementAsync(storageAgreement)); }
private async Task <AgreementResponse> SaveDepaAgreement(PurchasingAgreementFormModel formModel, CustomerBasicInfo customer) { var purchasePeriod = GenerateFromDatePeriod(formModel.AgreementPeriod); var storageAgreement = new StorageAgreement() { CustomerId = customer.CustomerNo, GrainType = formModel.GrainType, HarvestYear = purchasePeriod.HarvestYear, ModeOfDelivery = formModel.DeliveryMode, PriceArea = formModel.PriceArea, ProductItemId = formModel.ProductItemId, Quantity = formModel.CommitQuantity, ValidFrom = purchasePeriod.ValidFrom, ValidTo = purchasePeriod.ValidTo, }; return(await _agreementRepository.SaveStorageAgreementAsync(storageAgreement)); }
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); }
//public async Task<PricePeriod[]> GetPricePeriodsForPriceProtectingStorageAgreementAsync(string areaId, // string productItemId, string grainType) // => // await // _service.GetPricePeriodsForPriceProtectingStorageAgreementAsync(areaId, productItemId, grainType, // Ticket); public async Task <AgreementResponse> SaveStorageAgreementAsync(StorageAgreement agreement) => await _service.SaveStorageAgreementAsync(agreement, Ticket);