public ActionResult Create([Bind(
                                 "SelectedPAFType," +
                                 "FirstName," +
                                 "LastName," +
                                 "DepartmentIdNumber," +
                                 "PayrollIdNumber," +
                                 "DepartmentIdNumber," +
                                 "DepartmentDivision," +
                                 "DepartmentDivisionCode," +
                                 "WorkPlaceAddress," +
                                 "AuthorUserId," +
                                 "StartDate," +
                                 "EndDate," +
                                 "JobId," +
                                 "Assessment," +
                                 "Recommendation")] PAFFormViewModel form)
 {
     if (!ModelState.IsValid)
     {
         // next, re-populate the VM drop down lists
         form.HydrateLists(_repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList(), _repository.Components.ToList(), _repository.Users.Select(x => new UserListItem(x)).ToList());
         // return the View with the validation messages
         ViewData["Title"] = "Create PAF: Error";
         return(View(form));
     }
     else
     {
         // validation success, create new generator and pass repo
         SmartPAFFactory factory = new SmartPAFFactory(_repository);
         // call generator method to pass form data
         factory.CreatePAF(form);
         // redirect to success view with PPA as querystring param
         return(RedirectToAction("SaveSuccess", new { id = factory.PAF.DocumentId }));
     }
 }
        /// <summary>
        /// Shows the view to create a new SmartPAF.
        /// </summary>
        /// <returns>An <see cref="ActionResult"/></returns>
        public ActionResult Create()
        {
            // create a new, empty ViewModel
            int currentUserId   = Convert.ToInt32(((ClaimsIdentity)User.Identity).FindFirst("UserId").Value);
            PAFFormViewModel vm = new PAFFormViewModel(currentUserId);

            vm.HydrateLists(_repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList(), _repository.Components.ToList(), _repository.Users.Select(x => new UserListItem(x)).ToList());
            ViewData["Title"] = "Create PAF";
            return(View(vm));
        }
        public ActionResult Edit(int id)
        {
            // pull the PAF from the repo
            SmartDocument   paf     = _repository.PerformanceAssessmentForms.FirstOrDefault(x => x.DocumentId == id);
            SmartPAFFactory factory = new SmartPAFFactory(_repository, paf);
            // pass the PPA to the factory method takes a SmartPPA parameter
            PAFFormViewModel vm = factory.GetViewModelFromXML();

            // populate the VM <select> lists
            vm.HydrateLists(_repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList(), _repository.Components.ToList(), _repository.Users.Select(x => new UserListItem(x)).ToList());
            // return the view
            ViewData["Title"] = "Edit PAF";
            return(View(vm));
        }
 public ActionResult Edit(int id, [Bind(
                                       "DocumentId," +
                                       "SelectedPAFType," +
                                       "FirstName," +
                                       "LastName," +
                                       "DepartmentIdNumber," +
                                       "PayrollIdNumber," +
                                       "DepartmentIdNumber," +
                                       "DepartmentDivision," +
                                       "DepartmentDivisionCode," +
                                       "WorkPlaceAddress," +
                                       "AuthorUserId," +
                                       "StartDate," +
                                       "EndDate," +
                                       "JobId," +
                                       "Assessment," +
                                       "Recommendation")] PAFFormViewModel form)
 {
     // if the querystring parameter id doesn't match the POSTed PAFId, return 404
     if (id != form.DocumentId)
     {
         return(NotFound());
     }
     if (!ModelState.IsValid)
     {
         // next, re-populate the VM drop down lists
         form.HydrateLists(_repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList(), _repository.Components.ToList(), _repository.Users.Select(x => new UserListItem(x)).ToList());
         ViewData["Title"] = "Edit PAF: Error";
         return(View(form));
     }
     else
     {
         if (form.JobId != 0)
         {
             JobDescription job = new JobDescription(_repository.Jobs.FirstOrDefault(x => x.JobId == form.JobId));
         }
         else
         {
             return(NotFound());
         }
         // validation success, create a new PAFGenerator and pass the repo as a parameter
         SmartPAFFactory factory = new SmartPAFFactory(_repository);
         // populate the form info into the generator
         factory.UpdatePAF(form);
         // redirect to the SaveSuccess view, passing the newly created PPA as a querystring param
         return(RedirectToAction("SaveSuccess", new { id = factory.PAF.DocumentId }));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Converts an existing <see cref="SmartDocument"/>
        /// </summary>
        /// <returns></returns>
        public PAFFormViewModel GetViewModelFromXML()
        {
            XElement         root = PAF.FormDataXml;
            PAFFormViewModel vm   = new PAFFormViewModel()
            {
                DocumentId             = PAF.DocumentId,
                SelectedPAFType        = root.Element("SelectedPAFType").Value,
                FirstName              = root.Element("FirstName").Value,
                LastName               = root.Element("LastName").Value,
                DepartmentIdNumber     = root.Element("DepartmentIdNumber").Value,
                PayrollIdNumber        = root.Element("PayrollIdNumber").Value,
                DepartmentDivision     = root.Element("DepartmentDivision").Value,
                DepartmentDivisionCode = root.Element("DepartmentDivisionCode").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.HydrateLists(_repository.Jobs.Select(x => new JobDescriptionListItem(x)).ToList(), _repository.Components.ToList(), _repository.Users.Select(x => new UserListItem(x)).ToList());
            return(vm);
        }