示例#1
0
        /// <summary>
        /// Get a basic PathwaySet by CTID
        /// </summary>
        /// <param name="ctid"></param>
        /// <returns></returns>
        public static ThisEntity GetByCtid(string ctid)
        {
            PathwaySet entity = new PathwaySet();

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

            using (var context = new EntityContext())
            {
                context.Configuration.LazyLoadingEnabled = false;
                EM.PathwaySet item = context.PathwaySet
                                     .FirstOrDefault(s => s.CTID.ToLower() == ctid.ToLower() &&
                                                     s.EntityStateId > 1
                                                     );

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

            return(entity);
        }
示例#2
0
        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            to.Id = from.Id;
            if (to.Id < 1)
            {
            }
            else
            {
            }
            //don't map rowId, ctid, or dates as not on form
            //to.RowId = from.RowId;
            to.Name = from.Name;
            to.CTID = from.CTID;
            if (!string.IsNullOrWhiteSpace(from.CredentialRegistryId))
            {
                //this may not exist if added as pending?
                to.CredentialRegistryId = from.CredentialRegistryId ?? "";
            }
            to.EntityStateId  = from.EntityStateId > 0 ? from.EntityStateId : 3;
            to.Description    = from.Description;
            to.SubjectWebpage = from.SubjectWebpage;

            if (from.OwningAgentUid != null)
            {
                to.OwningAgentUid = ( Guid )from.OwningAgentUid;
            }
        }
示例#3
0
        public bool Delete(int Id, ref string statusMessage)
        {
            bool isValid = false;

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

                if (efEntity != null && efEntity.Id > 0)
                {
                    context.PathwaySet.Remove(efEntity);
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        isValid = true;
                    }
                }
                else
                {
                    statusMessage = "Error - delete failed, as record was not found.";
                }
            }

            return(isValid);
        }
示例#4
0
        public static void MapFromDB(DBEntity input, ThisEntity output, bool includingPathways = false)
        {
            output.Id             = input.Id;
            output.RowId          = input.RowId;
            output.CTID           = input.CTID;
            output.Name           = input.Name;
            output.Description    = input.Description;
            output.SubjectWebpage = input.SubjectWebpage;
            output.EntityStateId  = (int)(input.EntityStateId ?? 2);
            //TODO - get pathways
            if (includingPathways)
            {
                output.Pathways   = Entity_PathwayManager.GetAll(output.RowId, true);
                output.HasPathway = output.Pathways.Select(m => m.CTID).ToList();
            }
            else
            {
                //really only need the pathway ids for publishing - also ctid
                //might just get the lite versions of a pathway?
                output.Pathways = Entity_PathwayManager.GetAll(output.RowId, false);
                //always collect for now
                output.HasPathway = output.Pathways.Select(m => m.CTID).ToList();
            }

            if (IsGuidValid(input.OwningAgentUid))
            {
                output.OwningAgentUid     = ( Guid )input.OwningAgentUid;
                output.OwningOrganization = OrganizationManager.GetForSummary(output.OwningAgentUid);

                //get roles
                OrganizationRoleProfile orp = Entity_AgentRelationshipManager.AgentEntityRole_GetAsEnumerationFromCSV(output.RowId, output.OwningAgentUid);
                output.OwnerRoles = orp.AgentRole;
            }
            //
            output.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration(output.RowId, true);

            //confustion over OrganizationRole and OwnerRoles (enum)!!!
            //to.OrganizationRole = Entity_AgentRelationshipManager.AgentEntityRole_GetAll_ToEnumeration( to.RowId, true );
            output.CredentialRegistryId = input.CredentialRegistryId;

            if (IsValidDate(input.Created))
            {
                output.Created = ( DateTime )input.Created;
            }
            if (IsValidDate(input.LastUpdated))
            {
                output.LastUpdated = ( DateTime )input.LastUpdated;
            }

            var relatedEntity = EntityManager.GetEntity(output.RowId, false);

            if (relatedEntity != null && relatedEntity.Id > 0)
            {
                output.EntityLastUpdated = relatedEntity.LastUpdated;
            }
        }
示例#5
0
        /// <summary>
        /// Get a  pathway set
        /// if includingPathways is false, only a list of pathway ids is returned
        /// </summary>
        /// <param name="id"></param>
        /// <param name="includingPathways"></param>
        /// <returns></returns>
        public static ThisEntity Get(int id, bool includingPathways = true)
        {
            ThisEntity entity = new ThisEntity();

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

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

            return(entity);
        }
示例#6
0
        /// <summary>
        /// add a PathwaySet
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity, ref SaveStatus status)
        {
            bool isValid  = true;
            var  efEntity = new DBEntity();

            using (var context = new EntityContext())
            {
                try
                {
                    //messages = new List<string>();
                    if (ValidateProfile(entity, ref status) == false)
                    {
                        return(false);
                    }


                    if (entity.Id == 0)
                    {
                        //entity.StatusId = 1;
                        MapToDB(entity, efEntity);

                        if (entity.RowId == null || entity.RowId == Guid.Empty)
                        {
                            efEntity.RowId = entity.RowId = Guid.NewGuid();
                        }
                        else
                        {
                            efEntity.RowId = entity.RowId;
                        }

                        if (IsValidDate(status.EnvelopeCreatedDate))
                        {
                            efEntity.Created     = status.LocalCreatedDate;
                            efEntity.LastUpdated = status.LocalCreatedDate;
                        }
                        else
                        {
                            efEntity.Created     = System.DateTime.Now;
                            efEntity.LastUpdated = System.DateTime.Now;
                        }

                        context.PathwaySet.Add(efEntity);

                        // submit the change to database
                        int count = context.SaveChanges();
                        if (count > 0)
                        {
                            entity.Id = efEntity.Id;
                            //add log entry
                            SiteActivity sa = new SiteActivity()
                            {
                                ActivityType     = "PathwaySet",
                                Activity         = "Import",
                                Event            = "Add",
                                Comment          = string.Format("Full PathwaySet was added by the import. Name: {0}, SWP: {1}", entity.Name, entity.SubjectWebpage),
                                ActivityObjectId = entity.Id
                            };
                            new ActivityManager().SiteActivityAdd(sa);
                            UpdateParts(entity, ref status);

                            return(true);
                        }
                        else
                        {
                            //?no info on error
                            status.AddError("Error - the profile was not saved. ");
                            string message = string.Format("PathwayManager.Add Failed. Attempted to add a PathwaySet. The process appeared to not work, but was not an exception, so we have no message, or no clue.PathwaySet. PathwaySet: {0}, createdById: {1}", entity.Name, entity.CreatedById);
                            EmailManager.NotifyAdmin(thisClassName + ".Add Failed", message);
                        }
                    }
                    else
                    {
                        efEntity = context.PathwaySet
                                   .SingleOrDefault(s => s.Id == entity.Id);

                        if (efEntity != null && efEntity.Id > 0)
                        {
                            //for updates, chances are some fields will not be in interface, don't map these (ie created stuff)
                            MapToDB(entity, efEntity);
                            if (IsValidDate(status.EnvelopeCreatedDate) && status.LocalCreatedDate < efEntity.Created)
                            {
                                efEntity.Created = status.LocalCreatedDate;
                            }
                            if (IsValidDate(status.EnvelopeUpdatedDate) && status.LocalUpdatedDate != efEntity.LastUpdated)
                            {
                                efEntity.LastUpdated = status.LocalUpdatedDate;
                            }
                            //has changed?
                            if (HasStateChanged(context))
                            {
                                if (IsValidDate(status.EnvelopeUpdatedDate))
                                {
                                    efEntity.LastUpdated = status.LocalUpdatedDate;
                                }
                                else
                                {
                                    efEntity.LastUpdated = DateTime.Now;
                                }
                                int count = context.SaveChanges();
                                //can be zero if no data changed
                                if (count >= 0)
                                {
                                    isValid = true;
                                }
                                else
                                {
                                    //?no info on error
                                    status.AddError("Error - the update was not successful. ");
                                    string message = string.Format(thisClassName + ".Save Failed", "Attempted to update a PathwaySet. The process appeared to not work, but was not an exception, so we have no message, or no clue. PathwayId: {0}, Id: {1}, updatedById: {2}", entity.Id, entity.Id, entity.LastUpdatedById);
                                    EmailManager.NotifyAdmin(thisClassName + ". Pathway_Update Failed", message);
                                }
                            }
                            //continue with parts regardless
                            UpdateParts(entity, ref status);
                        }
                        else
                        {
                            status.AddError("Error - update failed, as record was not found.");
                        }
                    }
                }
                //catch ( System.Data.Entity.Validation.DBEntityValidationException dbex )
                //{
                //	//LoggingHelper.LogError( dbex, thisClassName + string.Format( ".ContentAdd() DBEntityValidationException, Type:{0}", entity.TypeId ) );
                //	string message = thisClassName + string.Format( ".Pathway_Add() DBEntityValidationException, PathwayId: {0}", PathwaySet.Id );
                //	foreach ( var eve in dbex.EntityValidationErrors )
                //	{
                //		message += string.Format( "\rEntity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                //			eve.Entry.Entity.GetType().Name, eve.Entry.State );
                //		foreach ( var ve in eve.ValidationErrors )
                //		{
                //			message += string.Format( "- Property: \"{0}\", Error: \"{1}\"",
                //				ve.PropertyName, ve.ErrorMessage );
                //		}

                //		LoggingHelper.LogError( message, true );
                //	}
                //}
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Save(), PathwaySet: '{0}'", entity.Name));
                    status.AddError(string.Format("PathwayManager.Save Failed. PathwaySet: {0}, createdById: {1}, Error: {2}", entity.Name, entity.CreatedById, ex.Message));
                    isValid = false;
                }
            }

            return(isValid);
        }
示例#7
0
        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(envelopeId))
            {
                envelopeId = "SKIP ME";
            }
            if (string.IsNullOrWhiteSpace(ctid))
            {
                ctid = "SKIP ME";
            }
            int  orgId  = 0;
            Guid orgUid = new Guid();

            using (var context = new EntityContext())
            {
                try
                {
                    context.Configuration.LazyLoadingEnabled = false;
                    DBEntity efEntity = context.PathwaySet
                                        .FirstOrDefault(s => s.CredentialRegistryId == envelopeId ||
                                                        (s.CTID == ctid)
                                                        );

                    if (efEntity != null && efEntity.Id > 0)
                    {
                        Guid rowId = efEntity.RowId;
                        if (IsValidGuid(efEntity.OwningAgentUid))
                        {
                            Organization org = OrganizationManager.GetBasics(( Guid )efEntity.OwningAgentUid);
                            orgId  = org.Id;
                            orgUid = org.RowId;
                        }
                        //need to remove from Entity.
                        //-using before delete trigger - verify won't have RI issues
                        string msg = string.Format(" PathwaySet. Id: {0}, Name: {1}, Ctid: {2}.", efEntity.Id, efEntity.Name, efEntity.CTID);
                        //18-04-05 mparsons - change to set inactive, and notify - seems to have been some incorrect deletes
                        //context.Pathway.Remove( efEntity );
                        efEntity.EntityStateId = 0;
                        efEntity.LastUpdated   = System.DateTime.Now;
                        int count = context.SaveChanges();
                        if (count > 0)
                        {
                            new ActivityManager().SiteActivityAdd(new SiteActivity()
                            {
                                ActivityType     = "PathwaySet",
                                Activity         = "Import",
                                Event            = "Delete",
                                Comment          = msg,
                                ActivityObjectId = efEntity.Id
                            });
                            isValid = true;
                            //add pending request
                            List <String> messages = new List <string>();
                            new SearchPendingReindexManager().AddDeleteRequest(CodesManager.ENTITY_TYPE_PATHWAY_SET, efEntity.Id, ref messages);
                            //mark owning org for updates (actually should be covered by ReindexAgentForDeletedArtifact
                            new SearchPendingReindexManager().Add(CodesManager.ENTITY_TYPE_ORGANIZATION, orgId, 1, ref messages);

                            //delete all relationships
                            workIT.Models.SaveStatus        status = new SaveStatus();
                            Entity_AgentRelationshipManager earmgr = new Entity_AgentRelationshipManager();
                            earmgr.DeleteAll(rowId, ref status);
                            //also check for any relationships
                            //There could be other orgs from relationships to be reindexed as well!

                            //also check for any relationships
                            new Entity_AgentRelationshipManager().ReindexAgentForDeletedArtifact(orgUid);
                        }
                    }
                    else
                    {
                        statusMessage = thisClassName + ".Delete() Warning No action taken, as the record was not found.";
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + ".Delete(envelopeId)");
                    isValid       = false;
                    statusMessage = FormatExceptions(ex);
                    if (statusMessage.ToLower().IndexOf("the delete statement conflicted with the reference constraint") > -1)
                    {
                        statusMessage = "Error: this PathwaySet cannot be deleted as it is being referenced by other items, such as roles or credentials. These associations must be removed before this PathwaySet can be deleted.";
                    }
                }
            }
            return(isValid);
        }