Lisov N.A LabWork7 #7
@ -8,6 +8,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
@ -101,11 +102,11 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Invalid fullname of user", nameof(model.FullName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
if (string.IsNullOrEmpty(model.Email) || !Regex.IsMatch(model.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", RegexOptions.IgnoreCase))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid email of user", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
if (string.IsNullOrEmpty(model.Password) || !Regex.IsMatch(model.Password, @"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$", RegexOptions.IgnoreCase))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid password of user", nameof(model.Password));
|
||||
}
|
||||
|
52
DressAtelierBusinessLogic/BusinessLogic/MessageInfoLogic.cs
Normal file
52
DressAtelierBusinessLogic/BusinessLogic/MessageInfoLogic.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
|
||||
public class MessageInfoLogic : IMessageInfoLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IMessageInfoStorage _messageStorage;
|
||||
|
||||
public MessageInfoLogic(IMessageInfoStorage messageStorage,ILogger<MessageInfoLogic> logger)
|
||||
{
|
||||
_messageStorage = messageStorage;
|
||||
_logger = logger;
|
||||
}
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (_messageStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ClientID:{ClientID}. ID:{ ID}", model?.ClientID, model?.ID);
|
||||
|
||||
var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierBusinessLogic.MailEmployee;
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
@ -18,11 +19,14 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
private readonly IClientStorage _clientStorage;
|
||||
private readonly AbstractMailEmployee _mailLogic;
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IClientStorage clientStorage, AbstractMailEmployee mailLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_clientStorage = clientStorage;
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -36,11 +40,19 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Accepted;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
|
||||
var order = _orderStorage.Insert(model);
|
||||
if (order == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
OrderViewModel orderViewModel = _orderStorage.GetElement(new OrderSearchModel { ID = order.ID});
|
||||
ClientViewModel clientViewModel = _clientStorage.GetElement(new ClientSearchModel { ID = orderViewModel.ClientID });
|
||||
|
||||
SendEmail(clientViewModel,orderViewModel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -55,8 +67,14 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
ID = model.ID
|
||||
}).EmployeeID;
|
||||
|
||||
_orderStorage.Update(model);
|
||||
|
||||
OrderViewModel orderViewModel = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID });
|
||||
ClientViewModel clientViewModel = _clientStorage.GetElement(new ClientSearchModel { ID = orderViewModel.ClientID });
|
||||
|
||||
SendEmail(clientViewModel, orderViewModel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -69,7 +87,14 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
ID = model.ID
|
||||
}).EmployeeID;
|
||||
|
||||
_orderStorage.Update(model);
|
||||
|
||||
OrderViewModel orderViewModel = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID });
|
||||
ClientViewModel clientViewModel = _clientStorage.GetElement(new ClientSearchModel { ID = orderViewModel.ClientID });
|
||||
|
||||
SendEmail(clientViewModel, orderViewModel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -89,6 +114,12 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
_logger.LogInformation("Update to in process status. ID:{ID}", model.ID);
|
||||
model.Status = OrderStatus.InProcess;
|
||||
_orderStorage.Update(model);
|
||||
|
||||
OrderViewModel orderViewModel = _orderStorage.GetElement(new OrderSearchModel { ID = model.ID });
|
||||
ClientViewModel clientViewModel = _clientStorage.GetElement(new ClientSearchModel { ID = orderViewModel.ClientID });
|
||||
|
||||
SendEmail(clientViewModel, orderViewModel);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -146,5 +177,37 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
throw new InvalidOperationException("Order with such name already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SendEmail(ClientViewModel clientModel ,OrderViewModel orderModel)
|
||||
{
|
||||
if(clientModel == null && orderModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MailSendInfoBindingModel mailModel;
|
||||
|
||||
if (orderModel.Status == OrderStatus.Accepted)
|
||||
{
|
||||
mailModel = new MailSendInfoBindingModel
|
||||
{
|
||||
Address = clientModel.Email,
|
||||
Subject = $"Order №{orderModel.ID}",
|
||||
Text = $"Your order №{orderModel.ID} by {orderModel.DateCreate} on {orderModel.Sum} was accepted!"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
mailModel = new MailSendInfoBindingModel
|
||||
{
|
||||
Address = clientModel.Email,
|
||||
Subject = $"Order №{orderModel.ID}",
|
||||
Text = $"Order №{orderModel.ID} status was changed to {orderModel.Status}"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
_mailLogic.MailSendAsync(mailModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
@ -0,0 +1,84 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierBusinessLogic.MailEmployee
|
||||
{
|
||||
public abstract class AbstractMailEmployee
|
||||
{
|
||||
protected string _mailLogin = string.Empty;
|
||||
protected string _mailPassword = string.Empty;
|
||||
protected string _smtpClientHost = string.Empty;
|
||||
|
||||
protected int _smtpClientPort;
|
||||
protected string _popHost = string.Empty;
|
||||
protected int _popPort;
|
||||
private readonly IMessageInfoLogic _messageInfoLogic;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public AbstractMailEmployee(ILogger<AbstractMailEmployee> logger, IMessageInfoLogic messageInfoLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoLogic = messageInfoLogic;
|
||||
}
|
||||
|
||||
public void MailConfig(MailConfigBindingModel config)
|
||||
{
|
||||
_mailLogin = config.Login;
|
||||
_mailPassword = config.Password;
|
||||
_smtpClientHost = config.SmtpClientHost;
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPort}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||
}
|
||||
|
||||
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(info.Address) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("Send E-mail: {To}, {Subject}", info.Address, info.Subject);
|
||||
await SendMailAsync(info);
|
||||
}
|
||||
|
||||
public async void MailCheck()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(_popHost) || _popPort == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_messageInfoLogic == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var list = await ReceiveMailAsync();
|
||||
_logger.LogDebug("Check E-Mail: {Count} new emails", list.Count);
|
||||
foreach (var mail in list)
|
||||
{
|
||||
_messageInfoLogic.Create(mail);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
|
||||
}
|
||||
}
|
84
DressAtelierBusinessLogic/MailEmployee/MailKitEmployee.cs
Normal file
84
DressAtelierBusinessLogic/MailEmployee/MailKitEmployee.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Net;
|
||||
using System.Security.Authentication;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MailKit.Net;
|
||||
using MailKit.Security;
|
||||
using MailKit.Net.Pop3;
|
||||
|
||||
namespace DressAtelierBusinessLogic.MailEmployee
|
||||
{
|
||||
public class MailKitEmployee : AbstractMailEmployee
|
||||
{
|
||||
public MailKitEmployee(ILogger<MailKitEmployee> logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic)
|
||||
{
|
||||
|
||||
}
|
||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
using var objMailMessage = new MailMessage();
|
||||
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||
try
|
||||
{
|
||||
objMailMessage.From = new MailAddress(_mailLogin);
|
||||
objMailMessage.To.Add(new MailAddress(info.Address));
|
||||
objMailMessage.Subject = info.Subject; objMailMessage.Body = info.Text;
|
||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||
{
|
||||
var list = new List<MessageInfoBindingModel>();
|
||||
using var client = new Pop3Client();
|
||||
await Task.Run(() => {
|
||||
try
|
||||
{
|
||||
client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect);
|
||||
client.Authenticate(_mailLogin, _mailPassword);
|
||||
for (int i = 0; i < client.Count; i++)
|
||||
{
|
||||
var message = client.GetMessage(i);
|
||||
foreach (var mail in message.From.Mailboxes)
|
||||
{
|
||||
list.Add(new MessageInfoBindingModel
|
||||
{
|
||||
DeliveryDate = message.Date.DateTime,
|
||||
ID = message.MessageId,
|
||||
SenderName = mail.Address,
|
||||
Subject = message.Subject,
|
||||
Body = message.TextBody != null ? message.TextBody : message.HtmlBody
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MailKit.Security.AuthenticationException)
|
||||
{
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
client.Disconnect(true);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
@ -109,5 +109,14 @@ namespace DressAtelierClientApp.Controllers
|
||||
var prod = APIClient.GetRequest<DressViewModel>($"api/main/getdress?dressID={dress}");
|
||||
return count * (prod?.Price ?? 1);
|
||||
}
|
||||
|
||||
[HttpGet] public IActionResult Mail()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientID={APIClient.Client.ID}"));
|
||||
}
|
||||
}
|
||||
}
|
48
DressAtelierClientApp/Views/Home/Mail.cshtml
Normal file
48
DressAtelierClientApp/Views/Home/Mail.cshtml
Normal file
@ -0,0 +1,48 @@
|
||||
@using DressAtelierContracts.ViewModels
|
||||
@model List<MessageInfoViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Mail";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Orders</h1>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Log in</h3>
|
||||
return;
|
||||
}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Date
|
||||
</th>
|
||||
<th>
|
||||
Title
|
||||
</th>
|
||||
<th>
|
||||
Text
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DeliveryDate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Subject)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Body)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -25,6 +25,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Personal data</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Mail">E-mails</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Sign in</a>
|
||||
</li>
|
||||
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.BindingModels
|
||||
{
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string SmtpClientHost { get; set; } = string.Empty;
|
||||
public int SmtpClientPort { get; set; }
|
||||
public string PopHost { get; set; } = string.Empty;
|
||||
public int PopPort { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.BindingModels
|
||||
{
|
||||
public class MailSendInfoBindingModel
|
||||
{
|
||||
public string Address { get; set; } = string.Empty;
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.BindingModels
|
||||
{
|
||||
public class MessageInfoBindingModel : IMessageInfoModel
|
||||
{
|
||||
public string ID { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientID { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DeliveryDate { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IMessageInfoLogic
|
||||
{
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
16
DressAtelierContracts/SearchModels/MessageInfoSearchModel.cs
Normal file
16
DressAtelierContracts/SearchModels/MessageInfoSearchModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.SearchModels
|
||||
{
|
||||
public class MessageInfoSearchModel
|
||||
{
|
||||
public string? ID { get; set; }
|
||||
public int? ClientID { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.StorageContracts
|
||||
{
|
||||
public interface IMessageInfoStorage
|
||||
{
|
||||
List<MessageInfoViewModel> GetFullList();
|
||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
29
DressAtelierContracts/ViewModels/MessageInfoViewModel.cs
Normal file
29
DressAtelierContracts/ViewModels/MessageInfoViewModel.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierContracts.ViewModels
|
||||
{
|
||||
public class MessageInfoViewModel : IMessageInfoModel
|
||||
{
|
||||
public string ID { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientID { get; set; }
|
||||
|
||||
[DisplayName("Sender's name")]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Delivery date")]
|
||||
public DateTime DeliveryDate { get; set; }
|
||||
|
||||
[DisplayName("Message subject")]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Message content")]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
18
DressAtelierDataModels/Models/IMessageInfoModel.cs
Normal file
18
DressAtelierDataModels/Models/IMessageInfoModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierDataModels.Models
|
||||
{
|
||||
public interface IMessageInfoModel
|
||||
{
|
||||
string ID { get; }
|
||||
int? ClientID { get; }
|
||||
string SenderName { get; }
|
||||
DateTime DeliveryDate { get; }
|
||||
string Subject { get; }
|
||||
string Body { get; }
|
||||
}
|
||||
}
|
@ -26,5 +26,6 @@ namespace DressAtelierDatabaseImplementation
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Employee> Employees { set; get; }
|
||||
public virtual DbSet<MessageInfo> Messages { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace DressAtelierDatabaseImplement.Implements
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email) && !model.ID.HasValue) { return null; }
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Clients.FirstOrDefault(x => (!(string.IsNullOrEmpty(model.Email)) && model.Email == x.Email) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel;
|
||||
return context.Clients.FirstOrDefault(x => (!(string.IsNullOrEmpty(model.Email)) && model.Email.Equals(x.Email)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
|
@ -0,0 +1,67 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDatabaseImplement.Models;
|
||||
using DressAtelierDatabaseImplementation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierDatabaseImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.ID))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Messages.Include(x => x.Client).FirstOrDefault(x => x.ID.Equals(model.ID))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientID.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Messages.Include(x => x.Client).Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList() ;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DressAtelierDatabase();
|
||||
return context.Messages.Include(x => x.Client).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
|
||||
using var context = new DressAtelierDatabase();
|
||||
|
||||
model.ClientID = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.ID;
|
||||
|
||||
var message = MessageInfo.Create(model);
|
||||
if (message == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (GetElement(new MessageInfoSearchModel { ID = model.ID }) != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Messages.Add(message);
|
||||
context.SaveChanges();
|
||||
return message.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
296
DressAtelierDatabaseImplement/Migrations/20230422104256_Messages.Designer.cs
generated
Normal file
296
DressAtelierDatabaseImplement/Migrations/20230422104256_Messages.Designer.cs
generated
Normal file
@ -0,0 +1,296 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DressAtelierDatabaseImplementation;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DressAtelierDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DressAtelierDatabase))]
|
||||
[Migration("20230422104256_Messages")]
|
||||
partial class Messages
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FullName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("FullName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.Property<string>("ID")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DeliveryDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Dress", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("DressName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Dresses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.DressMaterial", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("DressID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaterialID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("DressID");
|
||||
|
||||
b.HasIndex("MaterialID");
|
||||
|
||||
b.ToTable("DressMaterials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Material", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Materials");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
|
||||
|
||||
b.Property<int>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("DressID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("EmployeeID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.HasIndex("DressID");
|
||||
|
||||
b.HasIndex("EmployeeID");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.HasOne("DressAtelierDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientID");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.DressMaterial", b =>
|
||||
{
|
||||
b.HasOne("DressAtelierDatabaseImplementation.Models.Dress", "Dress")
|
||||
.WithMany("Materials")
|
||||
.HasForeignKey("DressID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DressAtelierDatabaseImplementation.Models.Material", "Material")
|
||||
.WithMany("DressComponents")
|
||||
.HasForeignKey("MaterialID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Dress");
|
||||
|
||||
b.Navigation("Material");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("DressAtelierDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DressAtelierDatabaseImplementation.Models.Dress", "Dress")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("DressID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("DressAtelierDatabaseImplement.Models.Employee", "Employee")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("EmployeeID");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Dress");
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Dress", b =>
|
||||
{
|
||||
b.Navigation("Materials");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Material", b =>
|
||||
{
|
||||
b.Navigation("DressComponents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DressAtelierDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Messages : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Messages",
|
||||
columns: table => new
|
||||
{
|
||||
ID = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClientID = table.Column<int>(type: "int", nullable: true),
|
||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DeliveryDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Messages", x => x.ID);
|
||||
table.ForeignKey(
|
||||
name: "FK_Messages_Clients_ClientID",
|
||||
column: x => x.ClientID,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "ID");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Messages_ClientID",
|
||||
table: "Messages",
|
||||
column: "ClientID");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Messages");
|
||||
}
|
||||
}
|
||||
}
|
@ -74,6 +74,36 @@ namespace DressAtelierDatabaseImplement.Migrations
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.Property<string>("ID")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int?>("ClientID")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DeliveryDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.ToTable("Messages");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.Dress", b =>
|
||||
{
|
||||
b.Property<int>("ID")
|
||||
@ -183,6 +213,15 @@ namespace DressAtelierDatabaseImplement.Migrations
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplement.Models.MessageInfo", b =>
|
||||
{
|
||||
b.HasOne("DressAtelierDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany()
|
||||
|
||||
.HasForeignKey("ClientID");
|
||||
|
||||
b.Navigation("Client");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DressAtelierDatabaseImplementation.Models.DressMaterial", b =>
|
||||
{
|
||||
b.HasOne("DressAtelierDatabaseImplementation.Models.Dress", "Dress")
|
||||
|
@ -26,6 +26,9 @@ namespace DressAtelierDatabaseImplement.Models
|
||||
[ForeignKey("ClientID")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
[ForeignKey("ClientID")]
|
||||
public virtual List<MessageInfo>? Messages { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
|
55
DressAtelierDatabaseImplement/Models/MessageInfo.cs
Normal file
55
DressAtelierDatabaseImplement/Models/MessageInfo.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierDatabaseImplement.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
|
||||
public string ID { get; private set; } = string.Empty;
|
||||
|
||||
public int? ClientID { get; private set; }
|
||||
|
||||
public string SenderName { get; private set; } = string.Empty;
|
||||
public DateTime DeliveryDate { get; private set; }
|
||||
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
|
||||
public virtual Client? Client { get; private set; }
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfo
|
||||
{
|
||||
ID = model.ID,
|
||||
ClientID = model.ClientID,
|
||||
SenderName = model.SenderName,
|
||||
Body = model.Body,
|
||||
DeliveryDate = model.DeliveryDate,
|
||||
Subject = model.Subject,
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
ClientID = ClientID,
|
||||
SenderName = SenderName,
|
||||
Body = Body,
|
||||
DeliveryDate = DeliveryDate,
|
||||
Subject = Subject,
|
||||
};
|
||||
}
|
||||
}
|
@ -17,11 +17,13 @@ namespace DressAtelierFileImplement
|
||||
private readonly string DressFileName = "Dress.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string EmployeeFileName = "Employee.xml";
|
||||
private readonly string MessageInfoFileName = "Message.xml";
|
||||
public List<Material> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Dress> Dresses { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Employee> Employees { get; private set; }
|
||||
public List<MessageInfo> Messages { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -35,6 +37,7 @@ namespace DressAtelierFileImplement
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName,"Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
public void SaveEmployees() => SaveData(Employees, EmployeeFileName,"Employees",x => x.GetXElement);
|
||||
public void SaveMessages() => SaveData(Messages, MessageInfoFileName, "Messages", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(MaterialFileName, "Component", x => Material.Create(x)!)!;
|
||||
@ -42,6 +45,7 @@ namespace DressAtelierFileImplement
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
Employees = LoadData(EmployeeFileName, "Employee", x => Employee.Create(x)!)!;
|
||||
Messages = LoadData(MessageInfoFileName, "Message", x => MessageInfo.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
|
59
DressAtelierFileImplement/Implements/MessageInfoStorage.cs
Normal file
59
DressAtelierFileImplement/Implements/MessageInfoStorage.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierFileImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public MessageInfoStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.ID))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _source.Messages.FirstOrDefault(x => x.ID.Equals(model.ID))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientID.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return _source.Messages.Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
return _source.Messages.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
var newMessage = MessageInfo.Create(model);
|
||||
if(newMessage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Messages.Add(newMessage);
|
||||
_source.SaveMessages();
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
80
DressAtelierFileImplement/Models/MessageInfo.cs
Normal file
80
DressAtelierFileImplement/Models/MessageInfo.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace DressAtelierFileImplement.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
public string ID { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientID { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DeliveryDate { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfo()
|
||||
{
|
||||
ID = model.ID,
|
||||
ClientID = model.ClientID,
|
||||
SenderName = model.SenderName,
|
||||
DeliveryDate = model.DeliveryDate,
|
||||
Subject = model.Subject,
|
||||
Body = model.Body,
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public static MessageInfo? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new MessageInfo()
|
||||
{
|
||||
ID = element.Attribute("ID")!.Value,
|
||||
ClientID = Convert.ToInt32(element.Attribute("ClientID")!.Value),
|
||||
SenderName = element.Element("SenderName")!.Value,
|
||||
DeliveryDate = Convert.ToDateTime(element.Element("DeliveryDate")!.Value),
|
||||
Subject = element.Attribute("Subject")!.Value,
|
||||
Body = element.Attribute("Body")!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
ClientID = ClientID,
|
||||
SenderName = SenderName,
|
||||
DeliveryDate = DeliveryDate,
|
||||
Subject = Subject,
|
||||
Body = Body
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("MessageInfo", new XAttribute("ID", ID),
|
||||
new XElement("ClientID", ClientID.ToString()),
|
||||
new XElement("SenderName", SenderName),
|
||||
new XElement("DeliveryDate", DeliveryDate),
|
||||
new XElement("Subject", Subject),
|
||||
new XElement("Body", Body),
|
||||
new XElement("SenderName", SenderName));
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ namespace DressAtelierListImplement
|
||||
public List<Dress> Dresses { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Employee> Employees { get; set; }
|
||||
public List<MessageInfo> Messages { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Material>();
|
||||
@ -22,6 +23,7 @@ namespace DressAtelierListImplement
|
||||
Dresses = new List<Dress>();
|
||||
Clients = new List<Client>();
|
||||
Employees = new List<Employee>();
|
||||
Messages = new List<MessageInfo>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
66
DressAtelierListImplement/Implements/MessageInfoStorage.cs
Normal file
66
DressAtelierListImplement/Implements/MessageInfoStorage.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.SearchModels;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierListImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public MessageInfoStorage(DataListSingleton source)
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.ID))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach(var msg in _source.Messages)
|
||||
{
|
||||
if(msg.ID.Equals(model.ID))
|
||||
{
|
||||
return msg.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
var list = new List<MessageInfoViewModel>();
|
||||
foreach(var msg in _source.Messages)
|
||||
{
|
||||
if(msg.ClientID.HasValue && model.ClientID == msg.ClientID)
|
||||
{
|
||||
list.Add(msg.GetViewModel);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
var list = new List<MessageInfoViewModel>();
|
||||
foreach(var msg in _source.Messages)
|
||||
{
|
||||
list.Add(msg.GetViewModel);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
51
DressAtelierListImplement/Models/MessageInfo.cs
Normal file
51
DressAtelierListImplement/Models/MessageInfo.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.ViewModels;
|
||||
using DressAtelierDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DressAtelierListImplement.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
public string ID { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientID { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DeliveryDate { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
ID = model.ID,
|
||||
SenderName = model.SenderName,
|
||||
DeliveryDate = model.DeliveryDate,
|
||||
Subject = model.Subject,
|
||||
Body = model.Body,
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
SenderName = SenderName,
|
||||
DeliveryDate = DeliveryDate,
|
||||
Subject = Subject,
|
||||
Body = Body
|
||||
};
|
||||
}
|
||||
}
|
@ -12,10 +12,12 @@ namespace DressAtelierRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -58,5 +60,22 @@ namespace DressAtelierRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientID)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientID = clientID
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Receiving letters for client error");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using DressAtelierBusinessLogic.BusinessLogic;
|
||||
using DressAtelierBusinessLogic.MailEmployee;
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierDatabaseImplement.Implements;
|
||||
@ -16,12 +18,16 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IDressStorage, DressStorage>();
|
||||
builder.Services.AddTransient<IEmployeeStorage, EmployeeStorage>();
|
||||
builder.Services.AddTransient<IEmployeeStorage,EmployeeStorage>();
|
||||
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IDressLogic, DressLogic>();
|
||||
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
builder.Services.AddTransient<IMessageInfoLogic,MessageInfoLogic>();
|
||||
|
||||
builder.Services.AddSingleton<AbstractMailEmployee,MailKitEmployee>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -32,6 +38,16 @@ builder.Services.AddSwaggerGen(c =>
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
var mailSender = app.Services.GetService<AbstractMailEmployee>();
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
Login = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||
Password = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||
});
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
|
@ -5,5 +5,12 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"SmtpClientHost": "smtp.rambler.ru",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.rambler.ru",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "chelovek.labov@rambler.ru",
|
||||
"MailPassword": "Iloverpp4real"
|
||||
}
|
||||
|
11
SewingDresses/App.config
Normal file
11
SewingDresses/App.config
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="SmtpClientHost" value="smtp.rambler.ru" />
|
||||
<add key="SmtpClientPort" value="587" />
|
||||
<add key="PopHost" value="pop.rambler.ru" />
|
||||
<add key="PopPort" value="995" />
|
||||
<add key="MailLogin" value="chelovek.labov@rambler.ru" />
|
||||
<add key="MailPassword" value="Iloverpp4real" />
|
||||
</appSettings>
|
||||
</configuration>
|
64
SewingDresses/FormEmails.Designer.cs
generated
Normal file
64
SewingDresses/FormEmails.Designer.cs
generated
Normal file
@ -0,0 +1,64 @@
|
||||
namespace SewingDresses
|
||||
{
|
||||
partial class FormEmails
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.emailsGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.emailsGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// emailsGridView
|
||||
//
|
||||
this.emailsGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.emailsGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.emailsGridView.GridColor = System.Drawing.SystemColors.AppWorkspace;
|
||||
this.emailsGridView.Location = new System.Drawing.Point(12, 12);
|
||||
this.emailsGridView.Name = "emailsGridView";
|
||||
this.emailsGridView.RowTemplate.Height = 25;
|
||||
this.emailsGridView.Size = new System.Drawing.Size(776, 426);
|
||||
this.emailsGridView.TabIndex = 0;
|
||||
//
|
||||
// FormEmails
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.emailsGridView);
|
||||
this.Name = "FormEmails";
|
||||
this.Text = "FormEmails";
|
||||
eegov
commented
Заголовок формы оформлен неверно Заголовок формы оформлен неверно
|
||||
this.Load += new System.EventHandler(this.FormEmails_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.emailsGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView emailsGridView;
|
||||
}
|
||||
}
|
53
SewingDresses/FormEmails.cs
Normal file
53
SewingDresses/FormEmails.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SewingDresses
|
||||
{
|
||||
public partial class FormEmails : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoLogic _logic;
|
||||
|
||||
public FormEmails(ILogger<FormEmails> logger, IMessageInfoLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormEmails_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
emailsGridView.DataSource = list;
|
||||
emailsGridView.Columns["ClientID"].Visible = false;
|
||||
emailsGridView.Columns["ID"].Visible = false;
|
||||
emailsGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Loading materials");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error loading materials");
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
SewingDresses/FormEmails.resx
Normal file
60
SewingDresses/FormEmails.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
23
SewingDresses/FormMain.Designer.cs
generated
23
SewingDresses/FormMain.Designer.cs
generated
@ -33,6 +33,7 @@
|
||||
materialsToolStripMenuItem = new ToolStripMenuItem();
|
||||
dressesToolStripMenuItem = new ToolStripMenuItem();
|
||||
clientsToolStripMenuItem = new ToolStripMenuItem();
|
||||
employeesToolStripMenuItem = new ToolStripMenuItem();
|
||||
reportsToolStripMenuItem = new ToolStripMenuItem();
|
||||
materialsListToolStripMenuItem = new ToolStripMenuItem();
|
||||
materialsByDressesToolStripMenuItem = new ToolStripMenuItem();
|
||||
@ -42,7 +43,7 @@
|
||||
createOrderButton = new Button();
|
||||
givenOrderButton = new Button();
|
||||
refreshOrdersButton = new Button();
|
||||
employeesToolStripMenuItem = new ToolStripMenuItem();
|
||||
emailsToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -58,7 +59,7 @@
|
||||
//
|
||||
// directoriesToolStripMenuItem
|
||||
//
|
||||
directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { materialsToolStripMenuItem, dressesToolStripMenuItem, clientsToolStripMenuItem, employeesToolStripMenuItem });
|
||||
directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { materialsToolStripMenuItem, dressesToolStripMenuItem, clientsToolStripMenuItem, employeesToolStripMenuItem, emailsToolStripMenuItem });
|
||||
directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem";
|
||||
directoriesToolStripMenuItem.Size = new Size(75, 20);
|
||||
directoriesToolStripMenuItem.Text = "Directories";
|
||||
@ -84,6 +85,13 @@
|
||||
clientsToolStripMenuItem.Text = "Clients";
|
||||
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
|
||||
//
|
||||
// employeesToolStripMenuItem
|
||||
//
|
||||
employeesToolStripMenuItem.Name = "employeesToolStripMenuItem";
|
||||
employeesToolStripMenuItem.Size = new Size(180, 22);
|
||||
employeesToolStripMenuItem.Text = "Employees";
|
||||
employeesToolStripMenuItem.Click += employeesToolStripMenuItem_Click;
|
||||
//
|
||||
// reportsToolStripMenuItem
|
||||
//
|
||||
reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { materialsListToolStripMenuItem, materialsByDressesToolStripMenuItem, ordersListToolStripMenuItem });
|
||||
@ -159,12 +167,12 @@
|
||||
refreshOrdersButton.UseVisualStyleBackColor = true;
|
||||
refreshOrdersButton.Click += ButtonRef_Click;
|
||||
//
|
||||
// employeesToolStripMenuItem
|
||||
// emailsToolStripMenuItem
|
||||
//
|
||||
employeesToolStripMenuItem.Name = "employeesToolStripMenuItem";
|
||||
employeesToolStripMenuItem.Size = new Size(180, 22);
|
||||
employeesToolStripMenuItem.Text = "Employees";
|
||||
employeesToolStripMenuItem.Click += employeesToolStripMenuItem_Click;
|
||||
emailsToolStripMenuItem.Name = "emailsToolStripMenuItem";
|
||||
emailsToolStripMenuItem.Size = new Size(180, 22);
|
||||
emailsToolStripMenuItem.Text = "Emails";
|
||||
emailsToolStripMenuItem.Click += emailsToolStripMenuItem_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
@ -204,5 +212,6 @@
|
||||
private ToolStripMenuItem clientsToolStripMenuItem;
|
||||
private ToolStripMenuItem startWorkingToolStripMenuItem;
|
||||
private ToolStripMenuItem employeesToolStripMenuItem;
|
||||
private ToolStripMenuItem emailsToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -177,5 +177,14 @@ namespace SewingDresses
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void emailsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormEmails));
|
||||
if (service is FormEmails form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using DressAtelierBusinessLogic.BusinessLogic;
|
||||
using DressAtelierBusinessLogic.MailEmployee;
|
||||
using DressAtelierBusinessLogic.OfficePackage;
|
||||
using DressAtelierBusinessLogic.OfficePackage.Implements;
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierContracts.StorageContracts;
|
||||
using DressAtelierDatabaseImplement.Implements;
|
||||
@ -28,6 +30,28 @@ namespace SewingDresses
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
try
|
||||
{
|
||||
var mailSender = _serviceProvider.GetService<AbstractMailEmployee>();
|
||||
mailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
Login = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
||||
Password = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
|
||||
SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
|
||||
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
|
||||
});
|
||||
// ñîçäàåì òàéìåð
|
||||
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var logger = _serviceProvider.GetService<ILogger>();
|
||||
logger?.LogError(ex, "Working with email error");
|
||||
}
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
@ -43,6 +67,7 @@ namespace SewingDresses
|
||||
services.AddTransient<IDressStorage, DressStorage>();
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IEmployeeStorage, EmployeeStorage>();
|
||||
services.AddTransient<IMessageInfoStorage,MessageInfoStorage>();
|
||||
|
||||
services.AddTransient<IMaterialLogic, MaterialLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
@ -50,7 +75,10 @@ namespace SewingDresses
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
|
||||
services.AddTransient<IWorkImitation, WorkImitation>();
|
||||
services.AddSingleton<AbstractMailEmployee, MailKitEmployee>();
|
||||
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
@ -68,7 +96,10 @@ namespace SewingDresses
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormEmployees>();
|
||||
services.AddTransient<FormEmployee>();
|
||||
services.AddTransient<FormEmails>();
|
||||
}
|
||||
|
||||
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailEmployee>()?.MailCheck();
|
||||
|
||||
}
|
||||
}
|
@ -59,6 +59,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="App.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="ReportOrders.rdlc">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
Loading…
Reference in New Issue
Block a user
Связь настроена не до конца