Exemplo n.º 1
0
        public async Task <IActionResult> UpdateCartProduct(int cartId, CartProductUpdateDto productToUpdate)
        {
            var productCart = await _repo.GetCartProduct(cartId, productToUpdate.ProductId);

            _mapper.Map(productToUpdate, productCart);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception($"Updating cart failed on save");
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateProduct(int id, ProductAddDto productToUpdate)
        {
            var productFromRepo = await _repo.GetProduct(id);

            _mapper.Map(productToUpdate, productFromRepo);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception($"Updating product {id} failed on save");
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdateDto userToUpdate)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var userFromRepo = await _repo.GetUser(id);

            _mapper.Map(userToUpdate, userFromRepo);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception($"Updating user {id} failed on save");
        }