From a9a3c0652893a6494e715dcf15f8e873395e4fa6 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Wed, 29 Jun 2022 13:03:33 -0400 Subject: [PATCH] added business layer logic --- DeskHubSharpRevised/BLL/EmailBLL.cs | 99 +++++++++++++++++++++++++++++ DeskHubSharpRevised/BLL/RepoInfo.cs | 46 +++++++++++++- DeskHubSharpRevised/BLL/Request.cs | 66 ++++++++++++++++++- 3 files changed, 208 insertions(+), 3 deletions(-) diff --git a/DeskHubSharpRevised/BLL/EmailBLL.cs b/DeskHubSharpRevised/BLL/EmailBLL.cs index e69de29..9cd3757 100644 --- a/DeskHubSharpRevised/BLL/EmailBLL.cs +++ b/DeskHubSharpRevised/BLL/EmailBLL.cs @@ -0,0 +1,99 @@ +using System; +using DeskHubSharpRevised.Models; +using MailKit; +using MailKit.Net.Smtp; +using MailKit.Security; +using MimeKit; + +namespace DeskHubSharpRevised.BLL; + +public class EmailBLL +{ + private string _name; + private string _message; + private string _emailText; + + public EmailBLL(string name, string message, string emailText) + { + _name = name; + _message = message; + _emailText = emailText; + } + + /// + /// Checks to see if Email is valid to send + /// + /// + private bool IsValidated() + { + if (_name == "") + { + ErrorWindow err = new ErrorWindow(); + err.lbl_title.Content = "Oops."; + err.txtblk_error.Text = "Please fill in your name."; + err.Show(); + return false; + } + if (_message == "") + { + ErrorWindow err = new ErrorWindow(); + err.lbl_title.Content = "Oops."; + err.txtblk_error.Text = "Please fill in your message to the developer."; + err.Show(); + return false; + } + if (_emailText == "") + { + ErrorWindow err = new ErrorWindow(); + err.lbl_title.Content = "Oops."; + err.txtblk_error.Text = "Please fill in your email."; + err.Show(); + return false; + } + + return true; + } + + /// + /// Creates message for user to send + /// + public void CreateMessage() + { + if (IsValidated()) + { + try + { + var email = new Email(); + var err = new ErrorWindow(); + var message = new MimeMessage(); + + message.From.Add(new MailboxAddress($"{_name}", email.FromEmail)); + message.To.Add(new MailboxAddress("Wyatt J. Miller", email.ToEmail)); + message.Subject = $"{_name} requires your attention!"; + message.Body = new TextPart("plain") + { + Text = _message + " " + _emailText + }; + + using (var client = new SmtpClient()) + { + client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect); + client.Authenticate(email.FromEmail, email.Password); + client.Send(message); + client.Disconnect(true); + } + + err.lbl_title.Content = "Thank you!"; + err.txtblk_error.Text = "Thank you for sending your email! We have it and will reply shortly."; + err.Show(); + } + catch (Exception e) + { + ErrorWindow err = new ErrorWindow(); + Console.WriteLine("Exception caught in sending message: {0}", + e.ToString()); + err.Show(); + } + } + } +} \ No newline at end of file diff --git a/DeskHubSharpRevised/BLL/RepoInfo.cs b/DeskHubSharpRevised/BLL/RepoInfo.cs index 1003d54..8536fbe 100644 --- a/DeskHubSharpRevised/BLL/RepoInfo.cs +++ b/DeskHubSharpRevised/BLL/RepoInfo.cs @@ -1,6 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using DeskHubSharpRevised.Models; + namespace DeskHubSharpRevised.BLL; -public class RepoInfo +class RepoInfo { - + public RepoInfo() + { + + } + + /// + /// Return a list for the list box + /// + /// + public List GetRepoInfoList() + { + List stuff = new List(); + + try + { + stuff = RequestList.repoDetail.Select(x => x.full_name).ToList(); + } + catch (Exception) + { + ErrorWindow err = new ErrorWindow(); + err.txtblk_error.Text = "We couldn't gather any data. Does the user exist?"; + err.btn_error_close.Content = "FUCK!"; + err.lbl_title.Content = "Oops!"; + err.Show(); + } + + return stuff; + } + + /// + /// Return a list for the combo box + /// + /// + public List GetBranchNameComboBox() + { + List stuff = RequestList.branchDetail.Select(x => x.name).ToList(); + return stuff; + } } \ No newline at end of file diff --git a/DeskHubSharpRevised/BLL/Request.cs b/DeskHubSharpRevised/BLL/Request.cs index 20b891d..6f7628e 100644 --- a/DeskHubSharpRevised/BLL/Request.cs +++ b/DeskHubSharpRevised/BLL/Request.cs @@ -1,6 +1,70 @@ +using System.Collections.Generic; +using DeskHubSharpRevised.DAL; +using DeskHubSharpRevised.Models; + namespace DeskHubSharpRevised.BLL; public class Request { - + private readonly ApiDataService _api; + private readonly string _query; + + /// + /// Override constructor for the class + /// + /// + public Request(string query) + { + _query = query; + _api = new ApiDataService(_query); + } + + /// + /// Constructor for the class + /// + public Request() + { + + } + + /// + /// Performs the search request + /// + public void PerformSearchRequest() + { + _api.SearchRequest(); + } + + /// + /// Performs the user request + /// + public void PerformUserRequest() + { + _api.UserRequest(); + } + + /// + /// Performs the branch request + /// + public void PerformBranchRequest() + { + _api.BranchRequest(); + } + + /// + /// Performs the local owner request + /// + /// + public Owner GetUserData() + { + Owner owner = new Owner(); + return owner; + } + + public List PerformGetSort() + { + Sort sort = new Sort(); + var sortTerms = sort.GetSortTerms(); + return sortTerms; + } } \ No newline at end of file