Пример #1
0
        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));
        }
Пример #2
0
        public async Task <ActionResult> Edit(WebUser user, PayingItemEditModel pItem)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (pItem.PricesAndIdsInItem == null)
                    {
                        await _payingItemService.UpdateAsync(pItem.PayingItem);
                    }
                    else
                    {
                        pItem.PayingItem.Summ = GetSummForPayingItem(pItem);
                        _payingItemHelper.CreateCommentWhileEdit(pItem);
                        await _payingItemService.UpdateAsync(pItem.PayingItem);

                        if (PayingItemEditModel.OldCategoryId != pItem.PayingItem.CategoryID)
                        {
                            await _pItemProductHelper.CreatePayingItemProduct(pItem);
                        }
                        else
                        {
                            await _pItemProductHelper.UpdatePayingItemProduct(pItem);
                        }
                    }
                }
                catch (ServiceException 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);
                }
                return(RedirectToAction("List"));
            }
            await FillViewBag(user, await GetTypeOfFlowId(pItem.PayingItem));

            return(PartialView(pItem));
        }
        public async Task UpdateAsync(PayingItem item)
        {
            var typeOfFlowId  = (await _categoryService.GetItemAsync(item.CategoryID)).TypeOfFlowID;
            var categories    = (await _typeOfFlowService.GetCategoriesAsync(typeOfFlowId)).Where(x => x.UserId == item.UserId);
            var oldCategoryId = await GetCategoryIdAsync(categories, item.ItemID);

            var oldCategory = await _categoryService.GetItemAsync(oldCategoryId);

            var oldPayingItem = oldCategory.PayingItem.FirstOrDefault(x => x.ItemID == item.ItemID);
            var newItem       = new PayingItem()
            {
                Category  = oldCategory,
                AccountID = item.AccountID,
                Summ      = item.Summ
            };
            await _payingItemService.UpdateAsync(item);

            await _serviceTrigger.Update(oldPayingItem, newItem);
        }