Example #1
0
        public async Task <IActionResult> Add(CreateLotForm form)
        {
            if (!ModelState.IsValid)
            {
                return(View(form));
            }

            var res = await _lots.Create(form);

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

            ViewData[ViewDataKeys.ErrorMessage] = res.ErrorMessage;
            return(View(form));
        }
Example #2
0
        public async Task <HbResult <HbLot> > Create(CreateLotForm form)
        {
            var exist = await _dc.Lots.AnyAsync(u => u.Identifier == form.IdentifierNumber && u.Year == form.Year && !u.IsDeleted);

            if (exist)
            {
                return(new HbResult <HbLot>(ErrorCodes.LotAlreadyExist));
            }

            var dbLot = _dc.Lots.Add(new HbLots
            {
                Identifier   = form.IdentifierNumber,
                CreationDate = DateTime.UtcNow,
                Year         = form.Year
            });

            await _dc.SaveChangesAsync();

            return(new HbResult <HbLot>(_mapper.Map <HbLot>(dbLot.Entity)));
        }