Exemplo n.º 1
0
        /// <summary>
        /// Private method that converts the form data to XML
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>An <see cref="XElement"/></returns>
        private XElement ViewModelToXML(PPAFormViewModel vm)
        {
            XElement root = new XElement("SmartPPA");

            PropertyInfo[] properties = typeof(PPAFormViewModel).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "Categories" && property.Name != "Components" && property.Name != "job" && property.Name != "JobList" && property.Name != "Users" && property.Name != "DocumentId")
                {
                    root.Add(new XElement(property.Name, property.GetValue(vm), new XAttribute("id", property.Name)));
                }
            }
            SmartUser author = _repository.Users.FirstOrDefault(x => x.UserId == vm.AuthorUserId);

            root.Add(new XElement("AuthorName", author?.DisplayName ?? "Unknown", new XAttribute("AuthorName", author?.DisplayName ?? "Unknown")));
            XElement job = new XElement("JobDescription");

            job.Add(new XElement("ClassTitle", vm.Job.ClassTitle, new XAttribute("id", "ClassTitle")));
            job.Add(new XElement("WorkingTitle", vm.Job.WorkingTitle, new XAttribute("id", "WorkingTitle")));
            job.Add(new XElement("Grade", vm.Job.Grade, new XAttribute("id", "Grade")));
            job.Add(new XElement("WorkingHours", vm.Job.WorkingHours, new XAttribute("id", "WorkingHours")));
            job.Add(new XElement("JobId", vm.Job.SmartJobId, new XAttribute("id", "JobId")));


            XElement categories = new XElement("Categories", new XAttribute("id", "Categories"));

            foreach (JobDescriptionCategory c in vm.Job.Categories)
            {
                XElement category = new XElement("Category", new XAttribute("id", "Category"));
                category.Add(new XElement("Letter", c.Letter, new XAttribute("id", "Letter")));
                category.Add(new XElement("Weight", c.Weight, new XAttribute("id", "Weight")));
                category.Add(new XElement("Title", c.Title, new XAttribute("id", "Title")));
                category.Add(new XElement("SelectedScore", c.SelectedScore, new XAttribute("id", "SelectedScore")));
                XElement positionDescriptionFields = new XElement("PositionDescriptionFields", new XAttribute("id", "PositionDescriptionFields"));
                foreach (PositionDescriptionItem p in c.PositionDescriptionItems)
                {
                    positionDescriptionFields.Add(new XElement("PositionDescriptionItem", p.Detail));
                }
                category.Add(positionDescriptionFields);
                XElement performanceStandardFields = new XElement("PerformanceStandardFields", new XAttribute("id", "PerformanceStandardFields"));
                foreach (PerformanceStandardItem p in c.PerformanceStandardItems)
                {
                    performanceStandardFields.Add(new XElement("PerformanceStandardItem", p.Detail, new XAttribute("initial", p.Initial)));
                }
                category.Add(performanceStandardFields);
                categories.Add(category);
            }
            job.Add(categories);
            root.Add(job);
            return(root);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="SmartDocument"/> from the user-provided form data.
        /// </summary>
        /// <param name="vm">A <see cref="PPAFormViewModel"/></param>
        public void CreatePPA(PPAFormViewModel vm)
        {
            SmartDocument newDoc = new SmartDocument
            {
                AuthorUserId = vm.AuthorUserId,
                Type         = SmartDocument.SmartDocumentType.PPA,
                Created      = DateTime.Now,
                Edited       = DateTime.Now,
                FileName     = $"{vm.LastName}, {vm.FirstName} PPA {vm.StartDate:MM-dd-yy} to {vm.EndDate:MM-dd-yy}.docx",
                Template     = _repository.Templates.FirstOrDefault(x => x.Name == ACTIVE_TEMPLATE_NAME),
                FormDataXml  = ViewModelToXML(vm)
            };

            PPA = _repository.SaveSmartDoc(newDoc);
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            // pull the PPA from the repo
            SmartDocument   ppa     = _repository.PerformanceAppraisalForms.FirstOrDefault(x => x.DocumentId == id);
            SmartPPAFactory factory = new SmartPPAFactory(_repository, ppa);
            // pass the PPA to the factory method takes a SmartPPA parameter
            PPAFormViewModel vm = factory.GetViewModelFromXML();

            // populate the VM <select> lists
            vm.JobList    = _repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList();
            vm.Users      = _repository.Users.Select(x => new UserListItem(x)).ToList();
            vm.Components = _repository.Components.ToList();
            // return the view
            ViewData["Title"] = "Edit PPA";
            return(View(vm));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates an existing <see cref="SmartDocument"/> PPA from user-provided form data.
        /// </summary>
        /// <param name="vm">A <see cref="PPAFormViewModel"/></param>
        public void UpdatePPA(PPAFormViewModel vm)
        {
            SmartDocument toEdit = _repository.PerformanceAppraisalForms.FirstOrDefault(x => x.DocumentId == vm.DocumentId);

            if (toEdit != null)
            {
                toEdit.FormDataXml  = ViewModelToXML(vm);
                toEdit.AuthorUserId = vm.AuthorUserId;
                toEdit.Edited       = DateTime.Now;
                toEdit.FileName     = $"{vm.LastName}, {vm.FirstName} PPA {vm.StartDate:MM-dd-yy} to {vm.EndDate:MM-dd-yy}.docx";
                toEdit.FormDataXml  = ViewModelToXML(vm);
                toEdit.Template     = _repository.Templates.FirstOrDefault(x => x.Name == ACTIVE_TEMPLATE_NAME);
                _repository.SaveSmartDoc(toEdit);
            }
            PPA = toEdit;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shows the view to create a new SmartPPA.
        /// </summary>
        /// <returns>An <see cref="ActionResult"/></returns>
        public ActionResult Create()
        {
            int UserId = Convert.ToInt32(((ClaimsIdentity)User.Identity).FindFirst("UserId").Value);
            // create a new, empty ViewModel
            PPAFormViewModel vm = new PPAFormViewModel
            {
                // populate the ViewModel's lists that serve the <selects> on the form
                JobList    = _repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList(),
                Users      = _repository.Users.Select(x => new UserListItem(x)).ToList(),
                Components = _repository.Components.ToList(),
                // default the "Author" <select> with the session user
                AuthorUserId = UserId
            };

            ViewData["Title"] = "Create PPA";
            return(View(vm));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(
                                        "FirstName," +
                                        "LastName," +
                                        "DepartmentIdNumber," +
                                        "PayrollIdNumber," +
                                        "PositionNumber," +
                                        "DepartmentDivision," +
                                        "DepartmentDivisionCode," +
                                        "WorkPlaceAddress," +
                                        "AuthorUserId," +
                                        "SupervisedByEmployee," +
                                        "StartDate," +
                                        "EndDate," +
                                        "JobId," +
                                        "Categories," +
                                        "Assessment," +
                                        "Recommendation")] PPAFormViewModel form)
        {
            if (!ModelState.IsValid)
            {
                // AS OF VERSION 1.1: Validation occurs clientside via jquery.validate
                // Model Validation failed, so I need to re-constitute the VM with the Job and the selected categories
                // This is done very clumsily, but I'm lazy...
                // first, reform the VM JobDescription member from the JobId in the submitted form data
                if (form.JobId != 0)
                {
                    JobDescription job = new JobDescription(_repository.Jobs.FirstOrDefault(x => x.JobId == form.JobId));
                    // next, loop through the submitted form categories and assign the JobDescription member's selected scores
                    for (int i = 0; i < job.Categories.Count(); i++)
                    {
                        job.Categories[i].SelectedScore = form.Categories[i]?.SelectedScore ?? 0;
                    }
                    form.Job = job;
                }

                // next, re-populate the VM drop down lists
                form.JobList    = _repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList();
                form.Users      = _repository.Users.Select(x => new UserListItem(x)).ToList();
                form.Components = _repository.Components.ToList();
                // return the View with the validation messages
                ViewData["Title"] = "Create PPA: Error";
                return(View(form));
            }
            else
            {
                // validation success, create new generator and pass repo
                SmartPPAFactory factory = new SmartPPAFactory(_repository);
                if (form.JobId != 0)
                {
                    JobDescription job = new JobDescription(_repository.Jobs.FirstOrDefault(x => x.JobId == form.JobId));
                    // next, loop through the submitted form categories and assign the JobDescription member's selected scores
                    for (int i = 0; i < job.Categories.Count(); i++)
                    {
                        job.Categories[i].SelectedScore = form.Categories[i]?.SelectedScore ?? 0;
                    }
                    form.Job = job;
                }
                else
                {
                    return(NotFound());
                }

                // call generator method to pass form data
                factory.CreatePPA(form);
                // redirect to success view with PPA as querystring param
                return(RedirectToAction("SaveSuccess", new { id = factory.PPA.DocumentId }));
            }
        }
Exemplo n.º 7
0
 public ActionResult Edit(int id, [Bind(
                                       "DocumentId," +
                                       "FirstName," +
                                       "LastName," +
                                       "DepartmentIdNumber," +
                                       "PayrollIdNumber," +
                                       "PositionNumber," +
                                       "DepartmentDivision," +
                                       "DepartmentDivisionCode," +
                                       "WorkPlaceAddress," +
                                       "AuthorUserId," +
                                       "SupervisedByEmployee," +
                                       "StartDate," +
                                       "EndDate," +
                                       "JobId," +
                                       "Categories," +
                                       "Assessment," +
                                       "Recommendation")] PPAFormViewModel form)
 {
     // if the querystring parameter id doesn't match the POSTed PPAId, return 404
     if (id != form.DocumentId)
     {
         return(NotFound());
     }
     if (!ModelState.IsValid)
     {
         // Model Validation failed, so I need to re-constitute the VM with the Job and the selected categories
         // This is done very clumsily, but I'm lazy...
         // first, reform the VM JobDescription member from the JobId in the submitted form data
         if (form.JobId != 0)
         {
             JobDescription job = new JobDescription(_repository.Jobs.FirstOrDefault(x => x.JobId == form.JobId));
             // next, loop through the submitted form categories and assign the JobDescription member's selected scores
             for (int i = 0; i < job.Categories.Count(); i++)
             {
                 job.Categories[i].SelectedScore = form.Categories[i]?.SelectedScore ?? 0;
             }
             form.Job = job;
         }
         // next, re-populate the VM drop down lists
         form.JobList      = _repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList();
         form.Users        = _repository.Users.Select(x => new UserListItem(x)).ToList();
         form.Components   = _repository.Components.ToList();
         ViewData["Title"] = "Edit PPA: Error";
         return(View(form));
     }
     else
     {
         if (form.JobId != 0)
         {
             JobDescription job = new JobDescription(_repository.Jobs.FirstOrDefault(x => x.JobId == form.JobId));
             // next, loop through the submitted form categories and assign the JobDescription member's selected scores
             for (int i = 0; i < job.Categories.Count(); i++)
             {
                 job.Categories[i].SelectedScore = form.Categories[i]?.SelectedScore ?? 0;
             }
             form.Job = job;
         }
         else
         {
             return(NotFound());
         }
         // validation success, create a new PPAGenerator and pass the repo as a parameter
         SmartPPAFactory factory = new SmartPPAFactory(_repository);
         // populate the form info into the generator
         factory.UpdatePPA(form);
         // redirect to the SaveSuccess view, passing the newly created PPA as a querystring param
         return(RedirectToAction("SaveSuccess", new { id = factory.PPA.DocumentId }));
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Converts an existing <see cref="SmartDocument"/>
        /// </summary>
        /// <returns></returns>
        public PPAFormViewModel GetViewModelFromXML()
        {
            XElement         root = PPA.FormDataXml;
            PPAFormViewModel vm   = new PPAFormViewModel {
                DocumentId             = PPA.DocumentId,
                FirstName              = root.Element("FirstName").Value,
                LastName               = root.Element("LastName").Value,
                DepartmentIdNumber     = root.Element("DepartmentIdNumber").Value,
                PayrollIdNumber        = root.Element("PayrollIdNumber").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,
                StartDate              = DateTime.Parse(root.Element("StartDate").Value),
                EndDate        = DateTime.Parse(root.Element("EndDate").Value),
                JobId          = Convert.ToInt32(root.Element("JobId").Value),
                AuthorUserId   = Convert.ToInt32(root.Element("AuthorUserId").Value),
                Assessment     = root.Element("Assessment").Value,
                Recommendation = root.Element("Recommendation").Value,
            };

            vm.Categories = new List <JobDescriptionCategory>();
            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,
                    SelectedScore = Convert.ToInt32(category.Element("SelectedScore").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.Categories.Add(cat);
                vm.Job.Categories.Add(cat);
            }
            return(vm);
        }