public ProductOption GetProductOption(Guid productOptionId) { var producEntity = _productOptionRepository.GetProductOption(productOptionId); var mapper = GetMapper <ProductOption, Data.Entities.ProductOption>(); return(mapper.ToModel(producEntity)); }
public async Task <IActionResult> GetProductOption(int id) { ProductOption productOption = await productOptionRepository.GetProductOption(id); return(Ok(productOption.Map())); }
public async Task <IActionResult> Add([FromBody] TariffDto tariffDto) { Tariff tariff = new Tariff(tariffDto.Name, (PaymentType)tariffDto.PaymentType); if (tariffDto.TestPeriod.Value != 0) { TariffTestPeriod testPeriod = new TariffTestPeriod(tariffDto.TestPeriod.Value, (TariffTestPeriodUnit)tariffDto.TestPeriod.Unit); tariff.AddTestPeriod(testPeriod); } tariff.SetArchive(tariffDto.IsArchived); tariff.SetAccountingTariffId(tariffDto.AccountingName); tariff.SetAwaitingPaymentStrategy(tariffDto.AwaitingPaymentStrategy); tariff.SetSettingsPresetId(tariffDto.SettingsPresetId); tariff.SetTermsOfUseId(tariffDto.TermsOfUseId); tariff.SetIsAcceptanceRequired(tariffDto.IsAcceptanceRequired); tariff.SetIsGradualFinishAvailable(tariffDto.IsGradualFinishAvailable); //add price foreach (var tariffPrice in tariffDto.Prices) { Price price = new Price(tariffPrice.Price.Value, tariffPrice.Price.Currency); ProlongationPeriod period = new ProlongationPeriod(tariffPrice.Period.Value, (PeriodUnit)tariffPrice.Period.periodUnit); tariff.AddPriceItem(price, period); } foreach (var advancePrice in tariffDto.AdvancePrices) { Price price = new Price(advancePrice.Price.Value, advancePrice.Price.Currency); ProlongationPeriod period = new ProlongationPeriod(advancePrice.Period.Value, (PeriodUnit)advancePrice.Period.periodUnit); tariff.AddAdvancePriceItem(price, period); } //add included product foreach (var includedProduct in tariffDto.IncludedProducts) { Product product = await productRepository.GetProduct(includedProduct.ProductId); tariff.AddProduct(product, includedProduct.RelativeWeight); } //add product option foreach (var includedProductOption in tariffDto.IncludedProductOptions) { ProductOption productOption = await productOptionRepository.GetProductOption(includedProductOption.ProductOptionId); tariff.AddProductOption(productOption, includedProductOption.Quantity); } //add contractKindBindings foreach (var contractKindBinding in tariffDto.ContractKindBindings) { ContractKind contractkind = await contractKindRepository.GetContractKind(contractKindBinding.ContractKindId); tariff.AddAvailableContractKind(contractkind); } await tariffRepository.Add(tariff); await unitOfWork.SaveEntitiesAsync(); return(Ok()); }