public virtual JsonResult Create(T v, [DataSourceRequest] DataSourceRequest request) { EntitySaving?.Invoke(this, new EntityEventArgs <T>(v, EntityState.Added)); Context.Set <T>().Add(v); Context.SaveChanges(); EntitySaved?.Invoke(this, new EntityEventArgs <T>(v, EntityState.Added)); return(Json(new[] { v }.ToDataSourceResult(request))); }
private void SaveUoW() { UoW.Save(); if (UoW.RootObject != null) { EntitySaved?.Invoke(this, new EntitySavedEventArgs(UoW.RootObject)); } }
public virtual JsonResult Update(T p, [DataSourceRequest] DataSourceRequest request) { Context.Set <T>().Attach(p); Context.Entry(p).State = System.Data.Entity.EntityState.Modified; EntitySaving?.Invoke(this, new EntityEventArgs <T>(p, EntityState.Modified)); Context.SaveChanges(); EntitySaved?.Invoke(this, new EntityEventArgs <T>(p, EntityState.Modified)); return(Json(new[] { p }.ToDataSourceResult(request))); }
public virtual JsonResult Delete(T v, [DataSourceRequest] DataSourceRequest request) { Context.Set <T>().Attach(v); EntitySaving?.Invoke(this, new EntityEventArgs <T>(v, EntityState.Deleted)); Context.Set <T>().Remove(v); try { Context.SaveChanges(); } catch (SqlException ex) { if (ex.Errors[0].Number == 547)//FK { throw new Exception("این اطلاعات جای دیگری استفاده شده است و نمی تواند حذف شود.", ex); } } EntitySaved?.Invoke(this, new EntityEventArgs <T>(v, EntityState.Deleted)); return(Json(new[] { v }.ToDataSourceResult(request))); }
void ViewModel_EntitySaved(object sender, EventArgs e) { EntitySaved?.Invoke(this, new EntitySavedEventArgs(ViewModel.RootEntity, tabClosed)); }
public virtual bool Save() { UoW.Save(); EntitySaved?.Invoke(this, EventArgs.Empty); return(true); }
private void OnEntitySaved() { EntitySaved?.Invoke(); }