Пример #1
0
        public async Task <IActionResult> Create([FromBody] CreateSneakerRequest sneakerRequest)
        {
            var sneaker = _mapper.Map <Sneaker>(sneakerRequest);

            SneakerRepository.PutFieldsToUppercase(sneaker);
            try
            {
                sneaker.Id = await _sneakerRepository.CreateAsync(sneaker);
            }
            catch (MySqlException ex)
            {
                Console.WriteLine(ex);
            }

            return(Ok(sneaker));
        }
Пример #2
0
        public async Task <IActionResult> Update([FromRoute] int id, [FromBody] UpdateSneakerRequest sneakerRequest)
        {
            try
            {
                var sneaker = _mapper.Map <Sneaker>(sneakerRequest);
                sneaker.Id = id;
                SneakerRepository.PutFieldsToUppercase(sneaker);

                var numOfRowsUpdated = await _sneakerRepository.UpdateAsync(id, sneaker);

                if (numOfRowsUpdated == 0)
                {
                    return(NotFound());
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine(ex);
            }

            return(Ok(await _sneakerRepository.GetByIdAsync(id)));
        }