added business layer logic
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Checks to see if Email is valid to send
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Creates message for user to send
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    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();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Return a list for the list box
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public List<string> GetRepoInfoList()
 | 
			
		||||
    {
 | 
			
		||||
        List<string> stuff = new List<string>();
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Return a list for the combo box
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public List<string> GetBranchNameComboBox()
 | 
			
		||||
    {
 | 
			
		||||
        List<string> stuff = RequestList.branchDetail.Select(x => x.name).ToList();
 | 
			
		||||
        return stuff;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Override constructor for the class
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="query"></param>
 | 
			
		||||
    public Request(string query)
 | 
			
		||||
    {
 | 
			
		||||
        _query = query;
 | 
			
		||||
        _api = new ApiDataService(_query);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Constructor for the class
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public Request()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Performs the search request 
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public void PerformSearchRequest()
 | 
			
		||||
    {
 | 
			
		||||
        _api.SearchRequest();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Performs the user request
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public void PerformUserRequest()
 | 
			
		||||
    {
 | 
			
		||||
        _api.UserRequest();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Performs the branch request
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public void PerformBranchRequest()
 | 
			
		||||
    {
 | 
			
		||||
        _api.BranchRequest();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Performs the local owner request
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <returns></returns>
 | 
			
		||||
    public Owner GetUserData()
 | 
			
		||||
    {
 | 
			
		||||
        Owner owner = new Owner();
 | 
			
		||||
        return owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<string> PerformGetSort()
 | 
			
		||||
    {
 | 
			
		||||
        Sort sort = new Sort();
 | 
			
		||||
        var sortTerms = sort.GetSortTerms();
 | 
			
		||||
        return sortTerms;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user