public virtual T SaveChanges(T model) { using (var context = new MoviekusDbContext()) { try { bool inserted = model.IsNew; if (model.IsNew) { context.Set <T>().Add(model); } else { context.Entry(model).State = EntityState.Modified; } model.IsNew = false; context.SaveChanges(); if (inserted) { OnModelInserted?.Invoke(this, model); } else { OnModelUpdated?.Invoke(this, model); } } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error(ex); throw; } return(model); } }