public async Task <string> BuildForm(string token, string formJSON, string path) { HttpResponseMessage response = null; string content = null; if (string.Empty.Equals(path)) { // Create response = await _httpUtil.PostAsync(token, APIs.FORM_URL, formJSON); } else { // Edit response = await _httpUtil.PutAsync(token, APIs.ModifiedForm(path), formJSON); } if (response == null || !response.IsSuccessStatusCode) { return("{}"); } content = await response.Content.ReadAsStringAsync(); return(content); }
public async Task <ActionResult> Edit(string id) { string adminAuthenResult = await AdminAuthentication(); if (!adminAuthenResult.Equals(string.Empty)) { return(View(adminAuthenResult)); } User user = GetUser(); string token = user.Token; string infoRes = await _groupService.FindGroupDataById(token, id); JObject jObject = JObject.Parse(infoRes); JObject dataObject = (JObject)jObject.GetValue(Keywords.DATA); if (dataObject.GetValue(Keywords.ID_PARENT).ToString().Equals(Keywords.ROOT_GROUP)) { return(View(ViewName.ERROR_403)); } ViewBag.Link = APIs.ModifiedForm(Keywords.GROUP); ViewBag.Id = id; ViewBag.Data = JsonConvert.SerializeObject(dataObject); ViewBag.User = user; ViewBag.Title = "Edit Group"; return(View(ViewName.EDIT_REPORT)); }
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)); }
public async Task <bool> DeleteForm(string token, string path) { HttpResponseMessage response = await _httpUtil.DeleteAsync(token, APIs.ModifiedForm(path)); if (response == null) { return(false); } return(response.IsSuccessStatusCode); }
public async Task <ActionResult> Create() { string adminAuthenResult = await AdminAuthentication(); if (!adminAuthenResult.Equals(string.Empty)) { return(View(adminAuthenResult)); } ViewBag.Link = APIs.ModifiedForm(Keywords.GROUP); ViewBag.User = GetUser(); ViewBag.Title = "Create new Group"; return(View(ViewName.SEND_REPORT)); }
public async Task <ActionResult> Anon(string path) { JObject formJSON = JObject.Parse(await _formService.FindFormWithNoToken(path)); if (formJSON.Count == 0) { return(View(ViewName.ERROR_403)); } JArray submissionAccessJSON = (JArray)formJSON.GetValue(Keywords.SUBMISSION_ACCESS); JArray roles = (JArray)((JObject)submissionAccessJSON[4]).GetValue(Keywords.ROLES); if (roles.Count == 0 || !((string)roles[0]).Equals(Keywords.ANONYMOUS)) { return(View(ViewName.ERROR_404)); } ViewBag.Link = APIs.ModifiedForm(path); ViewBag.Title = formJSON.GetValue(Keywords.TITLE).ToString(); return(View(ViewName.SEND_REPORT)); }