public void invoke_AfterSave(object sender, EventArgs args) { if (AfterSave != null) { AfterSave.Invoke(sender, args); } }
/// <summary> /// Commits all currently tracked entity changes /// </summary> /// <returns>the number of rows affected</returns> public virtual int Commit() { _log.Trace("\tCommit"); BeforeSave?.Invoke(this, new Interceptors.Events.BeforeSave()); ChangeTracker.DetectChanges(); int result = SaveChanges(); AfterSave?.Invoke(this, new Interceptors.Events.AfterSave()); _log.DebugFormat("\tCommited {0} Changes", result); return(result); }
private void SaveModelEvent(object sender, EventArgs e) { //try { int saveresult = Controller.Save(Model); if (saveresult > 0) { Model = Controller.Find(Model, Controller.GetMetaData().UniqueKeyFields.FirstOrDefault().ToArray()); } AfterSave?.Invoke(saveresult > 0); //} catch (Exception ex) { // FormsHelper.Error(ex.Message); //} }
public virtual void Save() { gather(); if (!executeValidations()) { return; } beforeSave(); BeforeSave?.Invoke(); var result = _context.SaveChanges(); afterSave(); AfterSave?.Invoke(); scatter(); }
public virtual void Save() { if (Session == null) { throw new SessionNotInstantiatedException(); } if (!IsSaveRequired) { return; } if (OnSave != null) { OnSave.Invoke(this, new Events.DataObjectOnSaveEventArgs()); } Session.Save(this); if (AfterSave != null) { AfterSave.Invoke(this, new Events.DataObjectAfterSaveArgs()); } }
/// <summary> /// Método responsável em realizar o salvamento dos registros na tela. /// </summary> /// <returns></returns> public override bool Salvar() { try { // Verifica se todos os campos foram validados. if (!IsValid()) { return(false); } var ret = ExecuteApp(TypeAction.Insert); AfterSave?.Invoke(); ShowLog(); return(ret); } catch (Exception exception) { MessageBox.Show(exception.Message, @"Erro ao Salvar", MessageBoxButtons.OK, MessageBoxIcon.Error); ShowLog(); return(false); } }
protected virtual void OnAfterSave(AfterSave e) { AfterSave?.Invoke(this, e); }
public virtual TransactionResult Save(T entity, bool edit, string headerkeyvalue = null, bool useLog = true) { if (Context.Database.Connection.State != ConnectionState.Open) { Context.Database.Connection.Open(); } TransactionScope scope = new TransactionScope(); try { T o; if (Exists(entity)) { if (!edit) { return(TransactionResult.IsExists); } o = Find(entity); if (entity.GetType().GetProperties().Any(p => p.Name.Equals("CreatedBy", StringComparison.OrdinalIgnoreCase))) { entity.SetValue("CreatedBy", o.GetValue("CreatedBy")); entity.SetValue("CreatedAt", o.GetValue("CreatedAt")); entity.SetValue("UpdatedBy", o.GetValue("UpdatedBy")); entity.SetValue("UpdatedAt", o.GetValue("UpdatedAt")); } Context.Entry(o).CurrentValues.SetValues(entity); if (Context.Entry(o).State == EntityState.Modified && entity.GetType().GetProperties().Any(p => p.Name.Equals("UpdatedBy", StringComparison.OrdinalIgnoreCase))) { //o.SetValue("UpdatedBy", _user.UserId.ToInt()); o.SetValue("UpdatedAt", DateTime.Now); } } else { if (entity.GetType().GetProperties().Any(p => p.Name.Equals("CreatedBy", StringComparison.OrdinalIgnoreCase))) { //entity.SetValue("CreatedBy", _user.UserId.ToInt()); entity.SetValue("CreatedAt", DateTime.Now); } Context.Entry(entity).State = EntityState.Added; o = entity; } if (BeforeSave != null) { var eventUseData = new EventUseData(); BeforeSave.Invoke(o, Context, eventUseData); if (eventUseData.Cancel) { scope.Dispose(); return(eventUseData.Message); } } //if (_user.FollowUp && useLog) //{ // Context.LogEntity(o, _user, GetKeys[0], _formType, headerkeyvalue, headerkeyvalue); //} Context.SaveChanges(); scope.Complete(); if (AfterSave != null) { var eventMessage = new EventBase { Message = TransactionResult.None }; AfterSave.Invoke(o, Context, eventMessage); if (eventMessage.Message != TransactionResult.None) { return(eventMessage.Message); } } return(TransactionResult.SaveSuccess); } catch (Exception ex) { HandleException(ex); scope.Dispose(); Context.Database.Connection.Close(); //Logger.LogSystemError(_user.UserId.ToString(), ex); return(TransactionResult.SaveFailed); } finally { scope.Dispose(); } }
public BaseBinder() : base() { Controllers = new Dictionary <string, IDBController>(); Mapper = new Dictionary <string, Control>(); Prop = new Func <string, PropertyInfo>(x => typeof(M).GetProperty(x)); isBoolean = new Func <string, bool>(x => Mapper[x].GetType() == typeof(CheckBox) && Prop(x).PropertyType == typeof(bool)); isDateTime = new Func <string, bool>(x => Prop(x).PropertyType == typeof(DateTime) || Prop(x).PropertyType == typeof(DateTime?)); isInt64 = new Func <string, bool>(x => Prop(x).PropertyType == typeof(Int64)); isInt32 = new Func <string, bool>(x => Prop(x).PropertyType == typeof(Int32) || Prop(x).PropertyType == typeof(int)); isDouble = new Func <string, bool>(x => Prop(x).PropertyType == typeof(double) || Prop(x).PropertyType == typeof(Double)); //Load += (s, e) => { // if (DesignMode || (Site != null && Site.DesignMode)) return; new PermissionsHelper <M>(this); foreach (var control in Mapper.Values.OrderBy(x => x.TabIndex)) { if (DefaultControl == null && control.TabStop) { DefaultControl = control; } control.KeyDown += delegate(object sender, KeyEventArgs ea) { if (ea.KeyCode == Keys.Enter) { ea.SuppressKeyPress = true; ea.Handled = true; SendKeys.Send("\t"); } }; } DefaultControl?.Focus(); if (SaveButton != null) { SaveButton.Enabled = SaveButtonEnabled; SaveButton.Click += (bs, be) => { try { Controller.Save(Model); Model = Controller.Find(Model, Controller.GetMetaData().UniqueKeyFields.ToArray()); AfterSave?.Invoke(); DefaultControl.Focus(); DefaultControl.Select(); }catch (Exception ex) { FormsHelper.Error(ex.Message); } }; } if (DeleteButton != null) { DeleteButton.Enabled = DeleteButtonEnabled; DeleteButton.Click += (bs, be) => { Controller.Delete(Model); NewButton?.PerformClick(); }; } if (NewButton != null) { NewButton.Enabled = NewButtonEnabled; NewButton.Click += (bs, be) => { Model = Controller.NewModel <M>(); }; } //}; }
protected virtual void OnAfterSave() { AfterSave?.Invoke(); }