Exemple #1
0
        public static void MapFromDB(DBEntityItem from, ThisEntityItem to, bool includingItems = true)
        {
            to.Id       = from.Id;
            to.ParentId = from.EntityFrameworkId;
            to.RowId    = from.RowId;

            to.Name              = StripJqueryTag(from.Name);
            to.Description       = from.Description;
            to.TargetName        = from.TargetName;
            to.TargetDescription = from.TargetDescription;
            to.TargetUrl         = from.TargetUrl;
            to.CodedNotation     = from.CodedNotation;

            if (IsValidDate(from.AlignmentDate))
            {
                to.AlignmentDate = (( DateTime )from.AlignmentDate).ToShortDateString();
            }
            else
            {
                to.AlignmentDate = "";
            }

            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);
        }
Exemple #2
0
        }        //

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

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

                    if (item != null && item.Id > 0)
                    {
                        MapFromDB(item, entity, true);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Entity_Competency_Get");
            }
            return(entity);
        }        //
Exemple #3
0
        /// <summary>
        /// Get all records for the parent
        /// Uses the parent Guid to retrieve the related ThisEntityItem, 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 <ThisEntityItem> Entity_Competency_GetAll(int frameworkId)
        {
            ThisEntityItem        entity = new ThisEntityItem();
            List <ThisEntityItem> list   = new List <ThisEntityItem>();

            try
            {
                using (var context = new EntityContext())
                {
                    List <DBEntityItem> results = context.Entity_CompetencyFrameworkItem
                                                  .Where(s => s.EntityFrameworkId == frameworkId)
                                                  .OrderBy(s => s.Id)
                                                  .ToList();

                    if (results != null && results.Count > 0)
                    {
                        foreach (DBEntityItem item in results)
                        {
                            entity = new ThisEntityItem();
                            MapFromDB(item, entity, true);
                            list.Add(entity);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Entity_Competency_GetAll");
            }
            return(list);
        }        //
Exemple #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);
            }
        }
Exemple #5
0
        }         //

        public static void MapToDB(ThisEntityItem from, DBEntityItem to)
        {
            //want to ensure fields from create are not wiped
            //to.Id = from.Id;
            to.EntityFrameworkId = from.ParentId;
            to.Name              = StripJqueryTag(from.Name);
            to.Description       = from.Description;
            to.TargetName        = from.TargetName;
            to.TargetDescription = from.TargetDescription;
            to.TargetUrl         = from.TargetUrl;
            to.CodedNotation     = from.CodedNotation;

            if (IsValidDate(from.AlignmentDate))
            {
                to.AlignmentDate = DateTime.Parse(from.AlignmentDate);
            }
            else
            {
                to.AlignmentDate = null;
            }
        }
Exemple #6
0
        public bool ValidateProfile(ThisEntityItem profile, ref bool isEmpty, ref SaveStatus status)
        {
            bool isValid = true;

            isEmpty = false;
            //check if empty
            if (string.IsNullOrWhiteSpace(profile.Name) &&
                string.IsNullOrWhiteSpace(profile.Description) &&
                string.IsNullOrWhiteSpace(profile.TargetName) &&
                string.IsNullOrWhiteSpace(profile.TargetDescription)
                )
            {
                status.AddWarning("Please enter, at minimum, a competency name.");
                //isEmpty = true;
                return(false);
            }

            if (string.IsNullOrWhiteSpace(profile.Name))
            {
                status.AddWarning("A competency name must be entered");
                isValid = false;
            }

            if (!string.IsNullOrWhiteSpace(profile.AlignmentDate) &&
                !IsValidDate(profile.AlignmentDate))
            {
                status.AddWarning("Please enter a valid alignment date");
                isValid = false;
            }

            //if ( string.IsNullOrWhiteSpace( profile.Description ) )
            //{
            //	status.AddWarning( "A competency Description must be entered" );
            //	isValid = false;
            //}

            return(isValid);
        }
Exemple #7
0
        }        //

        public static List <ThisEntityItem> Search(string pFilter, string pOrderBy, int pageNumber, int pageSize, ref int pTotalRows)
        {
            string                connectionString = DBConnectionRO();
            ThisEntityItem        item             = new ThisEntityItem();
            List <ThisEntityItem> list             = new List <ThisEntityItem>();
            var result = new DataTable();

            using (SqlConnection c = new SqlConnection(connectionString))
            {
                c.Open();

                if (string.IsNullOrEmpty(pFilter))
                {
                    pFilter = "";
                }

                using (SqlCommand command = new SqlCommand("[Competencies_search]", c))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@Filter", pFilter));
                    command.Parameters.Add(new SqlParameter("@SortOrder", pOrderBy));
                    command.Parameters.Add(new SqlParameter("@StartPageIndex", pageNumber));
                    command.Parameters.Add(new SqlParameter("@PageSize", pageSize));

                    SqlParameter totalRows = new SqlParameter("@TotalRows", pTotalRows);
                    totalRows.Direction = ParameterDirection.Output;
                    command.Parameters.Add(totalRows);

                    using (SqlDataAdapter adapter = new SqlDataAdapter())
                    {
                        adapter.SelectCommand = command;
                        adapter.Fill(result);
                    }
                    string rows = command.Parameters[4].Value.ToString();
                    try
                    {
                        pTotalRows = Int32.Parse(rows);
                    }
                    catch
                    {
                        pTotalRows = 0;
                    }
                }

                foreach (DataRow dr in result.Rows)
                {
                    item             = new ThisEntityItem();
                    item.Id          = GetRowColumn(dr, "CompetencyFrameworkItemId", 0);
                    item.Name        = GetRowColumn(dr, "Competency", "???");
                    item.ProfileName = GetRowPossibleColumn(dr, "Competency2", "???");
                    item.Description = GetRowColumn(dr, "Description", "");

                    //don't include credentialId, as will work with source of the search will often be for a credential./ Same for condition profiles for now.
                    item.SourceParentId     = GetRowColumn(dr, "SourceId", 0);
                    item.SourceEntityTypeId = GetRowColumn(dr, "SourceEntityTypeId", 0);
                    item.AlignmentTypeId    = GetRowColumn(dr, "AlignmentTypeId", 0);
                    item.AlignmentType      = GetRowColumn(dr, "AlignmentType", "");
                    //Although the condition profile type may be significant?
                    item.ConnectionTypeId = GetRowColumn(dr, "ConnectionTypeId", 0);

                    list.Add(item);
                }

                return(list);
            }
        }         //
Exemple #8
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 Entity_Competency_Save(ThisEntityItem entity,
                                           int userId,
                                           ref SaveStatus status)
        {
            bool isValid     = true;
            int  intialCount = messages.Count;

            if (entity.ParentId == 0)
            {
                status.AddWarning("Error: the parent identifier was not provided.");
            }

            if (messages.Count > intialCount)
            {
                return(false);
            }

            int count = 0;

            DBEntityItem efEntity = new DBEntityItem();

            using (var context = new EntityContext())
            {
                bool isEmpty = false;

                if (ValidateProfile(entity, ref isEmpty, ref status) == false)
                {
                    return(false);
                }
                if (isEmpty)
                {
                    status.AddWarning("The Competency Profile is empty. ");
                    return(false);
                }

                if (entity.Id == 0)
                {
                    //add
                    efEntity = new DBEntityItem();
                    MapToDB(entity, efEntity);

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

                    context.Entity_CompetencyFrameworkItem.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.Description));
                    }
                }
                else
                {
                    efEntity = context.Entity_CompetencyFrameworkItem.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;
                            efEntity.LastUpdatedById = userId;

                            count = context.SaveChanges();
                        }
                    }
                }
            }

            return(isValid);
        }