public async Task <IActionResult> CreateNewItem([FromBody] CreateItemRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _service.Create(ItemViewFactory.Create(model));

            if (result == null)
            {
                return(BadRequest());
            }

            return(Ok(ItemFactory.CreateEntity(result)));
        }
        public async Task <IActionResult> UpdateItem([FromRoute] int id, [FromBody] ItemDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            model.Id = id;
            var result = await _service.Update(model);

            if (result == null)
            {
                return(BadRequest());
            }

            return(Ok(ItemFactory.CreateEntity(result)));
        }
Beispiel #3
0
 /// <summary>
 /// Create
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 public async Task<ItemDto> Create(ItemDto dto)
 {
     var entity = ItemFactory.CreateEntity(dto);
     var res = await _repository.InsertAsync(entity);
     return ItemFactory.CreateDto(res);
 }