public ActionResult Download(int id) { // create a generator, passing the repository as a parameter SmartDocument document = _repository.Documents.FirstOrDefault(x => x.DocumentId == id); if (document != null) { switch (document.Type) { case SmartDocument.SmartDocumentType.PPA: var ppaFactory = new SmartPPAFactory(_repository, document); return(File(ppaFactory.GenerateDocument(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", document.FileName)); case SmartDocument.SmartDocumentType.JobDescription: var jobFactory = new SmartJobDescriptionFactory(_repository, document); return(File(jobFactory.GenerateDocument(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", document.FileName)); case SmartDocument.SmartDocumentType.AwardForm: var awardFactory = new SmartAwardFactory(_repository, document); return(File(awardFactory.GenerateDocument(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", document.FileName)); case SmartDocument.SmartDocumentType.PAF: var pafFactory = new SmartPAFFactory(_repository, document); return(File(pafFactory.GenerateDocument(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", document.FileName)); default: return(NotFound()); } } else { return(NotFound()); } }
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)); }
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 })); } }
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 })); } }