Exemplo n.º 1
0
        }        //

        //public static void MapToDB( ThisEntity from, DBEntity to )
        //{
        //	//want to ensure fields from create are not wiped
        //	if ( to.Id == 0 )
        //	{
        //		if ( IsValidDate( from.Created ) )
        //			to.Created = from.Created;
        //	}
        //	to.Id = from.Id;
        //	to.CredentialId = from.CredentialId;
        //	to.RelationshipTypeId = from.RelationshipTypeId;
        //	to.EntityId = from.ParentId;

        //}
        public static void MapFromDB(DBEntity from, ThisEntity to, bool isForDetailPageCondition = false)
        {
            to.Id                 = from.Id;
            to.CredentialId       = from.CredentialId;
            to.ParentId           = from.EntityId;
            to.RelationshipTypeId = from.RelationshipTypeId;

            //to.Credential = from.Credential;
            to.Credential = new Credential();
            if (from.Credential != null && from.Credential.Id > 0)
            {
                to.ProfileSummary = from.Credential.Name;
                CredentialMinimumMap(from.Credential, to.Credential);
            }
            else
            {
                to.Credential = CredentialManager.GetBasic(to.CredentialId);
                if (to.Credential != null && to.Credential.Id > 0)
                {
                    to.ProfileSummary = to.Credential.Name;
                    //CredentialMinimumMap( from.Credential, to.Credential );
                }
                else
                {
                    to.ProfileSummary = string.Format("Credential ({0}) has not been downloaded", to.CredentialId);
                    LoggingHelper.DoTrace(1, string.Format(thisClassName + ".MapFromDB() Credential ({0}) has not been downloaded. ParentEntityId: {1}, Entity.CredentialId: {2}", to.CredentialId, to.ParentId, to.Id));
                }
            }

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

        public static void MapToDB(ThisEntity from, DBEntity to)
        {
            //want to ensure fields from create are not wiped
            if (to.Id == 0)
            {
                if (IsValidDate(from.Created))
                {
                    to.Created = from.Created;
                }
            }
            to.Id           = from.Id;
            to.CredentialId = from.CredentialId;
            to.EntityId     = from.ParentId;
        }
Exemplo n.º 3
0
        /// <summary>
        /// get all the base credentials for an EntityCredential
        /// Uses the parent Guid to retrieve the related Entity, then uses the EntityId to retrieve the child objects.
        /// </summary>
        /// <param name="parentUid"></param>
        /// <returns></returns>
        public static List <Credential> GetAll(Guid parentUid, int relationshipTypeId = 1, bool isForDetailPageCondition = false)
        {
            ThisEntity        entity = new ThisEntity();
            List <Credential> list   = new List <Credential>();
            Entity            parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    //commented out in order to get more data for detail page
                    //context.Configuration.LazyLoadingEnabled = false;

                    List <DBEntity> results = context.Entity_Credential
                                              .Where(s => s.EntityId == parent.Id && s.RelationshipTypeId == relationshipTypeId)
                                              .OrderBy(s => s.Id)
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            entity = new ThisEntity();
                            if (item.Credential != null &&
                                item.Credential.Id > 0 &&
                                item.Credential.EntityStateId > 1)
                            {
                                MapFromDB(item, entity, isForDetailPageCondition);

                                list.Add(entity.Credential);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + string.Format(".GetAll. Guid: {0}, parentType: {1} ({2}), ", parentUid, parent.EntityType, parent.EntityBaseId));
            }
            return(list);
        }        //