Esempio n. 1
0
        public async Task <IActionResult> UpdateSale(int id, SaleForUpdateDto saleForUpdateDto)
        {
            var saleFromRepo = await _repo.GetSale(id);

            _mapper.Map(saleForUpdateDto, saleFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating sale details failed on save");
        }
Esempio n. 2
0
        // Este endpoint podría aceptar un dto
        public async Task <IActionResult> Put(int id, int orderId, [FromBody] SaleForUpdateDto saleDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var saleForRepo = await _repo.GetSaleByIdForUpdateOrDelete(orderId);

            _mapper.Map(saleDto, saleForRepo);
            _repo.Update(saleForRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            // si ha ido mal
            throw new Exception($"Updating sale {id} failed on save.");
        }