예제 #1
0
        }        //

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

            to.EducationalFrameworkName = from.EducationalFrameworkName;
            int pos2 = from.EducationalFrameworkName.ToLower().IndexOf("jquery");

            if (pos2 > 1)
            {
                from.EducationalFrameworkName = from.EducationalFrameworkName.Substring(0, pos2);
            }
            to.EducationalFrameworkUrl = from.EducationalFrameworkUrl;

            //TODO work to eliminate
            to.AlignmentType = from.AlignmentType;
            if (from.AlignmentTypeId > 0)
            {
                to.AlignmentTypeId = from.AlignmentTypeId;
            }
            else if (!string.IsNullOrWhiteSpace(to.AlignmentType))
            {
                CodeItem item = CodesManager.Codes_PropertyValue_Get(CodesManager.PROPERTY_CATEGORY_ALIGNMENT_TYPE, to.AlignmentType);
                if (item != null && item.Id > 0)
                {
                    to.AlignmentTypeId = item.Id;
                }
            }
        }
예제 #2
0
        }        //

        /// <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.Entity_CompetencyFramework
                                    .SingleOrDefault(s => s.Id == profileId);

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity, true);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Get");
            }
            return(entity);
        }        //
예제 #3
0
        public bool ValidateProfile(ThisEntity profile, ref SaveStatus status)
        {
            status.HasSectionErrors = false;
            if (string.IsNullOrWhiteSpace(profile.FrameworkName))
            {
                status.AddWarning("An educational framework name must be entered");
            }

            //could check for alignment type, but this is typically set by context, and not entered.
            return(!status.HasSectionErrors);
        }
예제 #4
0
        public static void MapFromDB(DBEntity from, ThisEntity to, bool includingItems = true)
        {
            to.Id       = from.Id;
            to.RowId    = from.RowId;
            to.ParentId = from.EntityId;

            to.ProfileName = from.EducationalFrameworkName;
            to.EducationalFrameworkName = from.EducationalFrameworkName;

            to.EducationalFrameworkUrl = from.EducationalFrameworkUrl;

            to.AlignmentTypeId = from.AlignmentTypeId ?? 0;
            to.AlignmentType   = from.AlignmentType;

            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }
            to.CreatedById = from.CreatedById == null ? 0 : ( int )from.CreatedById;
            if (IsValidDate(from.LastUpdated))
            {
                to.LastUpdated = ( DateTime )from.LastUpdated;
            }
            to.LastUpdatedById = from.LastUpdatedById == null ? 0 : ( int )from.LastUpdatedById;
            to.LastUpdatedBy   = SetLastUpdatedBy(to.LastUpdatedById, from.Account_Modifier);

            ThisEntityItem ip = new ThisEntityItem();

            //get all competencies - as profile links?
            foreach (DBEntityItem item in from.Entity_CompetencyFrameworkItem)
            {
                ip          = new ThisEntityItem();
                ip.Id       = item.Id;
                ip.ParentId = item.EntityFrameworkId;

                ip.Name              = item.Name;
                ip.Description       = item.Description;
                ip.TargetName        = item.TargetName;
                ip.TargetDescription = item.TargetDescription;
                ip.TargetUrl         = item.TargetUrl;
                ip.CodedNotation     = item.CodedNotation;

                to.Items.Add(ip);
            }
        }
예제 #5
0
        /// <summary>
        /// Get all profiles for the parent
        /// Uses the parent Guid to retrieve the related ThisEntity, then uses the EntityId to retrieve the child objects.
        /// </summary>
        /// <param name="parentUid"></param>
        /// <param name="alignmentType">If blank, get all types.</param>
        public static List <ThisEntity> GetAll(Guid parentUid, string alignmentType)
        {
            ThisEntity        entity = new ThisEntity();
            List <ThisEntity> list   = new List <ThisEntity>();
            //Views.Entity_Summary parent = EntityManager.GetDBEntity( parentUid );
            Entity parent = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                return(list);
            }
            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntity> results = context.Entity_CompetencyFramework
                                              .Where(s => s.EntityId == parent.Id &&
                                                     (alignmentType == "" || s.AlignmentType == alignmentType))
                                              .OrderBy(s => s.EducationalFrameworkName)
                                              .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntity item in results)
                        {
                            entity = new ThisEntity();
                            MapFromDB(item, entity, true);
                            list.Add(entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".GetAll");
            }
            return(list);
        }        //
예제 #6
0
        /// <summary>
        /// Add/Update a competency
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="parentUid"></param>
        /// <param name="userId"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Save(ThisEntity entity,
                         Guid parentUid,
                         ref SaveStatus status)
        {
            bool isValid = true;

            if (!IsValidGuid(parentUid))
            {
                status.AddError(thisClassName + "Save(). Error: the parent identifier was not provided.");
                return(false);
            }

            int count = 0;

            DBEntity efEntity = new DBEntity();
            Entity   parent   = EntityManager.GetEntity(parentUid);

            if (parent == null || parent.Id == 0)
            {
                status.AddError(thisClassName + string.Format("Save(). Error - the parent entity (parentUid: {0}) was not found.", parentUid));
                return(false);
            }

            using (var context = new EntityContext())
            {
                if (ValidateProfile(entity, ref status) == false)
                {
                    return(false);
                }
                if (entity.Id == 0)
                {
                    //add
                    efEntity = new DBEntity();
                    MapToDB(entity, efEntity);
                    efEntity.EntityId = parent.Id;

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

                    context.Entity_CompetencyFramework.Add(efEntity);

                    count = context.SaveChanges();

                    entity.Id       = efEntity.Id;
                    entity.ParentId = parent.Id;
                    entity.RowId    = efEntity.RowId;
                    if (count == 0)
                    {
                        status.AddWarning(thisClassName + string.Format("Save(). Unable to add Profile: {0} <br\\> ", string.IsNullOrWhiteSpace(entity.FrameworkName) ? "no description" : entity.FrameworkName));
                    }
                }
                else
                {
                    entity.ParentId = parent.Id;

                    efEntity = context.Entity_CompetencyFramework.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))
                        {
                            efEntity.LastUpdated = System.DateTime.Now;
                            count = context.SaveChanges();
                        }
                    }
                }
            }

            return(isValid);
        }