фиксы

This commit is contained in:
sardq 2024-05-03 12:37:02 +04:00
parent 33b6a149e6
commit 35b5df3d58
7 changed files with 106 additions and 95 deletions

View File

@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairClientApp", "..\..\PlumbingRepair 5 усложненная\PlumbingRepairClientApp\PlumbingRepairClientApp.csproj", "{298D21A7-C230-43AF-BD9E-752BE7A25ADC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairClientApp", "..\..\PlumbingRepair 7 база\PlumbingRepairClientApp\PlumbingRepairClientApp.csproj", "{4F1E898C-449A-4A60-95D8-BC7818019644}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairRestApi", "..\..\PlumbingRepair 5 усложненная\PlumbingRepairRestApi\PlumbingRepairRestApi.csproj", "{71B443EA-7014-4137-A2BD-25E8414CF6A3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairRestApi", "..\..\PlumbingRepair 7 база\PlumbingRepairRestApi\PlumbingRepairRestApi.csproj", "{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -55,14 +55,14 @@ Global
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.Build.0 = Release|Any CPU
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Release|Any CPU.Build.0 = Release|Any CPU
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Release|Any CPU.Build.0 = Release|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.Build.0 = Release|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -17,15 +17,15 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage;
private readonly AbstractMailWorker _mailWorker;
private readonly IClientLogic _clientLogic;
private readonly IClientStorage _clientStorage;
private readonly object _locker =new();
private readonly object _locker =new();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IClientLogic clientLogic, AbstractMailWorker mailWorker)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IClientStorage clientStorage, AbstractMailWorker mailWorker)
{
_logger = logger;
_orderStorage = orderStorage;
_clientLogic = clientLogic;
_clientStorage = clientStorage;
_mailWorker = mailWorker;
}
@ -61,13 +61,11 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
_logger.LogWarning("Insert operation failed");
return false;
}
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = result.ClientEmail,
Subject = $"Изменение статуса заказа номер {result.Id}",
Text = $"Ваш заказ №{result.Id} на покупку цветов {result.WorkName} от {result.DateCreate} на сумму {result.Sum} принят."
}));
return true;
var orderView = _orderStorage.GetElement(new() { Id = result.Id });
var clientView = _clientStorage.GetElement(new() { Id = orderView!.ClientId });
SendEmail(clientView, orderView);
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
@ -117,28 +115,47 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан)
model.DateImplement = DateTime.Now;
var result = _orderStorage.Update(model);
return true;
_orderStorage.Update(model);
var orderView = _orderStorage.GetElement(new() { Id = model.Id });
var clientView = _clientStorage.GetElement(new() { Id = orderView!.ClientId });
SendEmail(clientView, orderView);
return true;
}
private bool SendOrderStatusMail(int clientId, string subject, string text)
{
var client = _clientLogic.ReadElement(new() { Id = clientId });
public void SendEmail(ClientViewModel clientModel, OrderViewModel orderModel)
{
if (clientModel == null && orderModel == null)
{
return;
}
if (client == null)
{
return false;
}
MailSendInfoBindingModel mailModel;
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = client.Email,
Subject = subject,
Text = text
});
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
if (orderModel.Status == OrderStatus.Принят)
{
mailModel = new MailSendInfoBindingModel
{
MailAddress = clientModel.Email,
Subject = $"Order №{orderModel.Id}",
Text = $"Your order №{orderModel.Id} by {orderModel.DateCreate} on {orderModel.Sum} was accepted!"
};
}
else
{
mailModel = new MailSendInfoBindingModel
{
MailAddress = clientModel.Email,
Subject = $"Order №{orderModel.Id}",
Text = $"Order №{orderModel.Id} status was changed to {orderModel.Status}"
};
}
_mailWorker.MailSendAsync(mailModel);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{

View File

@ -6,17 +6,17 @@ namespace PlumbingRepairBusinessLogic.MailWorker
{
public abstract class AbstractMailWorker
{
protected string _mailLogin = string.Empty;
protected static string _mailLogin = string.Empty;
protected string _mailPassword = string.Empty;
protected static string _mailPassword = string.Empty;
protected string _smtpClientHost = string.Empty;
protected static string _smtpClientHost = string.Empty;
protected int _smtpClientPort;
protected static int _smtpClientPort;
protected string _popHost = string.Empty;
protected static string _popHost = string.Empty;
protected int _popPort;
protected static int _popPort;
private readonly IMessageInfoLogic _messageInfoLogic;

View File

@ -12,7 +12,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new PlumbingRepairDatabase();
var element = context.Orders.Include(x => x.Work).FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Orders.Include(x => x.Work).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
@ -24,57 +24,47 @@ namespace PlumbingRepairDatabaseImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new PlumbingRepairDatabase();
if (model.Id.HasValue)
return AttachNames(context.Orders
.Include(x => x.Work)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel);
else if (model.ImplementerId.HasValue && model.Status.HasValue)
return AttachNames(context.Orders
.Include(x => x.Implementer)
.FirstOrDefault(x => model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
?.GetViewModel);
return null;
}
if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.Status.HasValue)
return null;
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
using var context = new PlumbingRepairDatabase();
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)
|| (model.ImplementerId.HasValue && model.Status.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))?
.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
using var context = new PlumbingRepairDatabase();
if (model.DateFrom.HasValue)
{
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
&& (!model.ClientId.HasValue || x.ClientId == model.ClientId))
.Select(x => x.GetViewModel)
.ToList();
}
if (model.Id.HasValue)
{
return context.Orders
.Where(x => x.Id == model.Id)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
if (model.Status.HasValue)
{
return context.Orders
.Where(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
.Include(x => x.Client).
Where(x => x.ClientId == model.ClientId)
.Select(x =>AttachNames(x.GetViewModel)).ToList();
}
if (model.DateFrom != null && model.DateTo != null)
{
return context.Orders.
Include(x => x.Work)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => AttachNames(x.GetViewModel)).ToList();
}
return new();
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|| (model.ClientId.HasValue && x.ClientId == model.ClientId)
|| (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
|| (model.Status.HasValue && x.Status == model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
@ -83,6 +73,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
return context.Orders
.Include(x => x.Work)
.Include(x => x.Implementer)
.Include(x => x.Client)
.Select(x =>AttachNames(x.GetViewModel))
.ToList();
}
@ -104,7 +95,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new PlumbingRepairDatabase();
var order = context.Orders.Include(x => x.Work).FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders.Include(x => x.Work).Include(x => x.Implementer).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
@ -133,6 +124,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
if (client.Id == model.ClientId)
{
model.ClientFIO = client.ClientFIO;
model.ClientEmail = client.Email;
return model;
}
}

View File

@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement;
namespace PlumbingRepairDatabaseImplement.Migrations
{
[DbContext(typeof(PlumbingRepairDatabase))]
[Migration("20240502155936_InitCreate")]
[Migration("20240503080749_InitCreate")]
partial class InitCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -14,6 +14,7 @@ namespace PlumbingRepairDatabaseImplement.Models
public int ClientId { get; set; }
public int? ImplementerId { get; set; }
[Required]
public int Count { get; set; }
[Required]
@ -68,7 +69,8 @@ namespace PlumbingRepairDatabaseImplement.Models
ImplementerId= ImplementerId,
ImplementerFIO = Implementer == null ? null : Implementer.ImplementerFIO,
Count = Count,
Sum = Sum,
ClientEmail = Client.Email,
Sum = Sum,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,