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 IActionResult Edit(int id, [Bind("DocumentId,AuthorUserId,AgencyName,NomineeName,ClassTitle,Division,SelectedAward,Kind,AwardClass,AwardName,ComponentViewName,Description,HasRibbon,EligibilityConfirmationDate,StartDate,EndDate,SelectedAwardType")] SmartAwardViewModel form) { if (id != form.DocumentId) { return(NotFound()); } if (!ModelState.IsValid) { // rebuild and return VM ViewData["Title"] = "Edit Award Form: Error"; form.Components = _repository.Components.ToList(); form.Users = _repository.Users.ToList(); return(View(form)); } SmartDocument awardDoc = _repository.AwardForms.FirstOrDefault(x => x.DocumentId == id); if (awardDoc == null) { return(NotFound()); } SmartAwardFactory factory = new SmartAwardFactory(_repository, awardDoc); factory.UpdateAwardForm(form); return(RedirectToAction("SaveSuccess", new { id = factory.awardForm.DocumentId })); }
/// <summary> /// Initializes a new instance of the <see cref="DocumentListViewModelItem"/> class. /// </summary> /// <remarks> /// Builds a viewmodel from an existing <see cref="SmartDocument"/> /// </remarks> /// <param name="doc">A <see cref="SmartDocument"/>.</param> public DocumentListViewModelItem(SmartDocument doc) { DocumentId = doc.DocumentId; DocumentName = doc.FileName; Type = doc.Type; switch (doc.Type) { case SmartDocument.SmartDocumentType.PPA: DocumentTypeDisplayName = "Smart PPA"; ParentControllerName = "SmartPPA"; break; case SmartDocument.SmartDocumentType.JobDescription: DocumentTypeDisplayName = "Job Description"; ParentControllerName = "SmartJobDescription"; break; case SmartDocument.SmartDocumentType.AwardForm: DocumentTypeDisplayName = "Award Form"; ParentControllerName = "AwardForm"; break; case SmartDocument.SmartDocumentType.PAF: DocumentTypeDisplayName = "Performance Assessement Form"; ParentControllerName = "SmartPAF"; break; } CreatedDate = doc.Created; }
public IActionResult SaveSuccess(int id) { // this is a simple view, so use VB instead of a VM SmartDocument doc = _repository.PerformanceAssessmentForms.FirstOrDefault(x => x.DocumentId == id); ViewBag.PAFId = id; ViewBag.FileName = doc.FileName; ViewData["Title"] = "Success!"; return(View()); }
public SmartJobDescriptionFactory(IDocumentRepository repo, SmartDocument job) { if (job.Type != SmartDocument.SmartDocumentType.JobDescription) { throw new InvalidOperationException("The SmartDocument Parameter passed to the factory constructor is of the wrong type."); } else { _repository = repo; _jobDescription = job; } }
/// <summary> /// Constructs a new instance of the class. /// </summary> /// <param name="repo">An implementation of <see cref="IDocumentRepository"/></param> /// <param name="award">The <see cref="SmartDocument"/> Award Form being generated.</param> public SmartAwardFactory(IDocumentRepository repo, SmartDocument award) { if (award.Type != SmartDocument.SmartDocumentType.AwardForm) { throw new InvalidOperationException("The SmartDocument Parameter passed to the factory constructor is of the wrong type."); } else { _repository = repo; awardForm = award; } }
public IActionResult Edit(int id) { SmartDocument award = _repository.AwardForms.FirstOrDefault(x => x.DocumentId == id); if (award == null) { return(NotFound()); } SmartAwardFactory factory = new SmartAwardFactory(_repository, award); SmartAwardViewModel vm = factory.GetViewModelFromXML(); ViewData["Title"] = "Edit Award Form"; return(View(vm)); }
public IActionResult Edit(int id) { SmartDocument smartJob = _repository.JobDescriptionForms.FirstOrDefault(x => x.DocumentId == id); SmartJobDescriptionFactory factory = new SmartJobDescriptionFactory(_repository, smartJob); SmartJobDescriptionViewModel vm = factory.GetViewModelFromXML(); 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 Job Description"; 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 void UpdateSmartJobDescription(SmartJobDescriptionViewModel vm) { SmartDocument toEdit = _repository.JobDescriptionForms.FirstOrDefault(x => x.DocumentId == vm.DocumentId); if (toEdit != null) { toEdit.AuthorUserId = vm.AuthorUserId; toEdit.Edited = DateTime.Now; toEdit.FileName = $"{vm.LastName}, {vm.FirstName} Job Description {DateTime.Now.ToString("MM-dd-yy")}.docx"; toEdit.FormDataXml = ViewModelToXML(vm); toEdit.Template = _repository.Templates.FirstOrDefault(x => x.Name == "SmartJobDescription"); _repository.SaveSmartDoc(toEdit); } _jobDescription = toEdit; }
/// <summary> /// Creates a new <see cref="SmartDocument"/> from the user-provided form data. /// </summary> /// <param name="vm">A <see cref="PAFFormViewModel"/></param> public void CreatePAF(PAFFormViewModel vm) { SmartDocument newDoc = new SmartDocument { AuthorUserId = vm.AuthorUserId, Type = SmartDocument.SmartDocumentType.PAF, Created = DateTime.Now, Edited = DateTime.Now, FileName = $"{vm.LastName}, {vm.FirstName} {vm.SelectedPAFType} {DateTime.Now:MM-dd-yy}.docx", Template = _repository.Templates.FirstOrDefault(x => x.Name == ACTIVE_TEMPLATE_NAME), FormDataXml = ViewModelToXML(vm) }; PAF = _repository.SaveSmartDoc(newDoc); }
/// <summary> /// Updates an existing <see cref="SmartDocument"/> award form from user-provided form data. /// </summary> /// <param name="vm"></param> public void UpdateAwardForm(SmartAwardViewModel vm) { SmartDocument toEdit = _repository.AwardForms.FirstOrDefault(x => x.DocumentId == vm.DocumentId); if (toEdit != null) { toEdit.AuthorUserId = vm.AuthorUserId; toEdit.Edited = DateTime.Now; toEdit.FileName = $"{vm.NomineeName} {vm.AwardName} Form {DateTime.Now:MM-dd-yy}.docx"; toEdit.Template = _repository.Templates.FirstOrDefault(x => x.Name == "SmartAwardForm"); toEdit.FormDataXml = ViewModelToXML(vm); _repository.SaveSmartDoc(toEdit); } awardForm = toEdit; }
/// <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; }
/// <summary> /// Updates an existing <see cref="SmartDocument"/> PAF from user-provided form data. /// </summary> /// <param name="vm">A <see cref="PAFFormViewModel"/></param> public void UpdatePAF(PAFFormViewModel vm) { SmartDocument toEdit = _repository.PerformanceAssessmentForms.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} {vm.SelectedPAFType} {DateTime.Now:MM-dd-yy}.docx"; toEdit.FormDataXml = ViewModelToXML(vm); toEdit.Template = _repository.Templates.FirstOrDefault(x => x.Name == ACTIVE_TEMPLATE_NAME); _repository.SaveSmartDoc(toEdit); } PAF = toEdit; }
public void CreateSmartJobDescription(SmartJobDescriptionViewModel vm) { SmartDocument newDoc = new SmartDocument { AuthorUserId = vm.AuthorUserId, Type = SmartDocument.SmartDocumentType.JobDescription, Created = DateTime.Now, Edited = DateTime.Now, FileName = $"{vm.LastName} {vm.FirstName} Job Description {DateTime.Now.ToString("MM-dd-yy")}.docx", Template = _repository.Templates.FirstOrDefault(x => x.Name == "SmartJobDescription"), FormDataXml = ViewModelToXML(vm) }; _repository.SaveSmartDoc(newDoc); _jobDescription = newDoc; }
/// <summary> /// Creates a new <see cref="SmartDocument"/> from the user-provided form data. /// </summary> /// <param name="vm">An instance of <see cref="SmartAwardViewModel"/> view model.</param> public void CreateSmartAwardForm(SmartAwardViewModel vm) { SmartDocument newDoc = new SmartDocument { AuthorUserId = vm.AuthorUserId, Type = SmartDocument.SmartDocumentType.AwardForm, Created = DateTime.Now, Edited = DateTime.Now, FileName = $"{vm.NomineeName} {vm.AwardName} Form {DateTime.Now:MM-dd-yy}.docx", Template = _repository.Templates.FirstOrDefault(x => x.Name == "SmartAwardForm"), FormDataXml = ViewModelToXML(vm) }; _repository.SaveSmartDoc(newDoc); awardForm = newDoc; }
/// <summary> /// Constructs a new instance of the class from an existing <see cref="SmartDocument"/> /// </summary> /// <param name="repo">An implementation of <see cref="IDocumentRepository"/></param> /// <param name="ppa">An <see cref="SmartDocument"/> representing an existing PPA.</param> public SmartPAFFactory(IDocumentRepository repo, SmartDocument paf) { _repository = repo; PAF = paf; }
/// <summary> /// Constructs a new instance of the class from an existing <see cref="SmartDocument"/> /// </summary> /// <param name="repo">An implementation of <see cref="IDocumentRepository"/></param> /// <param name="ppa">An <see cref="SmartDocument"/> representing an existing PPA.</param> public SmartPPAFactory(IDocumentRepository repo, SmartDocument ppa) { _repository = repo; PPA = ppa; }