Exemplo n.º 1
0
        public bool ValidateProfile(ThisEntity profile, ref bool isEmpty, ref SaveStatus status)
        {
            status.HasSectionErrors = false;

            isEmpty = false;
            //check if empty

            //&& ( profile.EstimatedCost == null || profile.EstimatedCost.Count == 0 )
            if (string.IsNullOrWhiteSpace(profile.ProfileName))
            {
                status.AddError("A Condition Manifest name must be entered");
            }
            if (string.IsNullOrWhiteSpace(profile.Description))
            {
                status.AddWarning("A Condition Manifest Description must be entered");
            }

            //not sure if this will be selected, or by context
            if (!IsValidGuid(profile.OwningAgentUid))
            {
                status.AddError("An owning organization must be selected");
            }

            if (!IsUrlValid(profile.SubjectWebpage, ref commonStatusMessage))
            {
                status.AddWarning("The Subject Webpage Url is invalid " + commonStatusMessage);
            }

            return(!status.HasSectionErrors);
        }
Exemplo n.º 2
0
        public static ThisEntity GetBySubjectWebpage(string swp)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                context.Configuration.LazyLoadingEnabled = false;
                DBEntity from = context.ConditionManifest
                                .FirstOrDefault(s => s.SubjectWebpage.ToLower() == swp.ToLower());

                if (from != null && from.Id > 0)
                {
                    entity.RowId          = from.RowId;
                    entity.Id             = from.Id;
                    entity.Name           = from.Name;
                    entity.EntityStateId  = ( int )(from.EntityStateId ?? 1);
                    entity.Description    = from.Description;
                    entity.SubjectWebpage = from.SubjectWebpage;

                    entity.CTID = from.CTID;
                    entity.CredentialRegistryId = from.CredentialRegistryId;
                }
            }
            return(entity);
        }
Exemplo n.º 3
0
        public bool UpdateParts(ThisEntity entity, ref SaveStatus status)
        {
            status.HasSectionErrors = false;
            Entity relatedEntity = EntityManager.GetEntity(entity.RowId);

            if (relatedEntity == null || relatedEntity.Id == 0)
            {
                status.AddError("Error - the related Entity was not found.");
                return(false);
            }

            //ConditionProfile
            Entity_ConditionProfileManager emanager = new Entity_ConditionProfileManager();

            //deleteall is handled in SaveList
            //emanager.DeleteAll( relatedEntity, ref status );

            emanager.SaveList(entity.Requires, Entity_ConditionProfileManager.ConnectionProfileType_Requirement, entity.RowId, ref status);
            emanager.SaveList(entity.Recommends, Entity_ConditionProfileManager.ConnectionProfileType_Recommendation, entity.RowId, ref status);
            emanager.SaveList(entity.Corequisite, Entity_ConditionProfileManager.ConnectionProfileType_Corequisite, entity.RowId, ref status);
            emanager.SaveList(entity.EntryCondition, Entity_ConditionProfileManager.ConnectionProfileType_EntryCondition, entity.RowId, ref status);
            emanager.SaveList(entity.Renewal, Entity_ConditionProfileManager.ConnectionProfileType_Renewal, entity.RowId, ref status);

            return(status.WasSectionValid);
        }         //
Exemplo n.º 4
0
        public static ThisEntity Get(int id,
                                     bool forEditView = false)
        {
            ThisEntity entity            = new ThisEntity();
            bool       includingProfiles = false;

            if (forEditView)
            {
                includingProfiles = true;
            }

            using (var context = new EntityContext())
            {
                DBEntity item = context.ConditionManifest
                                .SingleOrDefault(s => s.Id == id);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity,
                              true,                   //includingProperties
                              includingProfiles,
                              forEditView);
                }
            }

            return(entity);
        }
Exemplo n.º 5
0
        }        //

        public static List <ThisEntity> GetAllManifests(Guid parentUid, bool forEditView)
        {
            List <ThisEntity> list   = new List <ThisEntity>();
            ThisEntity        entity = new ThisEntity();
            Entity            parent = EntityManager.GetEntity(parentUid);

            try
            {
                using (var context = new EntityContext())
                {
                    List <EM.Entity_ConditionManifest> results = context.Entity_ConditionManifest
                                                                 .Where(s => s.EntityId == parent.Id)
                                                                 .OrderBy(s => s.ConditionManifestId)
                                                                 .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (EM.Entity_ConditionManifest item in results)
                        {
                            //TODO - optimize the appropriate MapFromDB methods
                            entity = new ThisEntity();
                            MapFromDB(item.ConditionManifest, entity);

                            list.Add(entity);
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAllManifests");
            }
            return(list);
        }
        public static ThisEntity GetByCtid(string ctid)
        {
            ThisEntity entity = new ThisEntity();

            if (string.IsNullOrWhiteSpace(ctid))
            {
                return(entity);
            }

            return(EntityMgr.GetByCtid(ctid));
        }
Exemplo n.º 7
0
        }         //

        public int AddPendingRecord(Guid entityUid, string ctid, string registryAtId, ref string status)
        {
            DBEntity efEntity = new DBEntity();

            try
            {
                using (var context = new EntityContext())
                {
                    if (!IsValidGuid(entityUid))
                    {
                        status = thisClassName + " - A valid GUID must be provided to create a pending entity";
                        return(0);
                    }
                    //quick check to ensure not existing
                    ThisEntity entity = GetByCtid(ctid);
                    if (entity != null && entity.Id > 0)
                    {
                        return(entity.Id);
                    }

                    //only add DB required properties
                    //NOTE - an entity will be created via trigger
                    efEntity.Name          = "Placeholder until full document is downloaded";
                    efEntity.Description   = "Placeholder until full document is downloaded";
                    efEntity.EntityStateId = 1;
                    efEntity.RowId         = entityUid;
                    //watch that Ctid can be  updated if not provided now!!
                    efEntity.CTID           = ctid;
                    efEntity.SubjectWebpage = registryAtId;

                    efEntity.Created     = System.DateTime.Now;
                    efEntity.LastUpdated = System.DateTime.Now;

                    context.ConditionManifest.Add(efEntity);
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        return(efEntity.Id);
                    }

                    status = thisClassName + " Error - the save was not successful, but no message provided. ";
                }
            }

            catch (Exception ex)
            {
                string message = FormatExceptions(ex);
                LoggingHelper.LogError(ex, thisClassName + string.Format(".AddPendingRecord. entityUid:  {0}, ctid: {1}", entityUid, ctid));
                status = thisClassName + " Error - the save was not successful. " + message;
            }
            return(0);
        }
Exemplo n.º 8
0
        }        //

        /// <summary>
        /// Get all the condition manifests for the parent entity (ex a credential)
        /// </summary>
        /// <param name="parentUid"></param>
        /// <returns></returns>
        public static List <ThisEntity> GetAll(Guid parentUid, bool isForLinks)
        {
            ThisEntity        to     = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();
            Entity            parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }

            try
            {
                using (var context = new EntityContext())
                {
                    //context.Configuration.LazyLoadingEnabled = false;

                    List <EM.Entity_ConditionManifest> results = context.Entity_ConditionManifest
                                                                 .Where(s => s.EntityId == parent.Id)
                                                                 .OrderBy(s => s.Created)
                                                                 .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (EM.Entity_ConditionManifest from in results)
                        {
                            to = new ThisEntity();
                            if (isForLinks)
                            {
                                to.Id    = from.Id;
                                to.RowId = from.ConditionManifest.RowId;

                                to.OrganizationId = ( int )from.Entity.EntityBaseId;
                                to.OwningAgentUid = from.Entity.EntityUid;
                                to.ProfileName    = from.ConditionManifest.Name;
                            }
                            else
                            {
                                MapFromDB(from.ConditionManifest, to, true, true, false);
                            }
                            list.Add(to);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAll (Guid parentUid)");
            }
            return(list);
        }        //
Exemplo n.º 9
0
        /// <summary>
        /// Get all the condition manifests for the parent organization
        /// </summary>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public static List <ThisEntity> GetAll(int orgId, bool isForLinks)
        {
            ThisEntity        to   = new ThisEntity();
            List <ThisEntity> list = new List <ThisEntity>();

            //Entity parent = EntityManager.GetEntity( 2, orgId );
            //if ( parent == null || parent.Id == 0 )
            //{
            //	return list;
            //}
            try
            {
                using (var context = new EntityContext())
                {
                    var results = context.ConditionManifest
                                  .Where(s => s.OrganizationId == orgId)
                                  .OrderBy(s => s.Created)
                                  .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (var from in results)
                        {
                            to = new ThisEntity();
                            if (isForLinks)
                            {
                                to.Id    = from.Id;
                                to.RowId = from.RowId;

                                to.OrganizationId = (int)from.OrganizationId;
                                //to.OwningAgentUid = from.Entity.EntityUid;
                                //
                                to.ProfileName = from.Name;
                            }
                            else
                            {
                                MapFromDB(from, to);
                            }
                            list.Add(to);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAll(int orgId)");
            }
            return(list);
        }        //
        public bool Import(ThisEntity entity, ref SaveStatus status)
        {
            bool isValid = new EntityMgr().Save(entity, ref status);

            if (entity.Id > 0)
            {
                //update cache
                new CacheManager().PopulateEntityRelatedCaches(entity.RowId);

                //TODO - will need to update related elastic indices
                new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, entity.OrganizationId, 1, ref messages);
            }

            return(isValid);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get absolute minimum for display as profile link
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ThisEntity GetBasic(int id)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                //want to get org, deal with others
                //context.Configuration.LazyLoadingEnabled = false;

                DBEntity item = context.ConditionManifest
                                .SingleOrDefault(s => s.Id == id);

                if (item != null && item.Id > 0)
                {
                    entity.Id             = item.Id;
                    entity.RowId          = item.RowId;
                    entity.Name           = item.Name;
                    entity.Description    = item.Description;
                    entity.SubjectWebpage = item.SubjectWebpage;

                    entity.OrganizationId     = ( int )(item.OrganizationId ?? 0);
                    entity.OwningOrganization = new Organization();
                    if (item.OrganizationId > 0)
                    {
                        //if ( item.Organization != null && item.Organization.Id > 0 )
                        //{
                        //	entity.OwningOrganization.Id = item.Organization.Id;
                        //	entity.OwningOrganization.Name = item.Organization.Name;
                        //	entity.OwningOrganization.RowId = item.Organization.RowId;
                        //	entity.OwningOrganization.SubjectWebpage = item.Organization.SubjectWebpage;

                        //	//OrganizationManager.ToMapCommon( item.Organization, entity.OwningOrganization, false, false, false, false, false );
                        //}
                        //else
                        {
                            entity.OwningOrganization = OrganizationManager.GetForSummary(entity.OrganizationId);
                            entity.OwningAgentUid     = entity.OwningOrganization.RowId;
                        }

                        entity.OrganizationName = entity.OwningOrganization.Name;
                        entity.OwningAgentUid   = entity.OwningOrganization.RowId;
                    }
                }
            }

            return(entity);
        }
Exemplo n.º 12
0
        public static ThisEntity GetByCtid(string ctid)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                DBEntity from = context.ConditionManifest
                                .SingleOrDefault(s => s.CTID == ctid);

                if (from != null && from.Id > 0)
                {
                    MapFromDB(from, entity);
                }
            }

            return(entity);
        }
Exemplo n.º 13
0
        public static ThisEntity GetBySubjectWebpage(string swp)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                context.Configuration.LazyLoadingEnabled = false;
                DBEntity from = context.ConditionManifest
                                .FirstOrDefault(s => s.SubjectWebpage.ToLower() == swp.ToLower());

                if (from != null && from.Id > 0)
                {
                    MapFromDB(from, entity);
                }
            }
            return(entity);
        }
Exemplo n.º 14
0
        public static ThisEntity Get(int id)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                DBEntity item = context.ConditionManifest
                                .SingleOrDefault(s => s.Id == id);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity);
                }
            }

            return(entity);
        }
 //
 public static MicroProfile ConvertConditionManifestToMicroProfile(MC.ConditionManifest item)
 {
     return(new MicroProfile()
     {
         Id = item.Id,
         RowId = item.RowId,
         Name = item.ProfileName,
         Heading2 = "",                 // item.ConditionType,
         Description = item.Description,
         Selectors = new Dictionary <string, object>()
         {
             { "RowId", item.RowId },
             { "Id", item.Id },
             { "Name", item.ProfileName },
             { "TypeName", item.GetType().Name }
         }
     });
 }
Exemplo n.º 16
0
        }        //

        public static List <ThisEntity> Search(int orgId, int pageNumber, int pageSize, ref int pTotalRows)
        {
            ThisEntity        to     = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();
            Entity            parent = EntityManager.GetEntity(2, orgId);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    List <EM.Entity_ConditionManifest> results = context.Entity_ConditionManifest
                                                                 .Where(s => s.EntityId == parent.Id)
                                                                 .OrderBy(s => s.Created)
                                                                 .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (EM.Entity_ConditionManifest from in results)
                        {
                            to = new ThisEntity();

                            to.Id             = from.ConditionManifestId;
                            to.RowId          = from.ConditionManifest.RowId;
                            to.Description    = from.ConditionManifest.Description;
                            to.OrganizationId = ( int )from.Entity.EntityBaseId;
                            to.OwningAgentUid = from.Entity.EntityUid;
                            to.ProfileName    = from.ConditionManifest.Name;

                            list.Add(to);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Search()");
            }

            return(list);
        }         //
Exemplo n.º 17
0
        /// <summary>
        /// Get absolute minimum for display as profile link
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ThisEntity GetBasic(int id)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                //want to get org, deal with others
                //context.Configuration.LazyLoadingEnabled = false;

                DBEntity item = context.ConditionManifest
                                .SingleOrDefault(s => s.Id == id);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity);
                }
            }

            return(entity);
        }
Exemplo n.º 18
0
        }         //

        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            //want to ensure fields from create are not wiped
            if (to.Id == 0)
            {
                to.CTID = from.CTID;
            }

            if (!string.IsNullOrWhiteSpace(from.CredentialRegistryId))
            {
                to.CredentialRegistryId = from.CredentialRegistryId;
            }
            //don't map rowId, ctid, or dates as not on form

            to.Id = from.Id;
            //Dont do here, do in caller
            //to.OrganizationId = from.OrganizationId;
            to.Name           = GetData(from.Name);
            to.Description    = GetData(from.Description);
            to.SubjectWebpage = GetUrlData(from.SubjectWebpage, null);
        }
Exemplo n.º 19
0
        public static ThisEntity GetByCtid(string ctid)
        {
            ThisEntity entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                DBEntity from = context.ConditionManifest
                                .SingleOrDefault(s => s.CTID == ctid);

                if (from != null && from.Id > 0)
                {
                    entity.RowId                = from.RowId;
                    entity.Id                   = from.Id;
                    entity.EntityStateId        = ( int )(from.EntityStateId ?? 1);
                    entity.Name                 = from.Name;
                    entity.Description          = from.Description;
                    entity.SubjectWebpage       = from.SubjectWebpage;
                    entity.CTID                 = from.CTID;
                    entity.CredentialRegistryId = from.CredentialRegistryId;
                }
            }

            return(entity);
        }
Exemplo n.º 20
0
        }         //

        /// <summary>
        /// Search for a condition manifest.
        /// Currently should only allow where owned by the same org as the owning org of the current context
        /// </summary>
        /// <param name="pFilter"></param>
        /// <param name="pOrderBy"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="userId"></param>
        /// <param name="pTotalRows"></param>
        /// <returns></returns>
        public static List <ThisEntity> MainSearch(string pFilter, string pOrderBy, int pageNumber, int pageSize, int userId, ref int pTotalRows)
        {
            string            connectionString = DBConnectionRO();
            ThisEntity        item             = new ThisEntity();
            List <ThisEntity> list             = new List <ThisEntity>();
            var result = new DataTable();

            using (SqlConnection c = new SqlConnection(connectionString))
            {
                c.Open();

                if (string.IsNullOrEmpty(pFilter))
                {
                    pFilter = "";
                }

                using (SqlCommand command = new SqlCommand("[ConditionManifest_Search]", c))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@Filter", pFilter));
                    command.Parameters.Add(new SqlParameter("@SortOrder", pOrderBy));
                    command.Parameters.Add(new SqlParameter("@StartPageIndex", pageNumber));
                    command.Parameters.Add(new SqlParameter("@PageSize", pageSize));

                    SqlParameter totalRows = new SqlParameter("@TotalRows", pTotalRows);
                    totalRows.Direction = ParameterDirection.Output;
                    command.Parameters.Add(totalRows);

                    using (SqlDataAdapter adapter = new SqlDataAdapter())
                    {
                        adapter.SelectCommand = command;
                        adapter.Fill(result);
                    }
                    string rows = command.Parameters[4].Value.ToString();
                    try
                    {
                        pTotalRows = Int32.Parse(rows);
                    }
                    catch
                    {
                        pTotalRows = 0;
                    }
                }

                foreach (DataRow dr in result.Rows)
                {
                    item                = new ThisEntity();
                    item.Id             = GetRowColumn(dr, "Id", 0);
                    item.OrganizationId = GetRowColumn(dr, "OrganizationId", 0);
                    item.ProfileName    = GetRowColumn(dr, "Name", "missing");

                    item.Description = GetRowColumn(dr, "Description", "");

                    string rowId = GetRowColumn(dr, "RowId");
                    item.RowId          = new Guid(rowId);
                    item.CTID           = GetRowColumn(dr, "CTID");
                    item.SubjectWebpage = GetRowColumn(dr, "CostDetails", "");


                    list.Add(item);
                }

                return(list);
            }
        }         //
Exemplo n.º 21
0
        public static void MapFromDB(DBEntity from, ThisEntity to,
                                     bool includingProperties = false,
                                     bool includingProfiles   = true,
                                     bool forEditView         = true)
        {
            to.Id            = from.Id;
            to.RowId         = from.RowId;
            to.EntityStateId = ( int )(from.EntityStateId ?? 1);

            to.OrganizationId = (int)(from.OrganizationId ?? 0);

            if (to.OrganizationId > 0)
            {
                //if ( from.Organization != null && from.Organization.Id > 0 )
                //{
                //	//ensure there is no infinite loop
                //	//the following results in an infinite loop
                //	//OrganizationManager.ToMapCommon( from.Organization, to.OwningOrganization, false, false, false, false, false );
                //	//maybe: ToMapForSummary
                //	//OrganizationManager.ToMapForSummary( from.Organization, to.OwningOrganization );

                //	to.OwningOrganization = OrganizationManager.GetForSummary( to.OrganizationId );
                //	to.OwningAgentUid = to.OwningOrganization.RowId;
                //} else
                {
                    to.OwningOrganization = OrganizationManager.GetForSummary(to.OrganizationId);
                    to.OwningAgentUid     = to.OwningOrganization.RowId;
                }

                to.OrganizationName = to.OwningOrganization.Name;
                to.OwningAgentUid   = to.OwningOrganization.RowId;
            }

            to.Name        = from.Name;
            to.Description = from.Description == null ? "" : from.Description;

            to.CTID = from.CTID;
            to.CredentialRegistryId = from.CredentialRegistryId;

            to.SubjectWebpage = from.SubjectWebpage;

            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }

            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }

            //get common conditions
            //TODO - determine what to return for edit vs non-edit states
            //if ( forEditView )
            //	to.CommonConditions = Entity_CommonConditionManager.GetAll( to.RowId, forEditView );
            //else
            //	to.CommonConditions = Entity_CommonConditionManager.GetAll( to.RowId, forEditView );

            //get entry conditions
            List <ConditionProfile> list = Entity_ConditionProfileManager.GetAll(to.RowId, true);

            //??actions
            if (list != null && list.Count > 0)
            {
                foreach (ConditionProfile item in list)
                {
                    to.ConditionProfiles.Add(item);

                    if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Requirement)
                    {
                        to.Requires.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Recommendation)
                    {
                        to.Recommends.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_EntryCondition)
                    {
                        to.EntryCondition.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Corequisite)
                    {
                        to.Corequisite.Add(item);
                    }
                    else if (item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_Renewal)
                    {
                        to.Renewal.Add(item);
                    }
                    else
                    {
                        EmailManager.NotifyAdmin("Unexpected Condition Profile for Condition Manifest", string.Format("conditionManifestId: {0}, ConditionProfileTypeId: {1}", to.Id, item.ConnectionProfileTypeId));
                    }
                }
                //LoggingHelper.DoTrace( 5, "Unexpected Condition Profiles found for Condition Manifest. " + string.Format( "conditionManifestId: {0}, Count: {1}", to.Id, list.Count ) );
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Persist ConditionManifest
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="parentUid"></param>
        /// <param name="userId"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity, ref SaveStatus status)
        {
            bool isValid = true;

            //will not have a parent Guid - should be the entity.OwningAgentUid
            //Guid parentUid = entity.OwningAgentUid;

            if (!IsValidGuid(entity.OwningAgentUid))
            {
                status.AddError("Error: the parent identifier was not provided.");
                return(false);
            }

            int count = 0;

            DBEntity efEntity    = new DBEntity();
            int      parentOrgId = 0;

            Guid   condtionManifestParentUid = new Guid();
            Entity parent = EntityManager.GetEntity(entity.OwningAgentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError("Error - the entity for the parent organization was not found.");
                return(false);
            }
            if (parent.EntityTypeId == CodesManager.ENTITY_TYPE_ORGANIZATION)
            {
                parentOrgId = parent.EntityBaseId;
                condtionManifestParentUid = parent.EntityUid;
                //no common condition in this context
            }


            using (var context = new EntityContext())
            {
                try
                {
                    bool isEmpty = false;

                    if (ValidateProfile(entity, ref isEmpty, ref status) == false)
                    {
                        return(false);
                    }
                    if (isEmpty)
                    {
                        status.AddWarning("The Condition Manifest Profile is empty. ");
                        return(false);
                    }

                    if (entity.Id == 0)
                    {
                        //add
                        efEntity = new DBEntity();
                        MapToDB(entity, efEntity);

                        efEntity.OrganizationId = parentOrgId;
                        efEntity.EntityStateId  = 3;
                        efEntity.Created        = efEntity.LastUpdated = DateTime.Now;

                        if (IsValidGuid(entity.RowId))
                        {
                            efEntity.RowId = entity.RowId;
                        }
                        else
                        {
                            efEntity.RowId = Guid.NewGuid();
                        }

                        context.ConditionManifest.Add(efEntity);
                        count = context.SaveChanges();

                        entity.Id    = efEntity.Id;
                        entity.RowId = efEntity.RowId;
                        if (count == 0)
                        {
                            status.AddError(" Unable to add Condition Manifest Profile");
                        }
                        else
                        {
                            //create the Entity.ConditionManifest
                            //ensure to handle this properly when adding a commonCondition CM to a CM
                            Entity_HasConditionManifest_Add(condtionManifestParentUid, efEntity.Id, ref status);

                            if (!UpdateParts(entity, ref status))
                            {
                                isValid = false;
                            }

                            SiteActivity sa = new SiteActivity()
                            {
                                ActivityType     = "ConditionManifest",
                                Activity         = "Import",
                                Event            = "Add",
                                Comment          = string.Format("ConditionManifest was added by the import. Name: {0}, SWP: {1}", entity.Name, entity.SubjectWebpage),
                                ActivityObjectId = entity.Id
                            };
                            new ActivityManager().SiteActivityAdd(sa);
                            // a trigger is used to create the entity Object.
                        }
                    }
                    else
                    {
                        efEntity = context.ConditionManifest.SingleOrDefault(s => s.Id == entity.Id);
                        if (efEntity != null && efEntity.Id > 0)
                        {
                            //delete the entity and re-add
                            //Entity e = new Entity()
                            //{
                            //	EntityBaseId = efEntity.Id,
                            //	EntityTypeId = CodesManager.ENTITY_TYPE_CONDITION_MANIFEST,
                            //	EntityType = "ConditionManifest",
                            //	EntityUid = efEntity.RowId,
                            //	EntityBaseName = efEntity.Name
                            //};
                            //if ( entityMgr.ResetEntity( e, ref statusMessage ) )
                            //{

                            //}

                            entity.RowId = efEntity.RowId;
                            //update
                            MapToDB(entity, efEntity);
                            //assume and validate, that if we get here we have a full record
                            if ((efEntity.EntityStateId ?? 1) == 1)
                            {
                                efEntity.EntityStateId = 3;
                            }

                            //has changed?
                            if (HasStateChanged(context))
                            {
                                efEntity.LastUpdated = System.DateTime.Now;

                                count = context.SaveChanges();
                            }
                            else
                            {
                                //update entity.LastUpdated - assuming there has to have been some change in related data
                                new EntityManager().UpdateModifiedDate(entity.RowId, ref status);
                            }

                            if (!UpdateParts(entity, ref status))
                            {
                                isValid = false;
                            }

                            SiteActivity sa = new SiteActivity()
                            {
                                ActivityType     = "ConditionManifest",
                                Activity         = "Import",
                                Event            = "Update",
                                Comment          = string.Format("ConditionManifest was updated by the import. Name: {0}, SWP: {1}", entity.Name, entity.SubjectWebpage),
                                ActivityObjectId = entity.Id
                            };
                            new ActivityManager().SiteActivityAdd(sa);
                        }
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
                {
                    string message = HandleDBValidationError(dbex, thisClassName + ".Save() ", "ConditionManifest");
                    status.AddError("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(dbex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                    isValid = false;
                }
                catch (Exception ex)
                {
                    string message = FormatExceptions(ex);
                    status.AddError("Error - the save was not successful. " + message);
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Save(), Parent: {0} ({1})", parent.EntityBaseName, parent.EntityBaseId));
                    isValid = false;
                }
            }



            return(isValid);
        }