Exemple #1
0
        /// <summary>
        /// Builds and Returns the ViewComponent from a list of <see cref="T:SmartDocs.Models.Types.JobDescriptionCategory"/>
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <IViewComponentResult> InvokeAsync(List <JobDescriptionCategory> list)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            JobDescription job = new JobDescription {
                Categories = list
            };
            int categoriesCount = list.Count();

            if (categoriesCount < 6)
            {
                for (var i = categoriesCount; i < 6; i++)
                {
                    JobDescriptionCategory c = new JobDescriptionCategory();
                    list.Add(c);
                }
            }

            foreach (JobDescriptionCategory j in list)
            {
                int descriptionItemsCount = j.PositionDescriptionItems.Count();
                if (descriptionItemsCount < 7)
                {
                    for (var i = descriptionItemsCount; i < 7; i++)
                    {
                        PositionDescriptionItem p = new PositionDescriptionItem();
                        j.PositionDescriptionItems.Add(p);
                    }
                }
                int performanceItemsCount = j.PerformanceStandardItems.Count();
                if (performanceItemsCount < 7)
                {
                    for (var i = performanceItemsCount; i < 7; i++)
                    {
                        PerformanceStandardItem p = new PerformanceStandardItem();
                        j.PerformanceStandardItems.Add(p);
                    }
                }
            }
            return(View(job));
        }
Exemple #2
0
        public SmartJobDescriptionViewModel GetViewModelFromXML()
        {
            XElement root = _jobDescription.FormDataXml;
            SmartJobDescriptionViewModel vm = new SmartJobDescriptionViewModel
            {
                DocumentId             = _jobDescription.DocumentId,
                FirstName              = root.Element("FirstName").Value,
                LastName               = root.Element("LastName").Value,
                DepartmentIdNumber     = root.Element("DepartmentIdNumber").Value,
                PositionNumber         = root.Element("PositionNumber").Value,
                DepartmentDivision     = root.Element("DepartmentDivision").Value,
                DepartmentDivisionCode = root.Element("DepartmentDivisionCode").Value,
                WorkPlaceAddress       = root.Element("WorkPlaceAddress").Value,
                SupervisedByEmployee   = root.Element("SupervisedByEmployee").Value,
                JobId        = Convert.ToInt32(root.Element("JobId").Value),
                AuthorUserId = Convert.ToInt32(root.Element("AuthorUserId").Value),
            };

            vm.job = new JobDescription();

            XElement job = root.Element("JobDescription");

            vm.job.SmartJobId   = Convert.ToInt32(job.Element("JobId").Value);
            vm.job.ClassTitle   = job.Element("ClassTitle").Value;
            vm.job.WorkingTitle = job.Element("WorkingTitle").Value;
            vm.job.Grade        = job.Element("Grade").Value;
            vm.job.WorkingHours = job.Element("WorkingHours").Value;
            IEnumerable <XElement> CategoryList = job.Element("Categories").Elements("Category");

            foreach (XElement category in CategoryList)
            {
                JobDescriptionCategory cat = new JobDescriptionCategory
                {
                    Letter = category.Element("Letter").Value,
                    Weight = Convert.ToInt32(category.Element("Weight").Value),
                    Title  = category.Element("Title").Value
                };
                // each category contains a child element named "PositionDescriptionFields" that contains children named "PositionDescriptionItem"
                IEnumerable <XElement> positionDescriptionFields = category.Element("PositionDescriptionFields").Elements("PositionDescriptionItem");

                // loop through the PositionDescriptionItems and map to PositionDescriptionItem class objects
                foreach (XElement positionDescriptionItem in positionDescriptionFields)
                {
                    PositionDescriptionItem item = new PositionDescriptionItem {
                        Detail = positionDescriptionItem.Value
                    };
                    // add each object to the Category Object's collection
                    cat.PositionDescriptionItems.Add(item);
                }

                // each category contains a child element named "PerformanceStandardFields" that contains children named "PerformanceStandardItem"
                IEnumerable <XElement> performanceStandardFields = category.Element("PerformanceStandardFields").Elements("PerformanceStandardItem");

                // loop through the PerformanceStandardItems and map to PerformanceStandardItem class objects
                foreach (XElement performanceStandardItem in performanceStandardFields)
                {
                    PerformanceStandardItem item = new PerformanceStandardItem {
                        Initial = performanceStandardItem.Attribute("initial").Value, Detail = performanceStandardItem.Value
                    };
                    // add each object to the Category Object's collection
                    cat.PerformanceStandardItems.Add(item);
                }
                vm.job.Categories.Add(cat);
            }
            return(vm);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:SmartDocs.Models.ViewModels.JobDescriptionViewModel"/> class.
        /// </summary>
        /// <remarks>
        /// Class Constructor that takes a <see cref="SmartDocs.Models.SmartJob"/> parameter.
        /// </remarks>
        /// <param name="job">A <see cref="SmartDocs.Models.SmartJob"/>.</param>
        public JobDescriptionViewModel(SmartJob job)
        {
            JobId = job.JobId;
            // populate the Rank List via the DefaultRankList method below
            Ranks = DefaultRankList();


            // create an empty list of JobDescription Categories to be populated from DB Job XML column data
            List <JobDescriptionCategory> results = new List <JobDescriptionCategory>();
            // retrieve the XML data column for the job to parse for Job Data
            XElement root = job.JobDataXml;

            // assign the simple values
            WorkingTitle = root.Element("WorkingTitle").Value;
            Grade        = root.Element("Grade").Value;
            WorkingHours = root.Element("WorkingHours").Value;
            Rank         = root.Element("Rank").Value;

            // pull all of the Categories from the root element
            // categories are stored in the root's "Categories" child, which contains "Category" children
            IEnumerable <XElement> CategoryList = root.Element("Categories").Elements("Category");

            // loop through the list of Categories and build a JobDescriptionCategory class object for each
            foreach (XElement category in CategoryList)
            {
                // create a new JobDescriptionCategory object, and set the Letter, Weight, and Title from the XElement's children
                JobDescriptionCategory cat = new JobDescriptionCategory
                {
                    Letter = category.Element("Letter").Value,
                    Weight = Convert.ToInt32(category.Element("Weight").Value),
                    Title  = category.Element("Title").Value
                };
                // The XElement built from a "Category" has a child named "PositionDescriptionFields" that contains "PositionDescriptionItem" children
                IEnumerable <XElement> positionDescriptionFields = category.Element("PositionDescriptionFields").Elements("PositionDescriptionItem");

                // Loop through the collection of PositionDescriptionFields and create a PositionDescriptionItem class object from each
                foreach (XElement positionDescriptionItem in positionDescriptionFields)
                {
                    // create the PositionDescriptionItem class object
                    PositionDescriptionItem item = new PositionDescriptionItem {
                        Detail = positionDescriptionItem.Value
                    };
                    // add the PositionDescriptionItem class object to the Category's collection
                    cat.PositionDescriptionItems.Add(item);
                }
                // The XElement build from a "Category" has a child named "PerformanceStandardFields" that contains "PerformanceStandardItem" objects
                IEnumerable <XElement> performanceStandardFields = category.Element("PerformanceStandardFields").Elements("PerformanceStandardItem");

                // Loop through the collection of PerformanceStandardFields and create a PerformanceStandardItem class object from each
                foreach (XElement performanceStandardItem in performanceStandardFields)
                {
                    // create a new PerformanceStandardItem class object and populate it's properties from the XML data
                    PerformanceStandardItem item = new PerformanceStandardItem {
                        Initial = performanceStandardItem.Attribute("initial").Value, Detail = performanceStandardItem.Value
                    };
                    // add the PerformanceStandardItem class object to the Category's collection.
                    cat.PerformanceStandardItems.Add(item);
                }
                // the JobDescriptionCategory is built, so add it to the "results" collection
                results.Add(cat);
            }
            // assign the newly built collection of JobDescriptionCategory items named "results" to the class Categories properties
            Categories = results;
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JobDescription"/> class.
        /// </summary>
        /// <remarks>
        /// Class constructor that requires a <see cref="SmartJob"/>
        /// </remarks>
        /// <param name="job">A <see cref="SmartJob"/>.</param>
        public JobDescription(SmartJob job)
        {
            SmartJobId = job.JobId;

            // create a new category list
            List <JobDescriptionCategory> results = new List <JobDescriptionCategory>();

            // retrieve the XML data column from the SmartJob Entity parameter
            XElement root = job.JobDataXml;

            // assign the properties that are stored in the XML data
            ClassTitle   = root.Element("ClassTitle").Value;
            WorkingTitle = root.Element("WorkingTitle").Value;
            Grade        = root.Element("Grade").Value;
            WorkingHours = root.Element("WorkingHours").Value;
            Rank         = root.Element("Rank").Value;

            // the XML has a child element named "Categories" that has children named "Category"
            IEnumerable <XElement> CategoryList = root.Element("Categories").Elements("Category");

            // loop through the categories and map them to JobDescriptionCategory class objects
            foreach (XElement category in CategoryList)
            {
                JobDescriptionCategory cat = new JobDescriptionCategory
                {
                    Letter = category.Element("Letter").Value,
                    Weight = Convert.ToInt32(category.Element("Weight").Value),
                    Title  = category.Element("Title").Value
                };

                // each category contains a child element named "PositionDescriptionFields" that contains children named "PositionDescriptionItem"
                IEnumerable <XElement> positionDescriptionFields = category.Element("PositionDescriptionFields").Elements("PositionDescriptionItem");

                // loop through the PositionDescriptionItems and map to PositionDescriptionItem class objects
                foreach (XElement positionDescriptionItem in positionDescriptionFields)
                {
                    PositionDescriptionItem item = new PositionDescriptionItem {
                        Detail = positionDescriptionItem.Value
                    };
                    // add each object to the Category Object's collection
                    cat.PositionDescriptionItems.Add(item);
                }

                // each category contains a child element named "PerformanceStandardFields" that contains children named "PerformanceStandardItem"
                IEnumerable <XElement> performanceStandardFields = category.Element("PerformanceStandardFields").Elements("PerformanceStandardItem");

                // loop through the PerformanceStandardItems and map to PerformanceStandardItem class objects
                foreach (XElement performanceStandardItem in performanceStandardFields)
                {
                    PerformanceStandardItem item = new PerformanceStandardItem {
                        Initial = performanceStandardItem.Attribute("initial").Value, Detail = performanceStandardItem.Value
                    };
                    // add each object to the Category Object's collection
                    cat.PerformanceStandardItems.Add(item);
                }
                // now, add the Category object itself to the "result" list of categories
                results.Add(cat);
            }
            // assign the assembled category list to the Job Description's Categories property
            Categories = results;
        }