Exemplo n.º 1
0
        public async Task <IActionResult> Add()
        {
            var form = new CreateOverheadsForm();

            await InitLotsList(form);

            return(View(form));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Add(CreateOverheadsForm form)
        {
            if (!ModelState.IsValid)
            {
                await InitLotsList(form);

                return(View(form));
            }

            var res = await _overheads.Create(form);

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

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

            return(View(form));
        }
Exemplo n.º 3
0
        public async Task <HbResult <HbOverhead> > Create(CreateOverheadsForm form)
        {
            var lot = await _dc.Lots.FirstOrDefaultAsync(u => !u.IsDeleted && u.Id == form.LotId);

            if (lot == null)
            {
                return(new HbResult <HbOverhead>(ErrorCodes.LotNotFound));
            }

            var res = _dc.Overheads.Add(new HbOverheads
            {
                Amount       = form.Amount,
                Comment      = form.Comment,
                LotId        = form.LotId,
                OverheadDate = form.OverheadDate
            });

            await _dc.SaveChangesAsync();

            await _lotsUnit.RecalculateLot(form.LotId);

            return(new HbResult <HbOverhead>(_mapper.Map <HbOverhead>(res.Entity)));
        }
Exemplo n.º 4
0
 private async Task InitLotsList(CreateOverheadsForm form)
 {
     form.Lots = await _lots.GetList(new PagedLotsForm());
 }