示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// Delete a Condition Manifest, and related Entity
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Delete(int Id, ref string statusMessage)
        {
            bool isValid = false;

            if (Id == 0)
            {
                statusMessage = "Error - missing an identifier for the ConditionManifest";
                return(false);
            }
            using (var context = new EntityContext())
            {
                try
                {
                    DBEntity efEntity = context.ConditionManifest
                                        .SingleOrDefault(s => s.Id == Id);

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        Guid rowId = efEntity.RowId;

                        context.ConditionManifest.Remove(efEntity);
                        int count = context.SaveChanges();
                        if (count > 0)
                        {
                            isValid = true;
                            //do with trigger now
                            //new EntityManager().Delete( rowId, ref statusMessage );
                        }
                    }
                    else
                    {
                        statusMessage = "Error - delete failed, as record was not found.";
                    }
                }
                catch (Exception ex)
                {
                    statusMessage = FormatExceptions(ex);
                    LoggingHelper.LogError(ex, thisClassName + ".Delete()");

                    if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1)
                    {
                        statusMessage = "Error: this Condition Manifest cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this Condition Manifest can be deleted.";
                    }
                }
            }

            return(isValid);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
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);
        }
示例#10
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);
        }
示例#11
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);
        }
示例#12
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 ) );
            }
        }
示例#13
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);
        }
示例#14
0
        /// <summary>
        /// Delete by envelopeId
        /// </summary>
        /// <param name="envelopeId"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Delete(string envelopeId, string ctid, ref string statusMessage)
        {
            bool isValid = true;

            if ((string.IsNullOrWhiteSpace(envelopeId) || !IsValidGuid(envelopeId)) &&
                string.IsNullOrWhiteSpace(ctid))
            {
                statusMessage = thisClassName + ".Delete() Error - a valid envelope identifier must be provided - OR  valid CTID";
                return(false);
            }
            if (string.IsNullOrWhiteSpace(ctid))
            {
                ctid = "SKIP ME";
            }
            using (var context = new EntityContext())
            {
                try
                {
                    context.Configuration.LazyLoadingEnabled = false;
                    DBEntity efEntity = context.ConditionManifest
                                        .FirstOrDefault(s => s.CredentialRegistryId == envelopeId ||
                                                        (s.CTID == ctid)
                                                        );

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        Guid rowId = efEntity.RowId;
                        int  orgId = efEntity.OrganizationId ?? 0;
                        //need to remove from Entity.
                        //-using before delete trigger - verify won't have RI issues
                        string msg = string.Format(" ConditionManifest. Id: {0}, Name: {1}, Ctid: {2}, EnvelopeId: {3}", efEntity.Id, efEntity.Name, efEntity.CTID, envelopeId);
                        //leaving as a delete
                        context.ConditionManifest.Remove(efEntity);
                        //efEntity.EntityStateId = 0;
                        //efEntity.LastUpdated = System.DateTime.Now;

                        int count = context.SaveChanges();
                        if (count >= 0)
                        {
                            new ActivityManager().SiteActivityAdd(new SiteActivity()
                            {
                                ActivityType = "ConditionManifest",
                                Activity     = "Import",
                                Event        = "Delete",
                                Comment      = msg
                            });
                            isValid = true;
                        }
                        List <String> messages = new List <string>();
                        //mark owning org for updates
                        new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, orgId, 1, ref messages);
                    }
                    else
                    {
                        statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found.";
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)");
                    statusMessage = FormatExceptions(ex);
                    isValid       = false;
                    if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1)
                    {
                        statusMessage = thisClassName + "Error: this record cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this assessment can be deleted.";
                    }
                }
            }
            return(isValid);
        }