protected override int InsertObject(object newEntity) { LinqDataSourceInsertEventArgs insertEventArgs = new LinqDataSourceInsertEventArgs(newEntity); OnInserting(insertEventArgs); if (insertEventArgs.Cancel) { return(-1); } LinqDataSourceStatusEventArgs insertedEventArgs = null; try { InsertDataObject(Context, EntitySet, insertEventArgs.NewObject); } catch (Exception e) { // allow user to handle dlinq exceptions including OnValidate validation. insertedEventArgs = new LinqDataSourceStatusEventArgs(e); OnInserted(insertedEventArgs); OnException(new DynamicValidatorEventArgs(e, DynamicDataSourceOperation.Insert)); if (insertedEventArgs.ExceptionHandled) { return(-1); } throw; } insertedEventArgs = new LinqDataSourceStatusEventArgs(insertEventArgs.NewObject); OnInserted(insertedEventArgs); return(1); }
protected virtual void OnInserting(LinqDataSourceInsertEventArgs e) { if (Inserting != null) { Inserting(this, e); } }
protected void sourceAssets_Inserting(object sender, LinqDataSourceInsertEventArgs e) { var asset = (ClientAssetClass)e.NewObject; string guidString = ViewState["ClientAssetClass_ClientGUID"].ToString(); Guid guid = new Guid(guidString); asset.ClientGUID = guid; }
protected void LinqDataSource1_Inserting1(object sender, LinqDataSourceInsertEventArgs e) { Product books = (Product)e.NewObject; books.UserName = User.Identity.Name; Session["ID"] = books.UserName; books.AddedDate = DateTime.Now; books.Status = 1; books.UnitsInStock = 1; }
protected virtual void OnInserting(LinqDataSourceInsertEventArgs e) { EventHandler <LinqDataSourceInsertEventArgs> handler = (EventHandler <LinqDataSourceInsertEventArgs>)Events[EventInserting]; if (handler != null) { handler(this, e); } }
protected override void HandleValidationErrors(IDictionary <string, Exception> errors, DataSourceOperation operation) { LinqDataSourceValidationException exception = new LinqDataSourceValidationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.LinqDataSourceView_ValidationFailed, EntityType, errors.Values.First().Message), errors); bool exceptionHandled = false; switch (operation) { case DataSourceOperation.Delete: LinqDataSourceDeleteEventArgs deleteEventArgs = new LinqDataSourceDeleteEventArgs(exception); OnDeleting(deleteEventArgs); OnException(new DynamicValidatorEventArgs(exception, DynamicDataSourceOperation.Delete)); exceptionHandled = deleteEventArgs.ExceptionHandled; break; case DataSourceOperation.Insert: LinqDataSourceInsertEventArgs insertEventArgs = new LinqDataSourceInsertEventArgs(exception); OnInserting(insertEventArgs); OnException(new DynamicValidatorEventArgs(exception, DynamicDataSourceOperation.Insert)); exceptionHandled = insertEventArgs.ExceptionHandled; break; case DataSourceOperation.Update: // allow user to handle conversion or dlinq property validation exceptions. LinqDataSourceUpdateEventArgs updateEventArgs = new LinqDataSourceUpdateEventArgs(exception); OnUpdating(updateEventArgs); OnException(new DynamicValidatorEventArgs(exception, DynamicDataSourceOperation.Update)); exceptionHandled = updateEventArgs.ExceptionHandled; break; } if (!exceptionHandled) { throw exception; } }
protected virtual void OnInserting (LinqDataSourceInsertEventArgs e) { if (Inserting != null) Inserting (this, e); }
protected virtual void OnInserting(LinqDataSourceInsertEventArgs e) { EventHandler<LinqDataSourceInsertEventArgs> handler = (EventHandler<LinqDataSourceInsertEventArgs>)Events[EventInserting]; if (handler != null) { handler(this, e); } }
protected override int InsertObject(object newEntity) { LinqDataSourceInsertEventArgs insertEventArgs = new LinqDataSourceInsertEventArgs(newEntity); OnInserting(insertEventArgs); if (insertEventArgs.Cancel) { return -1; } LinqDataSourceStatusEventArgs insertedEventArgs = null; try { InsertDataObject(Context, EntitySet, insertEventArgs.NewObject); } catch (Exception e) { // allow user to handle dlinq exceptions including OnValidate validation. insertedEventArgs = new LinqDataSourceStatusEventArgs(e); OnInserted(insertedEventArgs); OnException(new DynamicValidatorEventArgs(e, DynamicDataSourceOperation.Insert)); if (insertedEventArgs.ExceptionHandled) { return -1; } throw; } insertedEventArgs = new LinqDataSourceStatusEventArgs(insertEventArgs.NewObject); OnInserted(insertedEventArgs); return 1; }
protected override void HandleValidationErrors(IDictionary<string, Exception> errors, DataSourceOperation operation) { LinqDataSourceValidationException exception = new LinqDataSourceValidationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.LinqDataSourceView_ValidationFailed, EntityType, errors.Values.First().Message), errors); bool exceptionHandled = false; switch (operation) { case DataSourceOperation.Delete: LinqDataSourceDeleteEventArgs deleteEventArgs = new LinqDataSourceDeleteEventArgs(exception); OnDeleting(deleteEventArgs); OnException(new DynamicValidatorEventArgs(exception, DynamicDataSourceOperation.Delete)); exceptionHandled = deleteEventArgs.ExceptionHandled; break; case DataSourceOperation.Insert: LinqDataSourceInsertEventArgs insertEventArgs = new LinqDataSourceInsertEventArgs(exception); OnInserting(insertEventArgs); OnException(new DynamicValidatorEventArgs(exception, DynamicDataSourceOperation.Insert)); exceptionHandled = insertEventArgs.ExceptionHandled; break; case DataSourceOperation.Update: // allow user to handle conversion or dlinq property validation exceptions. LinqDataSourceUpdateEventArgs updateEventArgs = new LinqDataSourceUpdateEventArgs(exception); OnUpdating(updateEventArgs); OnException(new DynamicValidatorEventArgs(exception, DynamicDataSourceOperation.Update)); exceptionHandled = updateEventArgs.ExceptionHandled; break; } if (!exceptionHandled) { throw exception; } }
protected void dsLink_Inserting(object sender, LinqDataSourceInsertEventArgs e) { Weblink link = (Weblink)e.NewObject; link.CategoryId = int.Parse(ddlLinkCategories.SelectedValue); }