protected override int UpdateObject(object oldEntity, object newEntity)
        {
            LinqDataSourceUpdateEventArgs updateEventArgs = new LinqDataSourceUpdateEventArgs(oldEntity, newEntity);

            OnUpdating(updateEventArgs);
            if (updateEventArgs.Cancel)
            {
                return(-1);
            }

            LinqDataSourceStatusEventArgs updatedEventArgs = null;

            try {
                UpdateDataObject(Context, EntitySet, updateEventArgs.OriginalObject, updateEventArgs.NewObject);
            }
            catch (Exception e) {
                ResetDataObject(EntitySet, updateEventArgs.OriginalObject);
                // allow user to handle dlinq exceptions including OnValidate validation.
                updatedEventArgs = new LinqDataSourceStatusEventArgs(e);
                OnUpdated(updatedEventArgs);
                OnException(new DynamicValidatorEventArgs(e, DynamicDataSourceOperation.Update));
                if (updatedEventArgs.ExceptionHandled)
                {
                    return(-1);
                }
                throw;
            }
            updatedEventArgs = new LinqDataSourceStatusEventArgs(updateEventArgs.NewObject);
            OnUpdated(updatedEventArgs);

            return(1);
        }
 protected virtual void OnUpdating(LinqDataSourceUpdateEventArgs e)
 {
     if (Updating != null)
     {
         Updating(this, e);
     }
 }
 protected void LinqDataSourceAddress_Updating(object sender, LinqDataSourceUpdateEventArgs e)
 {
     var old = (TerritorySite.BL.Linq.Address)e.OriginalObject;
     var newOne = (TerritorySite.BL.Linq.Address)e.NewObject;
     if (old.CityId != newOne.CityId  | old.StreetName != newOne.StreetName | old.HouseNumber != newOne.HouseNumber )
     {
         newOne.Geocode();
     }
 }
        protected virtual void OnUpdating(LinqDataSourceUpdateEventArgs e)
        {
            EventHandler <LinqDataSourceUpdateEventArgs> handler =
                (EventHandler <LinqDataSourceUpdateEventArgs>)Events[EventUpdating];

            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 void ldsGroups_Updating(object sender, LinqDataSourceUpdateEventArgs e)
        {
            ((Group)e.NewObject).Name = ((Group)e.NewObject).Name.Trim();
            ((Group)e.NewObject).Tag = ((Group)e.NewObject).Tag.Trim();

            //Group group = (Group) e.NewObject;

            //using (CSSDataContext db = new CSSDataContext())
            //{
            //    if (String.IsNullOrEmpty(group.Name) == true)
            //    {
            //        ValidationMessage = "Name cannot be empty.";
            //        e.Cancel = true;
            //    }
            //    else if (db.Groups.FirstOrDefault(p => p.Name == group.Name.Trim() && p.Id != group.Id) != null)
            //    {
            //        ValidationMessage = "Name is already used .";
            //        e.Cancel = true;
            //    }

            //}
        }
		protected virtual void OnUpdating (LinqDataSourceUpdateEventArgs e)
		{
			if (Updating != null)
				Updating (this, e);
		}
 protected void Settings_Updating(object sender, LinqDataSourceUpdateEventArgs e)
 {
     Setting a = (e.NewObject as Setting);
     a.Login = HttpContext.Current.User.Identity.Name;
     a.CreatedAt = DateTime.UtcNow;
 }
        protected override int UpdateObject(object oldEntity, object newEntity) {
            LinqDataSourceUpdateEventArgs updateEventArgs = new LinqDataSourceUpdateEventArgs(oldEntity, newEntity);
            OnUpdating(updateEventArgs);
            if (updateEventArgs.Cancel) {
                return -1;
            }

            LinqDataSourceStatusEventArgs updatedEventArgs = null;
            try {
                UpdateDataObject(Context, EntitySet, updateEventArgs.OriginalObject, updateEventArgs.NewObject);
            }
            catch (Exception e) {
                ResetDataObject(EntitySet, updateEventArgs.OriginalObject);
                // allow user to handle dlinq exceptions including OnValidate validation.
                updatedEventArgs = new LinqDataSourceStatusEventArgs(e);
                OnUpdated(updatedEventArgs);
                OnException(new DynamicValidatorEventArgs(e, DynamicDataSourceOperation.Update));
                if (updatedEventArgs.ExceptionHandled) {
                    return -1;
                }
                throw;
            }
            updatedEventArgs = new LinqDataSourceStatusEventArgs(updateEventArgs.NewObject);
            OnUpdated(updatedEventArgs);

            return 1;
        }
 protected virtual void OnUpdating(LinqDataSourceUpdateEventArgs e) {
     EventHandler<LinqDataSourceUpdateEventArgs> handler =
         (EventHandler<LinqDataSourceUpdateEventArgs>)Events[EventUpdating];
     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 void LinqDataSourceTerritories_Updating(object sender, LinqDataSourceUpdateEventArgs e)
 {
 }
 protected void LinqDataSourceAssignments_Updating(object sender, LinqDataSourceUpdateEventArgs e)
 {
 }
 protected void LinqDataSource_Rooms_Updating(object sender, LinqDataSourceUpdateEventArgs e)
 {
     if (e.Exception != null)
     {
         Label_StatusMsg.Text = "Could not edit room: " + e.Exception.Message;
         e.ExceptionHandled = true;
     }
 }