Exemple #1
0
        public async Task <IActionResult> CreateItem([FromBody] ItemForManipulationViewModel item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity(ModelState.GetValidationErrors()));
            }

            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var itemToAdd = _mapper.Map <Item>(item);

            itemToAdd.UserId = new Guid(user.Id);

            await _repository.CreateAsync(itemToAdd);

            return(CreatedAtRoute("get-item", new { id = itemToAdd.Id }, itemToAdd));
        }