Beispiel #1
0
        public ActionResult <ItemReadDto> CreateItem(ItemCreateDto itemCreateDto)
        {
            var model = new Item()
            {
                IdCategory = _repository.GetCategoryById(itemCreateDto.CategoryId),
                ItemName   = itemCreateDto.ItemName,
            };

            try
            {
                _repository.CreateItem(model);
                _repository.SaveChanges();
                _logger.LogInformation("Item created by {HttpUser}", HttpContext.User.Identity.Name);
            }
            catch (System.Exception ex)
            {
                _logger.LogInformation("Item creation failed. Exception:", ex.Message);
            }


            var readDto = _mapper.Map <ItemReadDto>(model);

            return(CreatedAtRoute(nameof(GetItemById), new { Id = readDto.ItemId }, readDto));
        }