//This is used for keeping track of number of characters typed and changes the Paragraph box text color depending on the character matching private void InputBox_TextChanged(object sender, EventArgs e) { CharactersTypedLB.Text = InputBox.Text.Length.ToString(); Mistype_Count(); if (InputBox.TextLength == ParagraphBox.TextLength) { InputBox.Enabled = false; timer1.Stop(); Result(); } if (InputBox.TextLength == 0) { ParagraphBox.SelectAll(); ParagraphBox.SelectionBackColor = System.Drawing.ColorTranslator.FromHtml("#F0F0F0"); } else { int i = InputBox.TextLength - 1; if (InputBox.Text[i].ToString() != ParagraphBox.Text[i].ToString()) { ParagraphBox_Color_Change(i, "Red"); } else if (InputBox.Text[i].ToString() == ParagraphBox.Text[i].ToString()) { ParagraphBox_Color_Change(i, "Blue"); } } }
//Component Edit Methods public ActionResult <ParagraphBox> EditParagraphBoxMethod(ParagraphBox paragraph_box, int admin_id, string admin_token, int site_id) { //check available (better way to do this?) ParagraphBox queried_paragraph_box; try{ queried_paragraph_box = dbQuery.QueryParagraphBoxById(paragraph_box.paragraph_box_id); }catch { JsonFailure f = new JsonFailure($"paragraph_box Id: {paragraph_box.paragraph_box_id} not found."); return(StatusCode(400, f)); } //verify and change if (authenticator.VerifyAdminForLeaf(admin_id, queried_paragraph_box.site_id, admin_token)) { DataPlan data_plan; try{ data_plan = _dataLimiter.ValidateDataPlanB(admin_id, queried_paragraph_box, paragraph_box); }catch (System.ArgumentException e) { return(StatusCode(400, e.Message)); } ParagraphBox changed_tcb = dbQuery.EditParagraphBox(paragraph_box); _dataLimiter.UpdateDataPlan(data_plan); return(paragraph_box); } else { return(StatusCode(400, "Invalid credentials.")); } }
public ActionResult <JsonResponse> PostBoxMethod(ParagraphBox NewBox, int admin_id, string admin_token) { if (authenticator.VerifyAdminForLeaf(admin_id, NewBox.site_id, admin_token)) { List <string> errors = authenticator.ValidateIncomingComponent(NewBox); if (errors.Count == 0) { DataPlan data_plan; try{ data_plan = _dataLimiter.ValidateComponentAdditionForDataPlan(admin_id, NewBox); }catch (System.ArgumentException e) { return(StatusCode(400, e.Message)); } NewBox.byte_size = NewBox.FindCharLength(); dbQuery.AddParagraphBox(NewBox); _dataLimiter.UpdateDataPlan(data_plan); JsonResponse r = new JsonSuccess("Paragraph box posted sucessfully!"); return(r); } else { return(StatusCode(400, errors)); } } else { return(StatusCode(400, "Invalid Token. Stranger Danger.")); } }
public ActionResult <ParagraphBox> GetParagraphBoxMethod(int p_box_id) { try{ ParagraphBox paragraph_box = dbQuery.QueryParagraphBoxById(p_box_id); return(paragraph_box); }catch { return(StatusCode(400, "Component Not Found")); } }
//Function for Paragraph box text color changing private void ParagraphBox_Color_Change(int start, string color) { ParagraphBox.Select(start, 1); if (color == "Blue") { ParagraphBox.SelectionBackColor = Color.SkyBlue; } else if (color == "Red") { ParagraphBox.SelectionBackColor = Color.Red; } ParagraphBox.Select(InputBox.TextLength, ParagraphBox.TextLength); ParagraphBox.SelectionBackColor = System.Drawing.ColorTranslator.FromHtml("#F0F0F0"); return; }
public ActionResult <JsonResponse> DeleteAuthenticatedSiteComponentMethod(ComponentReference Component) { if (Component.component_type == "p_box") { try{ ParagraphBox paragraph_box = dbQuery.DeleteParagraphBox(Component.component_id); Site parent_site = dbQuery.QueryFeaturelessSiteById(paragraph_box.site_id); _dataLimiter.RemoveFromDataPlan(paragraph_box, parent_site.admin_id); JsonResponse r = new JsonSuccess("Paragraph box deleted sucessfully!"); return(r); }catch { JsonFailure f = new JsonFailure($"Unable to find paragraph box id {Component.component_id}"); return(StatusCode(400, f)); } } else if (Component.component_type == "image") { try{ Image image = dbQuery.DeleteImage(Component.component_id); Site parent_site = dbQuery.QueryFeaturelessSiteById(image.site_id); _dataLimiter.RemoveFromDataPlan(image, parent_site.admin_id); JsonResponse r = new JsonSuccess("Image deleted sucessfully!"); return(r); }catch { JsonFailure f = new JsonFailure($"Unable to find image id {Component.component_id}"); return(StatusCode(400, f)); } } else if (Component.component_type == "portrait") { try{ Portrait portrait = dbQuery.DeletePortrait(Component.component_id); Site parent_site = dbQuery.QueryFeaturelessSiteById(portrait.site_id); _dataLimiter.RemoveFromDataPlan(portrait, parent_site.admin_id); JsonResponse r = new JsonSuccess("Portrait component deleted sucessfully!"); return(r); }catch { JsonFailure f = new JsonFailure($"Unable to find portrait id {Component.component_id}"); return(StatusCode(400, f)); } } else if (Component.component_type == "2c_box") { try{ TwoColumnBox two_column_box = dbQuery.DeleteTwoColumnBox(Component.component_id); Site parent_site = dbQuery.QueryFeaturelessSiteById(two_column_box.site_id); _dataLimiter.RemoveFromDataPlan(two_column_box, parent_site.admin_id); JsonResponse r = new JsonSuccess("Two Column Box component deleted sucessfully!"); return(r); }catch { JsonFailure f = new JsonFailure($"Unable to find two column box id {Component.component_id}"); return(StatusCode(400, f)); } } else if (Component.component_type == "link_box") { try{ LinkBox link_box = dbQuery.DeleteLinkBox(Component.component_id); Site parent_site = dbQuery.QueryFeaturelessSiteById(link_box.site_id); _dataLimiter.RemoveFromDataPlan(link_box, parent_site.admin_id); JsonResponse r = new JsonSuccess("Link Box component deleted sucessfully!"); return(r); }catch { JsonFailure f = new JsonFailure($"Unable to find link box id {Component.component_id}"); return(StatusCode(400, f)); } } else { JsonFailure f = new JsonFailure("Type mismatch. Type does not match any known components."); return(StatusCode(400, f)); } }
public ActionResult <ParagraphBox> EditParagraphBox([FromBody] ParagraphBox updated_paragraph_box, int admin_id, string admin_token, int site_id) { return(methods.EditParagraphBoxMethod(updated_paragraph_box, admin_id, admin_token, site_id)); }
public ActionResult <JsonResponse> PostBox([FromBody] string _paragraph_box, int admin_id, string admin_token) { ParagraphBox NewBox = JsonSerializer.Deserialize <ParagraphBox>(_paragraph_box); return(methods.PostBoxMethod(NewBox, admin_id, admin_token)); }