public async Task <IActionResult> Create(ItemCreateIndexView model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var Unit = await _unitRepo.GetById(model.UnitId).ConfigureAwait(true);

                    var item = new ItemCreateDTO {
                        ItemName = model.ItemName, Price = model.Price, Unit = Unit
                    };


                    await _itemService.Create(item).ConfigureAwait(true);

                    _toastNotification.AddSuccessToastMessage("Successfully Created Item :- " + item.ItemName);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                model.Units = (await _unitRepo.GetAllAsync().ConfigureAwait(true)).Where(a => a.IsActive()).ToList();
                _toastNotification.AddErrorToastMessage(ex.Message);
            }
            return(View(model));
        }
        public async Task Update(UnitUpdateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();
            var Unit = await _unitRepo.GetById(dto.UnitId).ConfigureAwait(false);

            await ValidateUnit(dto.Name, Unit);

            Unit.Update(dto.Name);
            await _unitRepo.UpdateAsync(Unit);

            tx.Complete();
        }
Example #3
0
        public async Task <ActionResult> GetById(long id)
        {
            try
            {
                var Unit = await _unitRepo.GetById(id) ?? throw new Exception("Unit Not Found.");

                return(Ok(CreateReponseDto(Unit)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Update(long id)
        {
            var Unit = await _unitRepo.GetById(id).ConfigureAwait(true);

            var model = new UnitUpdateViewModel();

            model.UnitId = Unit.Id;
            model.Name   = Unit.Name;

            return(View(model));
        }