Exemplo n.º 1
0
        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 }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Private method that converts the user-provided form data into the XML field of the <see cref="SmartDocument"/>.
        /// </summary>
        /// <param name="vm"></param>
        /// <returns>An <see cref="XElement"/></returns>
        private XElement ViewModelToXML(SmartAwardViewModel vm)
        {
            XElement root = new XElement("SmartAward");

            PropertyInfo[] properties;
            switch (vm.SelectedAward)
            {
            case 1:
                properties = typeof(GoodConductAwardViewModel).GetProperties();
                break;

            case 2:
                properties = typeof(OutstandingPerformanceAwardViewModel).GetProperties();
                break;

            default:
                throw new NotImplementedException("The Viewmodel has an unrecognized SelectedAwardType");
            }

            root.Add(new XElement("DocumentId", awardForm?.DocumentId ?? vm.DocumentId, new XAttribute("DocumentId", awardForm?.DocumentId ?? vm.DocumentId)));
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "DocumentId" && property.Name != "Components" && property.Name != "Users" && property.Name != "AwardList" && property.Name != "Components" && property.Name != "Users" && property.Name != "AwardTypes")
                {
                    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 award = new XElement("AwardType");

            return(root);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
        /// <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;
        }
Exemplo n.º 6
0
 public IActionResult Create([Bind("DocumentId,AuthorUserId,AgencyName,NomineeName,ClassTitle,Division,SelectedAward,Kind,AwardClass,AwardName,ComponentViewName,Description,HasRibbon,EligibilityConfirmationDate,StartDate,EndDate,SelectedAwardType")] SmartAwardViewModel form)
 {
     if (!ModelState.IsValid)
     {
         ViewData["Title"] = "Create Award Form: Error";
         form.Components   = _repository.Components.ToList();
         form.Users        = _repository.Users.ToList();
         return(View(form));
     }
     else
     {
         // do Award Form Factory stuff
         SmartAwardFactory factory = new SmartAwardFactory(_repository);
         factory.CreateSmartAwardForm(form);
         return(RedirectToAction("SaveSuccess", new { id = factory.awardForm.DocumentId }));
     }
 }