public async Task <int> Update(string id, Transaction transactionUpdate) { try { if (id != transactionUpdate.Id) { throw new Exception("Different id"); } var transaction = await GetById(id); if (transaction == null) { throw new NotFoundException(); } ValidateFieldsEmpty(transactionUpdate); _context.Entry <Transaction>(transactionUpdate).State = EntityState.Modified; int result = await _context.SaveChangesAsync(); _context.Entry <Transaction>(transactionUpdate).State = EntityState.Detached; return(result); } catch (DbUpdateConcurrencyException e) { if (!TransactionExists(id)) { throw new NotFoundException(); } else { throw e; } } catch (DbException e) { throw e; } catch (NotFoundException e) { throw e; } catch (Exception e) { throw e; } }
public async Task <int> Update(string id, Categorie categorieUpdate) { try { if (id != categorieUpdate.Id) { throw new Exception("Different id"); } var categorie = await GetById(id); if (categorie == null) { throw new NotFoundException(); } ValidateFieldsEmpty(categorieUpdate); _context.Entry <Categorie>(categorieUpdate).State = EntityState.Modified; int result = await _context.SaveChangesAsync(); _context.Entry <Categorie>(categorieUpdate).State = EntityState.Detached; return(result); } catch (DbUpdateConcurrencyException e) when(!CategorieExists(id)) { throw e; } catch (DbException e) { throw e; } catch (NotFoundException e) { throw e; } catch (Exception e) { throw e; } }