Esempio n. 1
0
        public async Task <HbResult <HbPurchase> > UpdatePurchase(UpdatePurchaseForm form)
        {
            var purchase = await _dc.Purchases.FirstOrDefaultAsync(u => u.Id == form.Id && !u.IsDeleted);

            if (purchase == null)
            {
                return(new HbResult <HbPurchase>(ErrorCodes.PurchaseNotFound));
            }

            var lotExist = await _dc.Lots.AnyAsync(u => !u.IsDeleted && u.Id == form.LotId);

            if (!lotExist)
            {
                return(new HbResult <HbPurchase>(ErrorCodes.LotNotFound));
            }

            purchase.Address      = form.Address;
            purchase.Amount       = form.Amount;
            purchase.Count        = form.Count;
            purchase.LotId        = form.LotId;
            purchase.PurchaseDate = form.PurchaseDate;

            await _dc.SaveChangesAsync();

            await _lotsUnit.RecalculateLot(purchase.LotId);

            return(new HbResult <HbPurchase>(_mapper.Map <HbPurchase>(purchase)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(UpdatePurchaseForm form)
        {
            if (!ModelState.IsValid)
            {
                await InitLotsList(form);

                return(View(form));
            }

            var res = await _purchase.UpdatePurchase(form);

            if (res.IsCorrect)
            {
                return(RedirectToAction(nameof(List)));
            }

            ViewData[ViewDataKeys.ErrorMessage] = res.ErrorMessage;
            await InitLotsList(form);

            return(View(form));
        }