public async Task <ActionResult> Edit(string path) { string userAuthenResult = await UserAuthentication(); if (!userAuthenResult.Equals(string.Empty)) { return(View(userAuthenResult)); } User user = GetUser(); string token = user.Token; FormControl formControl = await _formControlService.FindByPathForm(path); if (formControl == null) { return(View(ViewName.ERROR_404)); } string assign = formControl.Assign; bool isFormPending = CalculateUtil.IsFormPendingOrExpired(formControl.Start); bool isFormExpired = !CalculateUtil.IsFormPendingOrExpired(formControl.Expired); if (isFormPending || isFormExpired) { return(View(ViewName.ERROR_403)); } bool isFormAssignToUser = await IsFormAssignToUser(token, assign, user.IdGroup); if (assign.Equals(Keywords.AUTHENTICATED) || isFormAssignToUser) { string res1 = await _formService.FindFormWithToken(token, path); JObject resJSON = JObject.Parse(res1); string res2 = await _submissionService.FindSubmissionsByPage(token, path, 1); JArray jsonArray = JArray.Parse(res2); bool isNotSubmitted = jsonArray.Count == 0; if (isNotSubmitted) { ViewBag.Link = string.Empty; ViewBag.Title = Messages.HAS_NOT_SUBMITTED_MESSAGE; } else { ViewBag.Link = APIs.ModifiedForm(path); ViewBag.Title = resJSON.GetValue(Keywords.TITLE).ToString(); ViewBag.Id = ((JObject)jsonArray[0]).GetValue(Keywords.ID).ToString(); ViewBag.Data = ((JObject)jsonArray[0]).GetValue(Keywords.DATA).ToString(); } ViewBag.User = user; return(View(ViewName.EDIT_REPORT)); } return(View(ViewName.ERROR_404)); }
private async Task <List <Form> > AddFormToList(string token, List <Form> listForm, List <FormControl> listFormControl) { foreach (FormControl formControl in listFormControl) { string path = formControl.PathForm; string start = formControl.Start; string expired = formControl.Expired; int durationPercent = CalculateUtil.GetDurationPercent(start, expired); string typeProgressBar = CalculateUtil.GetTypeProgressBar(durationPercent); string formRes = await _formService.FindFormWithToken(token, path); JObject formResJSON = JObject.Parse(formRes); if (formResJSON.Count == 0) { return(listForm); } string title = formResJSON.GetValue(Keywords.TITLE).ToString(); List <string> tags = new List <string>(); JArray tagsArray = (JArray)formResJSON.GetValue(Keywords.TAGS); foreach (JObject tag in tagsArray) { tags.Add(tag.ToString()); } string submissionsRes = await _submissionService.FindSubmissionsByPage(token, path, 1); JArray submissionResJSON = JArray.Parse(submissionsRes); bool isSubmitted = submissionResJSON.Count != 0; bool isPending = CalculateUtil.IsFormPendingOrExpired(start); listForm.Add(new Form(title, path, start, expired, tags, durationPercent, typeProgressBar, isSubmitted, isPending)); } return(listForm); }