ISEbd-21 Melnikov I.O. Lab Work 05 Base #11
@ -3,7 +3,9 @@ using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||||
using BlacksmithWorkshopContracts.SearchModels;
|
||||
using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using DocumentFormat.OpenXml.InkML;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Net;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -102,6 +104,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с таким адресом электронной почты уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ namespace BlacksmithWorkshopContracts.ViewModels
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int ManufactureId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string ManufactureName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
|
@ -5,6 +5,7 @@ namespace BlacksmithWorkshopDataModels.Models
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int ManufactureId { get; }
|
||||
int ClientId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -28,21 +28,20 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
if (!model.Id.HasValue && (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ClientViewModel? result = null;
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
result = context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model.Id.HasValue)//сначала ищем по Id
|
||||
{
|
||||
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
result = context.Clients.FirstOrDefault(x => x.Email.Contains(model.Email) && x.Password.Contains(model.Password))?.GetViewModel;
|
||||
else if (!string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))//затем по логину
|
||||
{
|
||||
return context.Clients.FirstOrDefault(x => x.Email == model.Email)?.GetViewModel;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))//затем по логину и паролю
|
||||
{
|
||||
return context.Clients.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
@ -51,11 +50,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var existingClient = context.Clients.FirstOrDefault(x => x.Email == newClient.Email);//проверка на уникальность
|
||||
if (existingClient != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient.GetViewModel;
|
||||
|
@ -32,12 +32,20 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
}
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.ClientFIO))
|
||||
if (model.Id.HasValue)//сначала ищем по Id
|
||||
{
|
||||
return null;
|
||||
return source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
return source.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))//затем по логину
|
||||
{
|
||||
return source.Clients.FirstOrDefault(x => x.Email == model.Email)?.GetViewModel;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))//затем по логину и паролю
|
||||
{
|
||||
return source.Clients.FirstOrDefault(x => x.Email == model.Email && x.Password == model.Password)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
|
||||
|
@ -17,6 +17,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
private OrderViewModel AddManufactureAndClientName (OrderViewModel model)
|
||||
{
|
||||
model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty;
|
||||
model.ClientFIO = source.Clients.SingleOrDefault(x => x.Id == model.ClientId)?.ClientFIO ?? string.Empty;
|
||||
return model;
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
|
@ -53,6 +53,10 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
{
|
||||
return client.GetViewModel;
|
||||
}
|
||||
if (model.Email != null && client.Email.Contains(model.Email) && model.Password == null)//затем по логину
|
||||
{
|
||||
return client.GetViewModel;
|
||||
}
|
||||
if (model.Email != null && client.Email.Contains(model.Email) && model.Password != null && client.Password.Contains(model.Password))//затем по логину и паролю
|
||||
{
|
||||
return client.GetViewModel;
|
||||
@ -69,10 +73,6 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
{
|
||||
model.Id = client.Id + 1;
|
||||
}
|
||||
if (client.Email == model.Email)//проверка на уникальность
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var res = Client.Create(model);
|
||||
if (res != null)
|
||||
|
Loading…
Reference in New Issue
Block a user