public async Task <PayingItem> UpdatePayingItemFromViewModel(PayingItemEditModel model) { if (model is null) { throw new ArgumentNullException(nameof(model)); } var sum = GetSumOfTheProducts(model); var payingItem = await _payingItemService.GetItemAsync(model.PayingItem.ItemID).ConfigureAwait(false); payingItem.Summ = sum; var comment = CreateCommentForPayingItem(model); payingItem.Comment = comment; payingItem.CategoryID = model.PayingItem.CategoryID; payingItem.AccountID = model.PayingItem.AccountID; payingItem.Date = model.PayingItem.Date; payingItem.PayingItemProducts.Clear(); if (model.ProductsInItem == null && model.ProductsNotInItem == null) { await _payingItemService.UpdateAsync(payingItem); return(payingItem); } return(await CreatePayingItemProduct(model, payingItem).ConfigureAwait(false)); }
public async Task <PayingItemEditModel> CreateViewModel(int payingItemId) { try { var payingItem = await _payingItemService.GetItemAsync(payingItemId); if (payingItem == null) { return(null); } var model = new PayingItemEditModel() { PayingItem = payingItem, ProductsInItem = new List <Product>(), ProductsNotInItem = new List <Product>() }; var productsInItem = payingItem.PayingItemProducts .Select(x => new Product() { Price = x.Price, ProductID = x.Product.ProductID, Description = x.Product.Description, ProductName = x.Product.ProductName, UserID = x.Product.UserID }) .ToList(); var productsByCategory = payingItem.Category.Products.ToList(); if (productsInItem.Count != 0) { model.ProductsInItem = productsInItem; model.ProductsNotInItem = productsByCategory.Except(productsInItem, new ProductEqualityComparer()).ToList(); } else { model.ProductsNotInItem = productsByCategory; } return(model); } catch (ServiceException e) { throw new WebUiException( $"Ошибка в типе {nameof(PayingItemEditViewModelCreator)} в методе {nameof(CreateViewModel)}", e); } catch (Exception e) { throw new WebUiException( $"Ошибка в типе {nameof(PayingItemEditViewModelCreator)} в методе {nameof(CreateViewModel)}", e); } }
public async Task <ActionResult> Edit(WebUser user, int typeOfFlowId, int id) { await FillViewBag(user, typeOfFlowId); try { var pItem = await _payingItemService.GetItemAsync(id); if (pItem == null) { return(RedirectToAction("ListAjax", 1)); } var pItemEditModel = new PayingItemEditModel() { PayingItem = pItem, PayingItemProducts = new List <PaiyngItemProduct>() }; PayingItemEditModel.OldCategoryId = pItem.CategoryID; if (!CheckForSubCategories(pItem)) { return(PartialView(pItemEditModel)); } _pItemProductHelper.FillPayingItemEditModel(pItemEditModel, id); return(PartialView(pItemEditModel)); } catch (ServiceException e) { throw new WebUiException( $"Ошибка в контроллере {nameof(PayingItemController)} в методе {nameof(Edit)}", e); } catch (WebUiException e) { throw new WebUiException( $"Ошибка в контроллере {nameof(PayingItemController)} в методе {nameof(Edit)}", e); } catch (WebUiHelperException e) { throw new WebUiException( $"Ошибка в контроллере {nameof(PayingItemController)} в методе {nameof(Edit)}", e); } catch (Exception e) { throw new WebUiException( $"Ошибка в контроллере {nameof(PayingItemController)} в методе {nameof(Edit)}", e); } }
public async Task <PayingItem> GetItemAsync(int id) { return(await _payingItemService.GetItemAsync(id)); }