public async Task <ActionResult> Update(long id, [FromBody] SaveCashVoucherRequest entity) { try { var cashVoucher = await context.CashVouchers .AsNoTracking() .SingleOrDefaultAsync(t => t.Id == id); if (cashVoucher == null) { return(NotFound()); } cashVoucher = mapper.Map <CashVoucher>(entity); context.Update(cashVoucher); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status204NoContent)); } catch (DbUpdateConcurrencyException concurrencyEx) { logger.LogError(concurrencyEx.Message); return(StatusCode(StatusCodes.Status409Conflict, Constants.ErrorMessages.ConcurrencyErrorMessage)); } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveCashVoucherRequest entity) { try { var cashVoucher = mapper.Map <CashVoucher>(entity); await context.CashVouchers.AddAsync(cashVoucher); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }