public int Update(PengeluaranBiaya obj) { var result = 0; try { _context.BeginTransaction(); var transaction = _context.transaction; obj.total = GetTotalNota(obj); // update header result = _context.db.Update <PengeluaranBiaya>(obj, transaction) ? 1 : 0; // delete detail foreach (var item in obj.item_pengeluaran_biaya_deleted) { result = _context.db.Delete <ItemPengeluaranBiaya>(item, transaction) ? 1 : 0; } // insert/update detail foreach (var item in obj.item_pengeluaran_biaya.Where(f => f.JenisPengeluaran != null)) { item.pengeluaran_id = obj.pengeluaran_id; item.pengguna_id = obj.pengguna_id; if (item.entity_state == EntityState.Added) { item.item_pengeluaran_id = _context.GetGUID(); _context.db.Insert <ItemPengeluaranBiaya>(item, transaction); result = 1; } else if (item.entity_state == EntityState.Modified) { result = _context.db.Update <ItemPengeluaranBiaya>(item, transaction) ? 1 : 0; } // update entity state item.entity_state = EntityState.Unchanged; } _context.Commit(); LogicalThreadContext.Properties["NewValue"] = obj.ToJson(); _log.Info("Update data"); result = 1; } catch (Exception ex) { _log.Error("Error:", ex); } return(result); }
public int Save(PengeluaranBiaya obj) { var result = 0; try { _context.BeginTransaction(); var transaction = _context.transaction; if (obj.pengeluaran_id == null) { obj.pengeluaran_id = _context.GetGUID(); } obj.total = GetTotalNota(obj); // insert header _context.db.Insert <PengeluaranBiaya>(obj, transaction); // insert detail foreach (var item in obj.item_pengeluaran_biaya.Where(f => f.JenisPengeluaran != null)) { if (item.jenis_pengeluaran_id.Length > 0) { if (item.item_pengeluaran_id == null) { item.item_pengeluaran_id = _context.GetGUID(); } item.pengeluaran_id = obj.pengeluaran_id; item.pengguna_id = obj.pengguna_id; _context.db.Insert <ItemPengeluaranBiaya>(item, transaction); // update entity state item.entity_state = EntityState.Unchanged; } } _context.Commit(); LogicalThreadContext.Properties["NewValue"] = obj.ToJson(); _log.Info("Tambah data"); result = 1; } catch (Exception ex) { _log.Error("Error:", ex); } return(result); }
public int Delete(PengeluaranBiaya obj) { var result = 0; try { result = _context.db.Delete <PengeluaranBiaya>(obj) ? 1 : 0; if (result > 0) { LogicalThreadContext.Properties["OldValue"] = obj.ToJson(); _log.Info("Hapus data"); } } catch (Exception ex) { _log.Error("Error:", ex); } return(result); }