/// <summary> /// Handles the Entity PerformWork Event of the LLBLGenProDataSource. /// Used to trap the errors if exists when the user saves. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OrdersDS_PerformWork(object sender, PerformWorkEventArgs2 e) { try { // perform the commit using (DataAccessAdapter adapter = new DataAccessAdapter()) { e.Uow.Commit(adapter, true); } // everything OK, so hide the errors. HideEntityErrorControls(); } // some validation rules have been broken! catch (ORMEntityValidationException ex) { /// Show entity errors to the user. /// In this case this validator the errors list in the exception message. ShowEntityErrors(ex.Message); } /// -- catch other exceptions -- /// ... }
/// <summary> /// Customerses the D s_ perform work. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void CustomersDS_PerformWork(object sender, PerformWorkEventArgs2 e) { try { // perform the commit using (DataAccessAdapter adapter = new DataAccessAdapter()) { e.Uow.Commit(adapter, true); } // everything OK, so hide the errors. HideEntityErrorControls(); } // some validation rules have been broken! catch (ORMEntityValidationException ex) { // oops, there are errors somewhere, lets show them to the user. // this message come from the CustomerValidator class and come formatted so we can split it. ShowEntityErrors(ex.Message); } /// -- catch other exceptions -- /// ... }
/// <summary> /// Eventhandler for the PerformWork event on the _CustomerDS datasourcecontrol /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void _CustomerDS_PerformWork(object sender, PerformWorkEventArgs2 e) { // as we're using a formview, there's just 1 entity in the UoW. CustomerEntity entityToProcess = null; List <UnitOfWorkElement2> elementsToInsert = e.Uow.GetEntityElementsToInsert(); if (elementsToInsert.Count > 0) { // it's an insert operation. grab the entity so we can determine the PK later on. entityToProcess = (CustomerEntity)elementsToInsert[0].Entity; } using (DataAccessAdapter adapter = new DataAccessAdapter()) { e.Uow.Commit(adapter, true); } if (entityToProcess != null) { // store the PK values so a redirect can use these. _pkValuesAfterInsert = "&CustomerId=" + entityToProcess.CustomerId; } }
/// <summary> /// Handles the LLBLGenProDataSource PerformWork Event which is raised when LivePersistence is set to false and an insert/update/delete has to be performed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void EmployeeDetailsDS_PerformWork(object sender, PerformWorkEventArgs2 e) { #region Get the entityToDelete from UOW EmployeeEntity entityToDelete = null; // If found, get the entity to be deleted from the UnitOfWork object. List <UnitOfWorkElement2> deleteItems = e.Uow.GetEntityElementsToDelete(); if (deleteItems.Count > 0) { entityToDelete = (EmployeeEntity)deleteItems[0].Entity; } #endregion #region Get the entityToUpdate from UOW EmployeeEntity entityToUpdate = null; // If found, get the entity to be updated from the UnitOfWork object. List <UnitOfWorkElement2> updateItems = e.Uow.GetEntityElementsToUpdate(); if (updateItems.Count > 0) { entityToUpdate = (EmployeeEntity)updateItems[0].Entity; //Set the Photo of the EMployee, if uploaded. SetPicture(entityToUpdate); } #endregion #region Get the entityToInsert from UOW EmployeeEntity entityToInsert = null; // If found, get the entity to be inserted from the UnitOfWork object. List <UnitOfWorkElement2> inserteItems = e.Uow.GetEntityElementsToInsert(); if (inserteItems.Count > 0) { entityToInsert = (EmployeeEntity)inserteItems[0].Entity; //Set the Photo of the EMployee, if uploaded. SetPicture(entityToInsert); } #endregion #region Determining the entity to validate // entity to be validated EmployeeEntity entityToValidate = null; // flag to know whether the entity is valid bool entityToValidateIsValid = true; if (entityToInsert != null) { entityToValidate = entityToInsert; } if (entityToUpdate != null) { entityToValidate = entityToUpdate; } #endregion #region Validating the entity via ValidateEntity() method if (entityToValidate != null) { try { // perform the validate process entityToValidate.ValidateEntity(); // everything OK, lets hide the error controls HideEntityErrorControls(); } catch (ORMEntityValidationException ex) { // oops, there are errors somewhere, lets show to the user ShowEntityErrors(ex.Message); entityToValidateIsValid = false; } } #endregion #region Perform the work if (entityToValidateIsValid) { try { DataAccessAdapter adapter = new DataAccessAdapter(); e.Uow.Commit(adapter, true); } catch (ORMQueryExecutionException ex) { /// catch other errors /// ... } } #endregion }