}        //

        public static int GetAllTotal(Guid parentUid)
        {
            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(0);
            }
            //bool includingItems = true;
            try
            {
                using (var context = new EntityContext())
                {
                    context.Configuration.LazyLoadingEnabled = false;

                    List <DBEntity> results = context.Entity_VerificationProfile
                                              .Where(s => s.EntityId == parent.Id)
                                              .OrderBy(s => s.Id)
                                              .ToList();
                    if (results != null && results.Any())
                    {
                        return(results.Count);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAll");
            }
            return(0);
        }        //
Ejemplo n.º 2
0
        public static Entity GetEntity(int entityTypeId, int entityBaseId)
        {
            Entity entity = new Entity();

            using (var context = new EntityContext())
            {
                DBentity item = context.Entity
                                .FirstOrDefault(s => s.EntityTypeId == entityTypeId &&
                                                s.EntityBaseId == entityBaseId);

                if (item != null && item.Id > 0)
                {
                    entity.Id           = item.Id;
                    entity.EntityTypeId = item.EntityTypeId;
                    //not why this was commented. Reusing with care
                    if (item.Codes_EntityTypes != null)
                    {
                        entity.EntityType = item.Codes_EntityTypes.Title;
                    }
                    else
                    {
                        entity.EntityType = GetEntityType(entity.EntityTypeId);
                    }
                    entity.EntityUid      = item.EntityUid;
                    entity.EntityBaseId   = item.EntityBaseId ?? 0;
                    entity.EntityBaseName = item.EntityBaseName;
                    entity.Created        = ( DateTime )item.Created;
                }
                return(entity);
            }
        }
Ejemplo n.º 3
0
        public bool DeleteAll(Entity parent, ref SaveStatus status)
        {
            bool isValid = true;

            //Entity parent = EntityManager.GetEntity( parentUid );
            if (parent == null || parent.Id == 0)
            {
                status.AddError(thisClassName + ". Error - the provided target parent entity was not provided.");
                return(false);
            }
            using (var context = new EntityContext())
            {
                context.Entity_IdentifierValue.RemoveRange(context.Entity_IdentifierValue.Where(s => s.EntityId == parent.Id));
                int count = context.SaveChanges();
                if (count > 0)
                {
                    isValid = true;
                }
                else
                {
                    //if doing a delete on spec, may not have been any properties
                }
            }

            return(isValid);
        }
        }        //

        /// <summary>
        /// Get a competency record
        /// </summary>
        /// <param name="profileId"></param>
        /// <returns></returns>
        public static ThisEntity Get(int profileId)
        {
            ThisEntity entity = new ThisEntity();

            if (profileId == 0)
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    DBEntity item = context.Reference_Frameworks
                                    .SingleOrDefault(s => s.Id == profileId);

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //
        /// <summary>
        /// Delete all profiles for parent
        /// </summary>
        /// <param name="dataSetProfileId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool DeleteAll(int dataSetProfileId, ref List <string> messages)
        {
            bool isValid = true;
            int  count   = 0;

            if (dataSetProfileId < 1)
            {
                messages.Add(thisClassName + "DeleteAll. Error - the dataSetProfileId was not provided.");
                return(false);
            }
            using (var context = new EntityContext())
            {
                var results = context.DataSetTimeFrame
                              .Where(s => s.DataSetProfileId == dataSetProfileId)
                              .ToList();
                if (results == null || results.Count == 0)
                {
                    return(true);
                }

                foreach (var item in results)
                {
                    //need to remove DataProfile
                    new DataProfileManager().DeleteAll(item.Id, ref messages);

                    context.DataSetTimeFrame.Remove(item);
                    count = context.SaveChanges();
                    if (count > 0)
                    {
                    }
                }
            }

            return(isValid);
        }
        public bool UpdateModifiedDate(Guid entityUid, ref SaveStatus status)
        {
            bool isValid = false;

            if (!IsValidGuid(entityUid))
            {
                status.AddError(thisClassName + ".UpdateModifiedDate(). Error - missing a valid identifier for the Entity");
                return(false);
            }
            using (var context = new EntityContext())
            {
                DBentity efEntity = context.Entity
                                    .FirstOrDefault(s => s.EntityUid == entityUid);

                if (efEntity != null && efEntity.Id > 0)
                {
                    efEntity.LastUpdated = DateTime.Now;
                    int count = context.SaveChanges();
                    if (count >= 0)
                    {
                        isValid = true;
                        LoggingHelper.DoTrace(7, thisClassName + string.Format(".UpdateModifiedDate - update last updated for TypeId: {0}, BaseId: {1}", efEntity.EntityTypeId, efEntity.EntityBaseId));
                    }
                }
                else
                {
                    status.AddError(thisClassName + ".UpdateModifiedDate(). Error - Entity  was not found.");
                    LoggingHelper.LogError(thisClassName + string.Format(".UpdateModifiedDate - record was not found. entityUid: {0}", entityUid), true);
                }
            }

            return(isValid);
        }///
Ejemplo n.º 7
0
        }        //

        public bool SetImport_PendingRequestHandled(int recordId, bool importWasSuccessful)
        {
            bool isValid = false;

            if (recordId <= 0)
            {
                return(false);
            }
            using (var context = new EntityContext())
            {
                var efEntity = context.Import_PendingRequest
                               .FirstOrDefault(s => s.Id == recordId);

                if (efEntity != null && efEntity.Id > 0)
                {
                    efEntity.WasProcessed        = true;
                    efEntity.ImportWasSuccessful = importWasSuccessful;
                    if (importWasSuccessful)
                    {
                        efEntity.ImportedDate = DateTime.Now;
                    }
                    int count = context.SaveChanges();
                    if (count >= 0)
                    {
                        isValid = true;
                    }
                }
                else
                {
                    LoggingHelper.LogError(thisClassName + string.Format(".SetImport_PendingRequestHandled - record was not found. recordId: {0}", recordId), true);
                }
            }

            return(isValid);
        }        ///
        public static List <ThisEntity> GetAllPendingReindex(ref List <String> messages, int entityTypeId = 0)
        {
            List <ThisEntity> list   = new List <ThisEntity>();
            ThisEntity        entity = new ThisEntity();

            using (var context = new EntityContext())
            {
                List <DBEntity> results = context.SearchPendingReindex
                                          .Where(s => s.IsUpdateOrDeleteTypeId == 1 && s.StatusId == 1 &&
                                                 (entityTypeId == 0 || s.EntityTypeId == entityTypeId)
                                                 )
                                          .OrderBy(s => s.EntityTypeId).ThenBy(s => s.Created)
                                          .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (var item in results)
                    {
                        entity = new ThisEntity();
                        MapFromDB(item, entity, true);
                        list.Add(entity);
                    }
                }
            }

            return(list);
        }
        /// <summary>
        /// Delete a JurisdictionProfile
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Delete(int Id, ref string statusMessage)
        {
            bool isValid = false;

            using (var context = new EntityContext())
            {
                if (Id == 0)
                {
                    statusMessage = "Error - missing an identifier for the JurisdictionProfile";
                    return(false);
                }

                DBEntity efEntity =
                    context.Entity_JurisdictionProfile.SingleOrDefault(s => s.Id == Id);
                if (efEntity != null && efEntity.Id > 0)
                {
                    context.Entity_JurisdictionProfile.Remove(efEntity);
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        isValid = true;
                    }
                }
                else
                {
                    statusMessage = string.Format("JurisdictionProfile record was not found: {0}", Id);
                    isValid       = false;
                }
            }

            return(isValid);
        }
Ejemplo n.º 10
0
        }        //

        public static List <ThisEntity> GetAllForList(Guid parentUid)
        {
            ThisEntity        row      = new ThisEntity();
            DurationItem      duration = new DurationItem();
            List <ThisEntity> profiles = new List <ThisEntity>();
            Entity            parent   = EntityManager.GetEntity(parentUid);

            using (var context = new EntityContext())
            {
                List <DBEntity> results = context.Entity_CostProfile
                                          .Where(s => s.EntityId == parent.Id)
                                          .OrderBy(s => s.Id)
                                          .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (DBEntity item in results)
                    {
                        row = new ThisEntity();
                        MapFromDB(item, row, false);
                        profiles.Add(row);
                    }
                }
                return(profiles);
            }
        }        //
        public static bool IsParentBeingAddedAsChildToItself(int profileId, int childId, int childEntityTypeId)
        {
            bool isOk = false;

            using (var context = new EntityContext())
            {
                //get the profile that is the parent of the child
                DBEntity efEntity = context.Entity_ProcessProfile
                                    .SingleOrDefault(s => s.Id == profileId);

                if (efEntity != null &&
                    efEntity.Id > 0 &&
                    efEntity.Entity != null)
                {
                    //check if the parent entity is the same one being added as a child
                    if (efEntity.Entity.EntityTypeId == childEntityTypeId &&
                        efEntity.Entity.EntityBaseId == childId)
                    {
                        return(true);
                    }
                }
            }

            return(isOk);
        }
Ejemplo n.º 12
0
        }        //

        /// <summary>
        /// Get a single DurationProfile by integer Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        ///
        public static WM.DurationItem GetRenewalDuration(Guid parentUid)
        {
            WM.DurationItem duration = new WM.DurationItem();
            ThisEntity      profile  = new ThisEntity();
            Entity          parent   = EntityManager.GetEntity(parentUid);

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

            using (var context = new EntityContext())
            {
                List <EM.Entity_DurationProfile> results = context.Entity_DurationProfile
                                                           .Where(s => s.EntityId == parent.Id &&
                                                                  (s.TypeId == 3))
                                                           .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (EM.Entity_DurationProfile item in results)
                    {
                        MapFromDB(item, duration);
                        break;
                    }
                }
                return(duration);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Retrieve and fill duration profiles for parent entity
        /// </summary>
        /// <param name="parentUid"></param>
        public static List <ThisEntity> GetAll(Guid parentUid, int typeId = 0)
        {
            ThisEntity row = new ThisEntity();

            WM.DurationItem   duration = new WM.DurationItem();
            List <ThisEntity> profiles = new List <ThisEntity>();
            Entity            parent   = EntityManager.GetEntity(parentUid);

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

            using (var context = new EntityContext())
            {
                List <EM.Entity_DurationProfile> results = context.Entity_DurationProfile
                                                           .Where(s => s.EntityId == parent.Id &&
                                                                  ((typeId == 0 && s.TypeId < 3) || s.TypeId == typeId))
                                                           .OrderBy(s => s.Id)
                                                           .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (EM.Entity_DurationProfile item in results)
                    {
                        row = new ThisEntity();
                        MapFromDB(item, row);
                        profiles.Add(row);
                    }
                }
                return(profiles);
            }
        }        //
Ejemplo n.º 14
0
        public void AssignDurationSummary(  )
        {
            ThisEntity row = new ThisEntity();

            using (var context = new EntityContext())
            {
                List <EM.Entity_DurationProfile> results = context.Entity_DurationProfile
                                                           .OrderBy(s => s.Id)
                                                           .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (EM.Entity_DurationProfile item in results)
                    {
                        row = new ThisEntity();
                        MapFromDB(item, row);
                        if (row.ExactDuration.HasValue || row.IsRange)
                        {
                            item.DurationSummary = row.DurationSummary;

                            if (HasStateChanged(context))
                            {
                                //note: testing - the latter may be true if the child has changed - but shouldn't as the mapping only updates the parent
                                //item.LastUpdated = System.DateTime.Now;
                                context.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
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);
        }
        /// <summary>
        /// get all related JurisdictionProfiles for the parent
        /// </summary>
        /// <param name="parentUId"></param>
        /// <returns></returns>
        public static List <ThisEntity> Jurisdiction_GetAll(Guid parentUid, int jprofilePurposeId = 1)
        {
            //efEntity.JProfilePurposeId
            ThisEntity        entity = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();
            int count = 0;

            MC.Entity parent = EntityManager.GetEntity(parentUid);
            if (parent == null || parent.Id == 0)
            {
                return(list);
            }

            using (var context = new EntityContext())
            {
                List <DBEntity> Items = context.Entity_JurisdictionProfile
                                        .Where(s => s.EntityId == parent.Id &&
                                               s.JProfilePurposeId == jprofilePurposeId)
                                        .OrderBy(s => s.Id).ToList();

                if (Items.Count > 0)
                {
                    foreach (DBEntity item in Items)
                    {
                        entity = new ThisEntity();
                        count++;
                        //map and get regions
                        MapFromDB(item, entity, count);
                        list.Add(entity);
                    }
                }
            }

            return(list);
        }
        public static List <CostManifest> GetAllManifestInCommonCostsFor(int CostManifestId, int CostManifestBeingCheckedId)
        {
            List <CostManifest> list = new List <CostManifest>();


            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> results = context.Entity_CommonCost
                                              .Where(s => s.CostManifestId == CostManifestId)
                                              .OrderBy(s => s.EntityId)
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            if (item.Entity.EntityBaseId == CostManifestBeingCheckedId)
                            {
                            }
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAllManifestInCommonCostsFor");
            }
            return(list);
        }
        //

        /// <summary>
        /// get all related GeoCoordinates for the parent
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public static List <MC.GeoCoordinates> GetAll(int parentId, bool isException = false)
        {
            MC.GeoCoordinates        entity = new MC.GeoCoordinates();
            List <MC.GeoCoordinates> list   = new List <MC.GeoCoordinates>();

            if (parentId == 0)
            {
                return(list);
            }

            using (var context = new EntityContext())
            {
                List <EM.GeoCoordinate> Items = context.GeoCoordinate
                                                .Where(s => s.JurisdictionId == parentId && s.IsException == isException)
                                                .OrderBy(s => s.Id).ToList();

                if (Items.Count > 0)
                {
                    foreach (EM.GeoCoordinate item in Items)
                    {
                        entity = new MC.GeoCoordinates();
                        MapFromDB(item, entity);
                        list.Add(entity);
                    }
                }
            }

            return(list);
        }
        public static Entity GetEntity(Guid entityUid, bool includingAllChildren = true)
        {
            Entity entity = new Entity();

            using (var context = new EntityContext())
            {
                if (includingAllChildren == false)
                {
                    context.Configuration.LazyLoadingEnabled = false;
                }
                DBentity item = context.Entity
                                .FirstOrDefault(s => s.EntityUid == entityUid);

                if (item != null && item.Id > 0)
                {
                    entity.Id           = item.Id;
                    entity.EntityTypeId = item.EntityTypeId;

                    //entity.EntityType = item.Codes_EntityType.Title;

                    entity.EntityUid      = item.EntityUid;
                    entity.EntityBaseId   = item.EntityBaseId ?? 0;
                    entity.EntityBaseName = item.EntityBaseName;
                    entity.Created        = (DateTime)item.Created;
                    entity.LastUpdated    = item.LastUpdated != null ?( DateTime )item.LastUpdated : entity.Created;
                }
                return(entity);
            }
        }
Ejemplo n.º 20
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.Entity_FinancialAlignmentProfile
                                .SingleOrDefault(s => s.Id == id);

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

            return(entity);
        }
        }        //

        public static ThisEntity GetByUrl(string frameworkUrl)
        {
            ThisEntity entity = new ThisEntity();

            if (string.IsNullOrWhiteSpace(frameworkUrl))
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    DBEntity item = context.Reference_Frameworks
                                    .FirstOrDefault(s => s.TargetNode == frameworkUrl);

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //
Ejemplo n.º 22
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);
        }
        /// <summary>
        /// Check if the provided framework has already been sync'd.
        /// If not, it will be added.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="userId"></param>
        /// <param name="messages"></param>
        /// <param name="frameworkId"></param>
        /// <returns></returns>
        //public bool HandleFrameworkRequest( CassFramework request,
        //		int userId,
        //		ref SaveStatus status,
        //		ref int frameworkId )
        //{
        //	bool isValid = true;
        //	if ( request == null || string.IsNullOrWhiteSpace(request._IdAndVersion) )
        //	{
        //		status.AddWarning( "The Cass Request doesn't contain a valid Cass Framework class." );
        //		return false;
        //	}
        //	ThisEntity item = Get( request._IdAndVersion );
        //	if (item != null && item.Id > 0)
        //	{
        //		//TODO - do we want to attempt an update - if changed
        //		//		- if we plan to implement a batch refresh of sync'd content, then not necessary
        //		frameworkId = item.Id;
        //		return true;
        //	}
        //	//add the framework...
        //	ThisEntity entity = new ThisEntity();
        //	entity.Name = request.Name;
        //	entity.Description = request.Description;
        //	entity.FrameworkUrl = request.Url;
        //	entity.RepositoryUri = request._IdAndVersion;

        //	//TDO - need owning org - BUT, first person to reference a framework is not necessarily the owner!!!!!
        //	//actually, we may not care here. Eventually get a ctid from CASS
        //	//entity.OwningOrganizationId = 0;

        //	isValid = Save( entity, userId, ref status );
        //	frameworkId = entity.Id;
        //	return isValid;
        //}


        //actually not likely to have a separate list of frameworks
        //public bool SaveList( List<ThisEntity> list, ref SaveStatus status )
        //{
        //	if ( list == null || list.Count == 0 )
        //		return true;

        //	bool isAllValid = true;
        //	foreach ( ThisEntity item in list )
        //	{
        //		Save( item, ref status );
        //	}

        //	return isAllValid;
        //}

        /// <summary>
        /// Add/Update a Reference_Framework
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity,
                         ref SaveStatus status)
        {
            bool isValid = true;
            int  count   = 0;

            DBEntity efEntity = new DBEntity();

            using (var context = new EntityContext())
            {
                if (ValidateProfile(entity, ref status) == false)
                {
                    return(false);
                }

                if (entity.Id == 0)
                {
                    // - need to check for existance
                    DoesItemExist(entity);
                }

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


                    efEntity.Created = DateTime.Now;
                    //efEntity.RowId = Guid.NewGuid();

                    context.Reference_Frameworks.Add(efEntity);

                    count = context.SaveChanges();

                    entity.Id = efEntity.Id;
                    //entity.RowId = efEntity.RowId;
                    if (count == 0)
                    {
                        status.AddWarning(string.Format(" Unable to add Profile: {0} <br\\> ", string.IsNullOrWhiteSpace(entity.Name) ? "no description" : entity.Name));
                    }
                }
                else
                {
                    efEntity = context.Reference_Frameworks.SingleOrDefault(s => s.Id == entity.Id);
                    if (efEntity != null && efEntity.Id > 0)
                    {
                        //entity.RowId = efEntity.RowId;
                        //update
                        MapToDB(entity, efEntity);
                        //has changed?
                        if (HasStateChanged(context))
                        {
                            count = context.SaveChanges();
                        }
                    }
                }
            }
            return(isValid);
        }
Ejemplo n.º 24
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);
        }
        /// <summary>
        /// Get All for a DataSetProfileId
        /// </summary>
        /// <param name="dataSetProfileId"></param>
        /// <returns></returns>
        public static List <ThisEntity> GetAll(int dataSetProfileId)
        {
            var        list   = new List <ThisEntity>();
            ThisEntity entity = new ThisEntity();

            //Guid guid = new Guid( id );
            using (var context = new EntityContext())
            {
                var results = context.DataSetTimeFrame
                              .Where(s => s.DataSetProfileId == dataSetProfileId)
                              .OrderBy(s => s.Created)
                              .ToList();

                if (results != null && results.Count > 0)
                {
                    foreach (var item in results)
                    {
                        entity = new ThisEntity();
                        MapFromDB(item, entity, true);
                        list.Add(entity);
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        public static Entity EntityCacheGet(int entityTypeId, int entityBaseId)
        {
            Entity entity = new Entity();

            using (var context = new EntityContext())
            {
                var item = context.Entity_Cache
                           .FirstOrDefault(s => s.EntityTypeId == entityTypeId &&
                                           s.BaseId == entityBaseId);

                if (item != null && item.Id > 0)
                {
                    entity.Id             = item.Id;
                    entity.EntityTypeId   = item.EntityTypeId;
                    entity.EntityType     = item.EntityType;
                    entity.EntityUid      = item.EntityUid;
                    entity.EntityBaseId   = item.BaseId;
                    entity.EntityBaseName = item.Name;
                    entity.Created        = ( DateTime )item.Created;
                    entity.LastUpdated    = ( DateTime )item.LastUpdated;
                    if (item.parentEntityId > 0)
                    {
                        //NOTE	- can use the included Entity to get more info
                        //		- although may want to turn off lazy loading
                        entity.ParentEntity              = new ThisEntity();
                        entity.ParentEntity.Id           = item.parentEntityId ?? 0;
                        entity.ParentEntity.EntityTypeId = item.parentEntityTypeId ?? 0;
                        entity.ParentEntity.EntityType   = item.parentEntityType;
                        entity.ParentEntity.EntityUid    = ( Guid )item.parentEntityUid;
                    }
                }
                return(entity);
            }
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        public static ThisEntity Get(int parentId, int recordId)
        {
            ThisEntity entity = new ThisEntity();

            if (parentId < 1 || recordId < 1)
            {
                return(entity);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    DBEntity from = context.Entity_IdentifierValue
                                    .SingleOrDefault(s => s.Id == recordId && s.EntityId == parentId);

                    if (from != null && from.Id > 0)
                    {
                        MapFromDB(from, entity);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //
Ejemplo n.º 30
0
        //public static List<ThisEntity> GetAll( ref int totalRecords, int maxRecords = 100 )
        //{
        //	List<ThisEntity> list = new List<ThisEntity>();
        //	ThisEntity entity = new ThisEntity();
        //	using ( var context = new EntityContext() )
        //	{
        //		List<DBEntity> results = context.OccupationProfile
        //					 .Where( s => s.EntityStateId > 2 )
        //					 .OrderBy( s => s.Name )
        //					 .ToList();
        //		if ( results != null && results.Count > 0 )
        //		{
        //			totalRecords = results.Count();

        //			foreach ( DBEntity item in results )
        //			{
        //				entity = new ThisEntity();
        //				MapFromDB( item, entity, false );
        //				list.Add( entity );
        //				if ( maxRecords > 0 && list.Count >= maxRecords )
        //					break;
        //			}
        //		}
        //	}

        //	return list;
        //}
        public static ThisEntity GetForDetail(int id)
        {
            ThisEntity entity = new ThisEntity();

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

                if (item != null && item.Id > 0)
                {
                    //check for virtual deletes
                    if (item.EntityStateId == 0)
                    {
                        return(entity);
                    }

                    MapFromDB(item, entity,
                              true                           //includingProperties
                              );
                }
            }

            return(entity);
        }