public async Task <IActionResult> Edit(int id, [Bind("Id,Descr,ReligionId")] Confession confession) { if (id != confession.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(confession); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfessionExists(confession.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ReligionId"] = new SelectList(_context.Religions, "Id", "Descr", confession.ReligionId); return(View(confession)); }
//Search by topic public void FilterResults(DocumentList documentList, bool truncate, bool answers, bool proofs, bool allDocs, string searchTerm) { resultList.Clear(); Log.Info("Filter Results", "Filter has begun processing"); //for (int y = 1; y <= documentList.Count; y++) foreach (Document document in documentList) { if (document.Type == "CONFESSION") { Confession confession = (Confession)document; confession.Filter(searchTerm, truncate); if (confession.Matches >= 1) { resultList.Add(confession); } } else if (document.Type == "CATECHISM") { Catechism catechism = (Catechism)document; catechism.Filter(searchTerm, truncate); if (catechism.Matches >= 1) { resultList.Add(catechism); } } } this.documentList = resultList; this.documentList.MergeSort(DocumentList.OrderEnum.MatchOrder); }
public async Task <Confession> GetConfession(int id) { Confession confession = new Confession(); await Task.Run(() => { using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("select * from posts where posts.Id = " + id + " AND posts.Reply is null", conn); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { confession.Id = Convert.ToInt32(reader["Id"]); confession.Content = reader["Content"].ToString(); confession.Email = reader["Email"].ToString(); confession.Hearts = Convert.ToInt32(reader["Hearts"]); confession.Tags = reader["Tags"].ToString(); confession.CreationTime = reader["creation_time"].ToString(); } } } }); return(confession); }
public async Task OnGetConfessAsync(Confession form) { using (var httpClient = new HttpClient()) { using (var response = await httpClient.PostAsync("https://localhost:44310/tea/confession", new StringContent(JsonConvert.SerializeObject(form), Encoding.UTF8, "application/json"))); } }
public async Task <bool> CreateConfessionAsync(Confession confession) { confession.CreatedDate = DateTime.Now; await _db.Confessions.AddAsync(confession); var create = await _db.SaveChangesAsync(); return(create > 0); }
public async Task OnGetLikeAsync(Confession c) { using (var httpClient = new HttpClient()) { using (var response = await httpClient.PostAsync("https://localhost:44310/tea/post/heart", new StringContent(JsonConvert.SerializeObject(c), Encoding.UTF8, "application/json"))); } await this.GetPost(c.Content, c.Id); }
public async Task <bool> UpdatConfessionAsync(Confession confessionToUpdate) { //var conf = await GetConfessionByIdAsync(confessionToUpdate.Id); //confessionToUpdate.CreatedDate = conf.CreatedDate; _db.Confessions.Update(confessionToUpdate); var update = await _db.SaveChangesAsync(); return(update > 0); }
public async Task HeartPost(Confession post) { await Task.Run(() => { using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("UPDATE posts SET posts.Hearts = posts.Hearts+1 WHERE posts.Id =" + post.Id, conn); using (var reader = cmd.ExecuteReader()); } }); }
public async Task <IActionResult> Create([Bind("Id,Descr,ReligionId")] Confession confession) { if (ModelState.IsValid) { _context.Add(confession); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ReligionId"] = new SelectList(_context.Religions, "Id", "Descr", confession.ReligionId); return(View(confession)); }
public async ValueTask <IActionResult> Get(int id) { Confession confession = await _repo .Item() .Include(c => c.Parish) .Where(c => c.Id == id) .FirstOrDefaultAsync(); if (confession != null) { return(Ok(confession.Convert <Confession, ConfessionInfoViewModel>(_mapper))); } return(NotFound(new { Message = "Occasion not found" })); }
public async ValueTask <IActionResult> Post([FromBody] ConfessionViewModel model) { if (ModelState.IsValid) { Confession confession = model.Convert <ConfessionViewModel, Confession>(_mapper); (bool succeeded, Confession addedConfession, string error) = await _repo.Add(confession); if (succeeded) { return(Ok(addedConfession)); } return(BadRequest(new { Message = error })); } return(BadRequest(new { Errors = ModelState.Values.SelectMany(e => e.Errors).ToList() })); }
public async Task <Confession> PostConfession(Confession post) { // testi 3al string passed to change e table wl e stuff await Task.Run(() => { using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("INSERT INTO posts VALUES (null,'" + post.Content + "','" + post.Email + "','" + post.Tags + "',0,null,null)", conn); using (var reader = cmd.ExecuteReader()); } }); return(post); }
private string ShareListBuilder(string shares, Document document) { string qHeader = "", aHeader = "Answer:", pHeader = "Proofs:", chHeader = ""; List <string> listBuilder = new List <string>(); if (document.Type == "CREED") { Creed creed = (Creed)document; shares += creed.Title; shares += "\r\n"; shares += creed.CreedText; } else if (document.Type == "CATECHISM") { Catechism catechism = (Catechism)document; qHeader = String.Format("QUESTION {0}:", catechism.IDNumber.ToString("d3")); listBuilder.Add(catechism.DocTitle); listBuilder.Add(qHeader); listBuilder.Add(catechism.Question); listBuilder.Add(aHeader); listBuilder.Add(catechism.Answer); listBuilder.Add(pHeader); listBuilder.Add(catechism.Proofs); shares = ""; foreach (string shareElement in listBuilder) { shares += shareElement + "\r\n"; } } else if (document.Type == "CONFESSION") { Confession confession = (Confession)document; chHeader = String.Format("Chapter {0}: {1}", confession.IDNumber, confession.DocTitle); listBuilder.Add(confession.DocTitle); listBuilder.Add(chHeader); listBuilder.Add(confession.Chapter); listBuilder.Add(pHeader); listBuilder.Add(confession.Proofs); shares = ""; foreach (string element in listBuilder) { shares += element + "\r\n"; } } return(shares); }
//Fetches the fragment for display public override Android.Support.V4.App.Fragment GetItem(int position) { Android.Support.V4.App.Fragment frg; if (docPosition > 0) { position = position + 1; } string docTitle = ""; if (documentList.Title == "Results" || documentList.Title == "") { docTitle = documentList[position].DocTitle; } else { docTitle = documentList.Title; } if (documentList[position].Type == "CONFESSION") { docPosition++; Confession confession = (Confession)documentList[position]; frg = (Android.Support.V4.App.Fragment)SearchResultFragment.NewResult(confession.Chapter, confession.Proofs, confession.Title, confession.IDNumber, docTitle, documentList.Truncate, confession.Matches); } else if (documentList[position].Type == "CATECHISM") { docPosition++; Catechism catechism = (Catechism)documentList[position]; frg = (Android.Support.V4.App.Fragment)SearchResultFragment.NewResult(catechism.Question, catechism.Answer, catechism.Proofs, catechism.Title, catechism.IDNumber, docTitle, catechism.Matches, documentList.Truncate); } else if (documentList[position].Type == "CREED") { docPosition++; Creed creed = (Creed)documentList[position]; frg = (Android.Support.V4.App.Fragment)SearchResultFragment.NewResult(creed.DocTitle, documentList.Title, truncate, creed.CreedText, creed.IDNumber, creed.Proofs, creed.Matches); } else { frg = GetItem(position + 1); } Log.Info("Search Adapter", String.Format("{0} Panel Loaded", position)); return(frg); }
public async Task <IActionResult> Create([FromBody] CreateConfessionRequest confessionDto) { var confession = new Confession { Title = confessionDto.Title, Description = confessionDto.Description, UserId = HttpContext.GetUserId(), KnownAs = User.FindFirstValue(ClaimTypes.NameIdentifier), City = confessionDto.City }; var createdConfession = await _repo.CreateConfessionAsync(confession); if (!createdConfession) { return(BadRequest(new { Error = "Unable to create a new confession" })); } // Get the current Url of the browser //var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; // Get the complete url with the new confession object and the Id of it -- localhost:5000://confession/{the new Id} //var locationUri = baseUrl + "/" + ApiRoutes.Confessions.Get.Replace("{confessionId}", confession.Id.ToString()); var locationUri = _uriRepository.GetConfessionUri(confession.Id.ToString()); var response = new ConfessionResponse { Id = confession.Id, Title = confession.Title, Description = confession.Description, City = confession.City, UserId = confession.UserId, KnownAs = confession.KnownAs, CreatedDate = confession.CreatedDate }; return(Created(locationUri, response)); }
/// <summary> /// Search Method /// </summary> /// <param name="query"> Search Term</param> //281 lines of code private void Search(string query) { #region Variable Declaration int docCount = 1; bool truncate = false; Log.Info("Search()", String.Format(Resource.String.search_execution_begins + "")); documentList = new DocumentList(); RadioButton radio = FindViewById <RadioButton>(Resource.Id.viewAllRadio); this.searchFragmentActivity = new SearchFragmentActivity(); AssetManager asset = this.Assets; //string searchTerm = ""; bool proofs = true, answers = true, searchAll = false; string[] fileNames = new string[10]; CheckBox answerCheck = FindViewById <CheckBox>(Resource.Id.AnswerBox), proofCheck = FindViewById <CheckBox>(Resource.Id.proofBox), searchCheck = FindViewById <CheckBox>(Resource.Id.searchAllCheckBox); Spinner spinner = FindViewById <Spinner>(Resource.Id.spinner1); #endregion Spinner spinner2 = FindViewById <Spinner>(Resource.Id.spinner2); spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner1_ItemSelected); spinner2.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner2_ItemSelected); //Search Options #region Search Options // Modify This section if (allOpen) { if (radio.Checked == false) { if (answerCheck.Checked) { answers = false; } else { answers = true; } if (proofCheck.Checked) { proofs = false; } else { proofs = true; } if (searchCheck.Checked) { searchAll = true; fileNames = new[] { "Westminster Confession of Faith 1646.txt", "2nd London Baptist Confession of Faith.txt", "1618 Belgic Confession Of Faith.txt", "1658 Savoy Declaration.txt", "Westminster Larger Catechism.txt", "Westminster Shorter Catechism.txt", "Heidelberg Catechism.txt", "Apostle\'s Creed.txt", "Nicene Creed.txt", "Athanasian Creed.txt" }; docCount = 10; } else { searchAll = false; } } else { answers = true; searchAll = false; docCount = 1; proofs = true; } } else if (catechismOpen) { if (radio.Checked == false) { if (answerCheck.Checked) { answers = false; } else { answers = true; } if (proofCheck.Checked) { proofs = false; } else { proofs = true; } if (searchCheck.Checked) { searchAll = true; fileNames = new[] { "Westminster Larger Catechism.txt", "Westminster Shorter Catechism.txt", "Heidelberg Catechism.txt" }; docCount = 3; } else { searchAll = false; } } else { answers = true; searchAll = false; docCount = 1; proofs = true; } } else if (confessionOpen) { if (radio.Checked != true) { if (proofCheck.Checked) { proofs = false; } else { proofs = true; } if (searchCheck.Checked) { searchAll = true; fileNames = new[] { "Westminster Confession of Faith 1646.txt", "2nd London Baptist Confession of Faith.txt", "1618 Belgic Confession Of Faith.txt", "1658 Savoy Declaration.txt" }; docCount = 4; } else { searchAll = false; } docCount = 1; } else { proofs = true; searchAll = false; docCount = 1; } } else if (creedOpen) { if (searchCheck.Checked) { searchAll = true; docCount = 3; fileNames = new[] { "Apostle\'s Creed.txt", "Nicene Creed.txt", "Athanasian Creed.txt" }; } else { proofs = false; searchAll = false; truncate = false; docCount = 1; } answers = false; } Fill(this.documentList, 1, fileNames, answers, proofs, asset, searchAll); this.documentList.Truncate = truncate; search = query; //Results are truncated to the term if true if (FindViewById <CheckBox>(Resource.Id.truncateCheck).Checked) { truncate = true; } #endregion Log.Info("Search()", String.Format(Resource.String.search_status_sorting + "")); //If topic is filled if (radio.Checked != true && query != "" && FindViewById <RadioButton>(Resource.Id.topicRadio).Checked) { if (FindViewById <RadioButton>(Resource.Id.topicRadio).Checked) { stopwatch.Start(); FilterResults(this.documentList, truncate, answers, proofs, searchAll, query); this.documentList.Reverse(); stopwatch.Stop(); } } //if Chapter is filled else if (FindViewById <RadioButton>(Resource.Id.chapterRadio).Checked & query != "") { int searchInt = Int32.Parse(query); FilterResults(this.documentList, truncate, answers, proofs, searchAll, searchInt); } //if View Document is checked else if (FindViewById <RadioButton>(Resource.Id.viewAllRadio).Checked) { if (!FindViewById <CheckBox>(Resource.Id.searchAllCheckBox).Checked) { query = this.documentList.Title; } else { query = "View All"; } } //Display Results Log.Info("Search Method", "Displaying Results"); if (documentList.Count > 1) { SetContentView(Resource.Layout.search_results); ViewPager viewPager = FindViewById <ViewPager>(Resource.Id.viewpager); SearchAdapter adapter = new SearchAdapter(SupportFragmentManager, this.documentList, query, truncate); //Sets the final state of application this.searchFragmentActivity.DisplayResults(this.documentList, viewPager, adapter, query, 1, truncate); SetTitle(Resource.String.search_results_title); } //Single result or no results found else { stopwatch.Stop(); //If There are no Search Results if (this.documentList.Empty) { #region Error Logging Log.Info("Search()", String.Format("No Results were found for {0}", query)); Toast.MakeText(this, String.Format("No results were found for {0}", query), ToastLength.Long).Show(); #endregion #region Variable Declaration and Assignment SetContentView(Resource.Layout.errorLayout); TextView errorMsg = FindViewById <TextView>(Resource.Id.errorTV); errorMsg.Text = String.Format("No Search Results were found for {0}\r\n\r\n" + "Go back to home page to search for another topic", query); #endregion #region Dialog Box Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this); alert.SetTitle(Resource.String.zero_results_title); alert.SetMessage(String.Format("No Results were found for {0}.\r\n\r\n" + "Do you want to go back and search for another topic?", query)); alert.SetPositiveButton("Yes", (senderAlert, args) => { intent = new Intent(this, Class); searchFragmentActivity = null; this.OnStop(); this.Finish(); StartActivity(intent); }); alert.SetNegativeButton("No", (senderAlert, args) => { alert.Dispose(); }); Dialog dialog = alert.Create(); dialog.Show(); #endregion SetTitle(Resource.String.error_results); } //If there is only 1 search result else { SetTitle(Resource.String.search_results_title); Document document = this.documentList[this.documentList.Count]; //Display Catechism Results if (document.Type == "CATECHISM") { this.SetContentView(Resource.Layout.catechism_Results); TextView questionBox = FindViewById <TextView>(Resource.Id.chapterText); TextView answerBox = FindViewById <TextView>(Resource.Id.answerText); TextView numberBox = FindViewById <TextView>(Resource.Id.confessionChLabel); TextView proofBox = FindViewById <TextView>(Resource.Id.proofText); TextView proofView = FindViewById <TextView>(Resource.Id.proofLabel); TextView docTitleBox = FindViewById <TextView>(Resource.Id.documentTitleLabel); Catechism catechism = (Catechism)document; questionBox.Text = catechism.Question; answerBox.Text = catechism.Answer; numberBox.Text = String.Format("Question {0}: {1}", catechism.IDNumber.ToString(), catechism.Title); proofBox.Text = catechism.Proofs; docTitleBox.Text = catechism.DocTitle; ChangeColor(true, Android.Graphics.Color.Black, questionBox, answerBox, proofBox, numberBox, docTitleBox); ChangeColor(false, Android.Graphics.Color.Black, proofView, FindViewById <TextView>(Resource.Id.catechismAnswerLabel)); shareList = docTitleBox.Text + newLine + String.Format("Question {0}:", catechism.IDNumber.ToString("d3")) + newLine + questionBox.Text + newLine + "Answer:" + newLine + answerBox.Text + newLine + "Proofs:" + newLine + proofBox.Text; FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.shareActionButton); ChangeColor(fab, Android.Graphics.Color.Black); fab.Click += ShareContent; } //Display Confession Results else if (document.Type == "CONFESSION") { SetContentView(Resource.Layout.confession_results); TextView chapterBox = FindViewById <TextView>(Resource.Id.chapterText); TextView proofBox = FindViewById <TextView>(Resource.Id.proofText); TextView chNumbBox = FindViewById <TextView>(Resource.Id.confessionChLabel); TextView docTitleBox = FindViewById <TextView>(Resource.Id.documentTitleLabel); Confession confession = (Confession)document; chapterBox.Text = confession.Chapter; chNumbBox.Text = String.Format("Chapter {0} : {1}", confession.IDNumber.ToString(), confession.Title); proofBox.Text = confession.Proofs; docTitleBox.Text = confession.DocTitle; TextView proofView = FindViewById <TextView>(Resource.Id.proofLabel); ChangeColor(true, Android.Graphics.Color.Black, chapterBox, proofBox, chNumbBox, docTitleBox); ChangeColor(proofView, false, Android.Graphics.Color.Black); shareList = docTitleBox.Text + newLine + chNumbBox.Text + newLine + chapterBox.Text + newLine + "Proofs" + newLine + proofBox.Text; FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.shareActionButton); ChangeColor(fab, Android.Graphics.Color.Black); fab.Click += ShareContent; } //Display Creed Results else if (document.Type == "CREED") { SetContentView(Resource.Layout.creed_Results); Creed creed = (Creed)document; TextView creedBox = FindViewById <TextView>(Resource.Id.chapterText); TextView titleBox = FindViewById <TextView>(Resource.Id.documentTitleLabel); SetTitle(Resource.String.search_results_title); creedBox.Text = creed.CreedText; titleBox.Text = documentList.Title; shareList = titleBox.Text + newLine + creed.CreedText; FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.shareActionButton); ChangeColor(fab, Android.Graphics.Color.Black); ChangeColor(true, Android.Graphics.Color.Black, creedBox, titleBox); fab.Click += ShareContent; } } } Toast.MakeText(this, String.Format("Search Completed for {0}" + "\r\n" + "{1} ms Passed", query, stopwatch.ElapsedMilliseconds.ToString()), ToastLength.Long).Show(); }
public async Task <Confession> PostConfession([FromBody] Confession c) { return(await this.UWS.PostConfession(c)); }
public async Task HeartPost([FromBody] Confession c) => await this.UWS.HeartPost(c);