private void Add <T>(T entity, BillingContext context) where T : BaseEntity { if (entity.Id > 0) { context.Entry(entity).State = EntityState.Modified; } else { context.Entry(entity).State = EntityState.Added; } context.SaveChanges(); }
public virtual void Update(Entity entity, int id) { Entity oldEntity = Get(id); if (oldEntity != null) { context.Entry(oldEntity).CurrentValues.SetValues(entity); } }
public void Update(Domain.Bill item) { var entity = EntityFrom(item); var existingEntity = context.Bills .Include(e => e.Lines) .FirstOrDefault(e => e.Id == entity.Id) ?? throw new ArgumentException($"The bill {entity.Id} was not found"); logger.Log(context, "Bill", "Update", existingEntity, entity); context.Entry(existingEntity).CurrentValues.SetValues(entity); existingEntity.Lines.Clear(); existingEntity.Lines.AddRange(entity.Lines); context.SaveChanges(); }