protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues)
        {
            Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteDelete", "Begin");

            if (!CanDelete)
            {
                throw new NotSupportedException("Delete not supported.");
            }

            var id         = keys["ID"] as Guid?;
            var entityName = keys["Name"] as string;

            if (id == null || entityName == null)
            {
                throw new ArgumentException("Delete requires the 'ID' and 'Name' to be specified as DataKeyNames.", "keys");
            }

            var rowsAffected     = 0;
            var deletedEventArgs = new CrmDataSourceViewDeletedEventArgs();

            try
            {
                var entity = _crmDataContext.Retrieve(entityName, id.Value, new ColumnSet(true));

                if (entity == null)
                {
                    throw new NullReferenceException("The {0} entity with ID='{1}' could not be found.".FormatWith(id, entityName));
                }

                _crmDataContext.Attach(entity);

                _crmDataContext.DeleteObject(entity);

                var result = _crmDataContext.SaveChanges();

                rowsAffected = result.HasError ? 0 : 1;
            }
            catch (Exception e)
            {
                Tracing.FrameworkError("CrmDataSourceView", "ExecuteDelete", "{0}", e);

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

            Tracing.FrameworkInformation("CrmDataSourceView", "ExecuteDelete", "End");

            OnDeleted(deletedEventArgs);

            return(rowsAffected);
        }
Exemplo n.º 2
0
        private static int GetImportStatus(CrmOrganizationServiceContext serviceContext, Guid importId)
        {
            var importEntity   = serviceContext.Retrieve("import", importId, new ColumnSet(new[] { "statuscode" }));
            var attributeValue = importEntity.GetAttributeValue <OptionSetValue>("statuscode");

            return((attributeValue == null) ? 0 : attributeValue.Value);
        }
Exemplo n.º 3
0
        public static Entity Retrieve(string EntityName, Guid Id, ColumnSet Columns = null, CrmConnection connection = null, bool CacheResults = true)
        {
            Columns = Columns ?? new ColumnSet(true);

            if (CacheResults)
            {
                using (CrmOrganizationServiceContext service = new CrmOrganizationServiceContext(connection ?? XrmConnection.Connection))
                {
                    return(service.Retrieve(EntityName, Id, Columns));
                }
            }
            else
            {
                OrganizationService srv = new OrganizationService(connection ?? XrmConnection.Connection);
                using (CrmOrganizationServiceContext service = new CrmOrganizationServiceContext(srv))
                {
                    return(service.Retrieve(EntityName, Id, Columns));
                }
            }
        }
Exemplo n.º 4
0
 private static int GetImportStatus(CrmOrganizationServiceContext serviceContext, Guid importId)
 {
     var importEntity = serviceContext.Retrieve("import", importId, new ColumnSet(new[] { "statuscode" }));
     var attributeValue = importEntity.GetAttributeValue<OptionSetValue>("statuscode");
     return (attributeValue == null) ? 0 : attributeValue.Value;
 }