public IActionResult EditRequest(int idRequest) { FormRequestViewModel = FormRequestService.GetFormRequest(idRequest); FormRequestViewModel.HtmlForm = GetFormHtml(FormRequestViewModel.FormId, false); PopulateViewModel(); return(View("FormRequest", FormRequestViewModel)); }
private void GetRequestForms(int idForm, int idView) { var viewNode = XmlForm.SelectSingleNode("//body/views/group/view[viewId='" + idView.ToString() + "']"); var groupView = FormsBoardViewModel.GroupViews.SelectMany(g => g.Views.Where(v => v.Id.Equals(idView))).ToList(); FormsBoardViewModel.CurrentView = groupView.First(); var getAllRequests = viewNode.SelectSingleNode("listAllRequests") != null && viewNode.SelectSingleNode("listAllRequests").InnerText == "true"; var formRequests = FormRequestService.GetFormRequests(idForm, getAllRequests ? string.Empty : UserUtil.DisplayUserName); var jsonResult = new JObject(); var row = 1; foreach (var request in formRequests) { var formData = JObject.Parse(request.JSonFormData); formData.Add("IdFormRequest", request.Id.ToString()); if (viewNode.SelectSingleNode("filter") != null) { var filter = viewNode.SelectSingleNode("filter").InnerText; if (!FormXmlService.ValidateConditions(request.JSonFormData, filter)) { continue; } } jsonResult.Add(row.ToString(), formData); row++; } FormsBoardViewModel.FormRequests = formRequests; var groupedJson = GroupBy(jsonResult, FormsBoardViewModel.CurrentView.GroupBy); var orderByNode = viewNode.SelectSingleNode("orderBy"); if (orderByNode != null && !FormsBoardViewModel.CurrentView.GroupBy.Contains("Date") && !FormsBoardViewModel.CurrentView.GroupBy.Contains("Calendar")) { OrderBy(groupedJson, orderByNode.InnerText); } FormsBoardViewModel.JSonResult = groupedJson; }
public IActionResult ChangeStatus(string formData, ChangeStatusViewModel viewModel) { if (ModelState.IsValid) { try { var urlScheme = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}{HttpContext.Request.QueryString}"; FormRequestService.ChangeStatus(formData, viewModel, (UrlHelper)Url, urlScheme); } catch (Exception ex) { Logger.Info("Ha ocurrido un error: " + ex.Message); TempData[Constants.InfoKey] = "An error has happened in the saving process."; } } return(Json(new { RedirectTo = Url.Action("Index", "FormsBoard", new { idForm = viewModel.FormId, message = "Action executed successfully!" }) })); }
public IActionResult Save(string formData, FormRequestViewModel viewModel) { var jsonFormData = JsonConvert.DeserializeObject <JObject>(string.IsNullOrEmpty(formData) ? "{}" : formData); if (ModelState.IsValid) { try { FormRequestService.SaveFormRequest(viewModel, formData); } catch (Exception ex) { Logger.Info("Ha ocurrido un error: " + ex.Message); TempData[Constants.InfoKey] = "An error has happened in the saving process."; } } var redirectTo = Url.Action("Index", "FormsBoard", new { idForm = viewModel.FormId, message = "Request Form created successfully!" }); return(Json(new { RedirectTo = redirectTo })); }
private void FillBaseFormData(XmlDocument xml, bool newForm) { var statusDisplayName = string.Empty; var status = string.Empty; var reference = string.Empty; if (newForm) { statusDisplayName = xml.SelectSingleNode("//body/statuses/status[order=0]/displayName").InnerXml; status = xml.SelectSingleNode("//body/statuses/status[order=0]/name").InnerXml; FormRequestViewModel.CreatedBy = UserUtil.DisplayUserName; FormRequestViewModel.UserAssigned = UserUtil.DisplayUserName; if (xml.SelectSingleNode("//body/initialInput/createdBy") != null) { xml.SelectSingleNode("//body/initialInput/createdBy").InnerXml = UserUtil.DisplayUserName; } if (xml.SelectSingleNode("//body/initialInput/createdByEmail") != null) { xml.SelectSingleNode("//body/initialInput/createdByEmail").InnerXml = UserUtil.UserEmail; } if (xml.SelectSingleNode("//body/initialInput/createdDate") != null) { xml.SelectSingleNode("//body/initialInput/createdDate").InnerXml = DateTime.Now.ToString("MM/dd/yyyy"); } if (xml.SelectSingleNode("//body/initialInput/userAssigned") != null) { xml.SelectSingleNode("//body/initialInput/userAssigned").InnerXml = UserUtil.DisplayUserName; } if (xml.SelectSingleNode("//body/fields/field[controlId='Reference']") != null) { reference = FormRequestService.GetNextReferenceCode(xml.SelectSingleNode("//body/referenceCode").InnerXml); xml.SelectSingleNode("//body/fields/field[controlId='Reference']/value").InnerXml = reference; } } else { statusDisplayName = xml.SelectSingleNode("//body/statuses/status[name='" + FormRequestViewModel.StatusId + "']/displayName").InnerXml; status = xml.SelectSingleNode("//body/statuses/status[name='" + FormRequestViewModel.StatusId + "']/name").InnerXml; if (xml.SelectSingleNode("//body/initialInput/formRequestId") != null) { xml.SelectSingleNode("//body/initialInput/formRequestId").InnerXml = FormRequestViewModel.Id.ToString(); } if (xml.SelectSingleNode("//body/initialInput/createdBy") != null) { xml.SelectSingleNode("//body/initialInput/createdBy").InnerXml = FormXmlService.GetValue(FormRequestViewModel.JSonFormData, "field(createdBy)"); } if (xml.SelectSingleNode("//body/initialInput/createdByEmail") != null) { xml.SelectSingleNode("//body/initialInput/createdByEmail").InnerXml = FormXmlService.GetValue(FormRequestViewModel.JSonFormData, "field(createdByEmail)"); } if (xml.SelectSingleNode("//body/initialInput/createdDate") != null) { xml.SelectSingleNode("//body/initialInput/createdDate").InnerXml = FormXmlService.GetValue(FormRequestViewModel.JSonFormData, "field(createdDate)"); } if (xml.SelectSingleNode("//body/initialInput/userAssigned") != null) { xml.SelectSingleNode("//body/initialInput/userAssigned").InnerXml = FormRequestViewModel.UserAssigned; } if (xml.SelectSingleNode("//body/fields/field[controlId='Reference']") != null) { xml.SelectSingleNode("//body/fields/field[controlId='Reference']/value").InnerXml = FormXmlService.GetValue(FormRequestViewModel.JSonFormData, "field(reference)"); } LoadAttachedFilesIntoXML(xml); } if (xml.SelectSingleNode("//body/initialInput/currentUser") != null) { xml.SelectSingleNode("//body/initialInput/currentUser").InnerXml = UserUtil.DisplayUserName; } if (xml.SelectSingleNode("//body/initialInput/currentUserEmail") != null) { xml.SelectSingleNode("//body/initialInput/currentUserEmail").InnerXml = UserUtil.UserEmail; } if (xml.SelectSingleNode("//body/initialInput/status") != null) { xml.SelectSingleNode("//body/initialInput/status").InnerXml = statusDisplayName; } if (xml.SelectSingleNode("//body/initialInput/statusId") != null) { xml.SelectSingleNode("//body/initialInput/statusId").InnerXml = status; } FormRequestViewModel.FormId = int.Parse(xml.SelectSingleNode("//body/idForm").InnerXml); FormRequestViewModel.StatusDisplayName = statusDisplayName; FormRequestViewModel.StatusId = status; if (!string.IsNullOrEmpty(reference)) { FormRequestViewModel.Reference = reference; } }