protected virtual void OnInserted(CrmDataSourceViewInsertedEventArgs args)
        {
            var handler = (EventHandler <CrmDataSourceViewInsertedEventArgs>)Events[EventInserted];

            if (handler != null)
            {
                handler(this, args);
            }
        }
Ejemplo n.º 2
0
        private void DataSourceViewInserted(object sender, CrmDataSourceViewInsertedEventArgs e)
        {
            var insertedEventArgs = new CrmEntityFormViewInsertedEventArgs
            {
                EntityId         = e.EntityId,
                Exception        = e.Exception,
                ExceptionHandled = e.ExceptionHandled
            };

            OnItemInserted(insertedEventArgs);
        }
        protected override int ExecuteInsert(IDictionary values)
        {
            Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteInsert", "Begin");

            if (!CanInsert)
            {
                throw new NotSupportedException("Insert not supported.");
            }

            string entityName = values["EntityName"] as string;

            if (string.IsNullOrEmpty(entityName))
            {
                throw new ArgumentException("Insert requires an 'EntityName' to be specified as one of the values.", "values");
            }

            var entity = new Entity(entityName);

            SetEntityAttributes(entity, values);

            var rowsAffected      = 0;
            var insertedEventArgs = new CrmDataSourceViewInsertedEventArgs();

            try
            {
                _crmDataContext.AddObject(entity);
                _crmDataContext.SaveChanges();

                insertedEventArgs.EntityId = entity.Id;

                rowsAffected = 1;
            }
            catch (Exception e)
            {
                Tracing.FrameworkError("CrmDataSourceView", "ExecuteInsert", "{0}", e);

                insertedEventArgs.Exception        = e;
                insertedEventArgs.ExceptionHandled = true;
            }

            Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteInsert", "End: rowsAffected={0}", rowsAffected);

            OnInserted(insertedEventArgs);

            return(rowsAffected);
        }