Exemple #1
0
    public async Task <ServiceResponse <GetGastoDto> > PutGasto(UpdateGastoDto updatedGasto)
    {
        ServiceResponse <GetGastoDto> serviceResponse = new ServiceResponse <GetGastoDto>();

        try
        {
            Gasto gasto = await _context.Gastos.FindAsync(updatedGasto.ID);

            gasto.Nombre           = updatedGasto.Nombre;
            gasto.Importe          = updatedGasto.Importe;
            gasto.Pagado           = updatedGasto.Pagado;
            gasto.FechaVencimiento = updatedGasto.FechaVencimiento;

            //_context.Entry(_mapper.Map<Gasto>(updatedGasto)).State = EntityState.Modified;
            _context.Gastos.Update(gasto);
            await _context.SaveChangesAsync();

            serviceResponse.Data = _mapper.Map <GetGastoDto>(updatedGasto);
        }
        catch (Exception ex)
        {
            serviceResponse.Success = false;
            serviceResponse.Message = ex.Message;
        }
        return(serviceResponse);
    }
Exemple #2
0
        public async Task <IActionResult> PutGasto(UpdateGastoDto updatedGasto)
        {
            ServiceResponse <GetGastoDto> response = await _gastoService.PutGasto(updatedGasto);

            if (response.Data == null)
            {
                return(NotFound(response));
            }
            return(Ok(response));
        }