private async Task ValidateUnit(string dtoItemName, Unit?unit = null)
        {
            var UnitByName = await _unitRepo.GetByName(dtoItemName).ConfigureAwait(false);

            if (UnitByName != null && unit != UnitByName)
            {
                throw new Exception("Unit with same name already exists.");
            }
        }
Example #2
0
        public async Task <IActionResult> Create(UnitCreateIndexView model)
        {
            try
            {
                var UnitDto = new UnitCreateDTO {
                    Name = model.UnitName
                };


                await _unitService.Create(UnitDto).ConfigureAwait(true);

                var Unit = await _unitRepo.GetByName(UnitDto.Name) ?? throw new Exception("Unit Not Found.");

                return(Ok(CreateReponseDto(Unit)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }