public virtual async Task <T> SaveChangesAsync(T model) { if (model.IsDeleted) { return(model); } using (var context = new MoviekusDbContext()) { try { bool inserted = model.IsNew; if (model.IsNew) { await InsertAsync(context, model); } else { UpdateAsync(context, model); } model.IsNew = false; await context.SaveChangesAsync(); if (inserted) { OnModelInserted?.Invoke(this, model); } else { OnModelUpdated?.Invoke(this, model); } } catch (Exception ex) { LogManager.GetCurrentClassLogger().Error(ex); throw; } return(model); } }
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); } }
private void ChangeState(string newModelState, bool lockModel = false) { CurrentState = newModelState; Ready = !lockModel; OnModelUpdated?.Invoke(); }