фиксы
This commit is contained in:
parent
33b6a149e6
commit
35b5df3d58
@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}"
|
||||||
EndProject
|
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
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{6DDC0CCD-97E0-4CB7-8024-C27DB9AEF97B}.Release|Any CPU.Build.0 = 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
|
{4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4F1E898C-449A-4A60-95D8-BC7818019644}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{298D21A7-C230-43AF-BD9E-752BE7A25ADC}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4F1E898C-449A-4A60-95D8-BC7818019644}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{71B443EA-7014-4137-A2BD-25E8414CF6A3}.Release|Any CPU.Build.0 = Release|Any CPU
|
{CEB61A52-7C4D-45CC-A48B-E52B295EE28E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -17,15 +17,15 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
private readonly AbstractMailWorker _mailWorker;
|
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;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
_clientLogic = clientLogic;
|
_clientStorage = clientStorage;
|
||||||
_mailWorker = mailWorker;
|
_mailWorker = mailWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +61,10 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
var orderView = _orderStorage.GetElement(new() { Id = result.Id });
|
||||||
{
|
var clientView = _clientStorage.GetElement(new() { Id = orderView!.ClientId });
|
||||||
MailAddress = result.ClientEmail,
|
|
||||||
Subject = $"Изменение статуса заказа номер {result.Id}",
|
SendEmail(clientView, orderView);
|
||||||
Text = $"Ваш заказ №{result.Id} на покупку цветов {result.WorkName} от {result.DateCreate} на сумму {result.Sum} принят."
|
|
||||||
}));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,27 +115,46 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
if (model.Status == OrderStatus.Выдан)
|
if (model.Status == OrderStatus.Выдан)
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now;
|
||||||
var result = _orderStorage.Update(model);
|
_orderStorage.Update(model);
|
||||||
|
var orderView = _orderStorage.GetElement(new() { Id = model.Id });
|
||||||
|
var clientView = _clientStorage.GetElement(new() { Id = orderView!.ClientId });
|
||||||
|
|
||||||
|
SendEmail(clientView, orderView);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
private bool SendOrderStatusMail(int clientId, string subject, string text)
|
public void SendEmail(ClientViewModel clientModel, OrderViewModel orderModel)
|
||||||
{
|
{
|
||||||
var client = _clientLogic.ReadElement(new() { Id = clientId });
|
if (clientModel == null && orderModel == null)
|
||||||
|
|
||||||
if (client == null)
|
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
|
MailSendInfoBindingModel mailModel;
|
||||||
|
|
||||||
|
if (orderModel.Status == OrderStatus.Принят)
|
||||||
{
|
{
|
||||||
MailAddress = client.Email,
|
mailModel = new MailSendInfoBindingModel
|
||||||
Subject = subject,
|
{
|
||||||
Text = text
|
MailAddress = clientModel.Email,
|
||||||
});
|
Subject = $"Order №{orderModel.Id}",
|
||||||
return true;
|
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)
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
@ -6,17 +6,17 @@ namespace PlumbingRepairBusinessLogic.MailWorker
|
|||||||
{
|
{
|
||||||
public abstract class AbstractMailWorker
|
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;
|
private readonly IMessageInfoLogic _messageInfoLogic;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new PlumbingRepairDatabase();
|
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)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
@ -24,57 +24,47 @@ namespace PlumbingRepairDatabaseImplement.Implements
|
|||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.Id.HasValue && !model.ImplementerId.HasValue && !model.Status.HasValue)
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
using var context = new PlumbingRepairDatabase();
|
using var context = new PlumbingRepairDatabase();
|
||||||
if (model.Id.HasValue)
|
|
||||||
return AttachNames(context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Work)
|
.Include(x => x.Work)
|
||||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
.Include(x => x.Client)
|
||||||
?.GetViewModel);
|
|
||||||
else if (model.ImplementerId.HasValue && model.Status.HasValue)
|
|
||||||
return AttachNames(context.Orders
|
|
||||||
.Include(x => x.Implementer)
|
.Include(x => x.Implementer)
|
||||||
.FirstOrDefault(x => model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
|
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)
|
||||||
?.GetViewModel);
|
|| (model.ImplementerId.HasValue && model.Status.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))?
|
||||||
return null;
|
.GetViewModel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new PlumbingRepairDatabase();
|
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
|
return context.Orders
|
||||||
.Where(x => x.Id == model.Id)
|
.Include(x => x.Work)
|
||||||
.Select(x => AttachNames(x.GetViewModel)).ToList();
|
.Include(x => x.Client)
|
||||||
}
|
.Include(x => x.Implementer)
|
||||||
if (model.Status.HasValue)
|
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|
||||||
{
|
|| (model.ClientId.HasValue && x.ClientId == model.ClientId)
|
||||||
return context.Orders
|
|| (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
|
||||||
.Where(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)
|
|| (model.Status.HasValue && x.Status == model.Status))
|
||||||
.Select(x => AttachNames(x.GetViewModel)).ToList();
|
.Select(x => 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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
@ -83,6 +73,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
|
|||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Work)
|
.Include(x => x.Work)
|
||||||
.Include(x => x.Implementer)
|
.Include(x => x.Implementer)
|
||||||
|
.Include(x => x.Client)
|
||||||
.Select(x =>AttachNames(x.GetViewModel))
|
.Select(x =>AttachNames(x.GetViewModel))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -104,7 +95,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new PlumbingRepairDatabase();
|
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)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@ -133,6 +124,7 @@ namespace PlumbingRepairDatabaseImplement.Implements
|
|||||||
if (client.Id == model.ClientId)
|
if (client.Id == model.ClientId)
|
||||||
{
|
{
|
||||||
model.ClientFIO = client.ClientFIO;
|
model.ClientFIO = client.ClientFIO;
|
||||||
|
model.ClientEmail = client.Email;
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ using PlumbingRepairDatabaseImplement;
|
|||||||
namespace PlumbingRepairDatabaseImplement.Migrations
|
namespace PlumbingRepairDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PlumbingRepairDatabase))]
|
[DbContext(typeof(PlumbingRepairDatabase))]
|
||||||
[Migration("20240502155936_InitCreate")]
|
[Migration("20240503080749_InitCreate")]
|
||||||
partial class InitCreate
|
partial class InitCreate
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
@ -14,6 +14,7 @@ namespace PlumbingRepairDatabaseImplement.Models
|
|||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
public int? ImplementerId { get; set; }
|
public int? ImplementerId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
@ -68,6 +69,7 @@ namespace PlumbingRepairDatabaseImplement.Models
|
|||||||
ImplementerId= ImplementerId,
|
ImplementerId= ImplementerId,
|
||||||
ImplementerFIO = Implementer == null ? null : Implementer.ImplementerFIO,
|
ImplementerFIO = Implementer == null ? null : Implementer.ImplementerFIO,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
|
ClientEmail = Client.Email,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
|
Loading…
Reference in New Issue
Block a user