public async Task CreatePayingItemProduct(PayingItemEditModel pItem) { try { var paiyngItemProducts = _pItemProductService.GetList() .Where(x => x.PayingItemID == pItem.PayingItem.ItemID); foreach (var item in paiyngItemProducts) { await _pItemProductService.DeleteAsync(item.ItemID); } await _pItemProductService.SaveAsync(); foreach (var item in pItem.PricesAndIdsInItem) { if (item.Id != 0) { var pItemProd = new PaiyngItemProduct() { PayingItemID = pItem.PayingItem.ItemID, Summ = item.Price, ProductID = item.Id }; await _pItemProductService.CreateAsync(pItemProd); } } await _pItemProductService.SaveAsync(); } catch (ServiceException e) { throw new WebUiHelperException( $"Ошибка в типе {nameof(PayingItemProductHelper)} в методе {nameof(CreatePayingItemProduct)}", e); } }
public async Task CreatePayingItemProduct(PayingItemModel pItem) { try { foreach (var item in pItem.Products) { if (item.ProductID != 0) { var pItemProd = new PaiyngItemProduct() { PayingItemID = pItem.PayingItem.ItemID, Summ = item.Price, ProductID = item.ProductID }; await _pItemProductService.CreateAsync(pItemProd); await _pItemProductService.SaveAsync(); } } } catch (ServiceException e) { throw new WebUiHelperException( $"Ошибка в типе {nameof(PayingItemProductHelper)} в методе {nameof(CreatePayingItemProduct)}", e); } }
public async Task UpdateAsync(PaiyngItemProduct item) { try { await _pItemRepository.UpdateAsync(item); } catch (DomainModelsException e) { throw new ServiceException($"Ошибка в сервисе {nameof(PayingItemProductService)} в методе {nameof(UpdateAsync)} при обращении к БД", e); } }
public async Task UpdatePayingItemProduct(PayingItemEditModel pItem) { try { foreach (var item in pItem.PricesAndIdsInItem) { if (item.Id != 0) { var itemToUpdate = await _pItemProductService.GetItemAsync(item.PayingItemProductId); if (itemToUpdate != null) { itemToUpdate.Summ = item.Price; await _pItemProductService.UpdateAsync(itemToUpdate); } } if (item.Id == 0 && item.Price != 0) { await _pItemProductService.DeleteAsync(item.PayingItemProductId); } } await _pItemProductService.SaveAsync(); if (pItem.PricesAndIdsNotInItem != null) { foreach (var item in pItem.PricesAndIdsNotInItem) { if (item.Id != 0) { var payingItemProduct = new PaiyngItemProduct() { PayingItemID = pItem.PayingItem.ItemID, Summ = item.Price, ProductID = item.Id }; await _pItemProductService.CreateAsync(payingItemProduct); } } await _pItemProductService.SaveAsync(); } } catch (ServiceException e) { throw new WebUiHelperException( $"Ошибка в типе {nameof(PayingItemProductHelper)} в методе {nameof(UpdatePayingItemProduct)}", e); } }