Пример #1
0
 /// <summary>
 /// Saves/Updates the <see cref="SmartJob"/>.
 /// </summary>
 /// <remarks>
 /// If this method is passed a SmartJob with a non-zero SmartJob.JobId, it will update the corresponding SmartJob in the repo. If this method is passed a SmartJob with a SmartJob.JobId = 0, then it will create a new SmartJob in the repo.
 /// </remarks>
 /// <param name="job">The <see cref="SmartJob"/>.</param>
 public void SaveJob(SmartJob job)
 {
     if (job.JobId == 0)
     {
         context.Jobs.Add(job);
     }
     else
     {
         SmartJob dbJob = context.Jobs.FirstOrDefault(j => j.JobId == job.JobId);
         if (dbJob != null)
         {
             dbJob.JobName = job.JobName;
             dbJob.JobData = job.JobData;
         }
     }
     context.SaveChanges();
 }
Пример #2
0
 /// <summary>
 /// Removes the <see cref="SmartJob"/> from the repo.
 /// </summary>
 /// <param name="job">The <see cref="SmartJob"/>.</param>
 public void RemoveJob(SmartJob job)
 {
     context.Jobs.Remove(job);
     context.SaveChanges();
 }
Пример #3
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;
        }