Exemple #1
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);
        }        //
Exemple #2
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;
                }
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        /// <summary>
        /// Delete a competency
        /// </summary>
        /// <param name="recordId"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public bool Delete(int recordId, ref string statusMessage)
        {
            bool isOK = true;

            using (var context = new EntityContext())
            {
                DBEntity p = context.Entity_CompetencyFramework.FirstOrDefault(s => s.Id == recordId);
                if (p != null && p.Id > 0)
                {
                    context.Entity_CompetencyFramework.Remove(p);
                    int count = context.SaveChanges();
                }
                else
                {
                    statusMessage = string.Format("The record was not found: {0}", recordId);
                    isOK          = false;
                }
            }
            return(isOK);
        }
Exemple #5
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);
        }