знания сИлА

This commit is contained in:
Алина 2024-05-14 18:58:14 +04:00
parent 26c128572a
commit adc9a97725
6 changed files with 81 additions and 76 deletions

View File

@ -14,79 +14,80 @@ namespace TypographyDatabaseImplement.Implements
public class ClientStorage : IClientStorage
{
public List<ClientViewModel> GetFullList()
{
using var context = new TypographyDatabase();
return context.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFullList()
{
using var context = new TypographyDatabase();
return context.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new TypographyDatabase();
return context.Clients
.Where(x => (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO.Contains(model.ClientFIO)) ||
(!string.IsNullOrEmpty(model.Email) && x.ClientFIO.Contains(model.Email)))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new TypographyDatabase();
return context.Clients
.Where(x => (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO.Contains(model.ClientFIO)) ||
(!string.IsNullOrEmpty(model.Email) && x.ClientFIO.Contains(model.Email)))
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new TypographyDatabase();
return context.Clients
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
(!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) ||
(!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && x.Email == model.Email && x.Password == model.Password))
?.GetViewModel;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new TypographyDatabase();
return context.Clients
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
(!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) ||
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
(!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && x.Email == model.Email && x.Password == model.Password))
?.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new TypographyDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new TypographyDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new TypographyDatabase();
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new TypographyDatabase();
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new TypographyDatabase();
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new TypographyDatabase();
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -12,7 +12,7 @@ using TypographyDatabaseImplement;
namespace TypographyDatabaseImplement.Migrations
{
[DbContext(typeof(TypographyDatabase))]
[Migration("20240513180009_InitialCreate")]
[Migration("20240514095701_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />

View File

@ -27,8 +27,11 @@ namespace TypographyDatabaseImplement.Models
[ForeignKey("ClientId")]
public virtual List<Order> ClientOrders { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
[ForeignKey("ClientId")]
public virtual List<MessageInfo> ClientMessages { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;

View File

@ -83,7 +83,8 @@ namespace TypographyDatabaseImplement.Models
Id = Id,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
ImplementerId = ImplementerId,
ClientEmail = Client.Email,
ImplementerId = ImplementerId,
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
PrintedId = PrintedId,
PrintedName = Printed.PrintedName,

View File

@ -11,6 +11,6 @@
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
"MailLogin": "hmscolossus.r95@gmail.com",
"MailPassword": "fbiv zyz yxpoy fgac"
"MailLogin": "rppiscool@gmail.com",
"MailPassword": "ykol hxqb nynr zozo"
}