Немного фиксов, начал работать над хранилищем для клиента
This commit is contained in:
parent
4e8948cd57
commit
a4a2923b51
@ -10,8 +10,8 @@ namespace ZooContracts.BindingModels
|
||||
public class ClientBindingModel : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ClientFIO { get; set; }
|
||||
public string EMail { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public string EMail { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
69
git/JurasicZoo/ZooDataBaseImplement/Models/Client.cs
Normal file
69
git/JurasicZoo/ZooDataBaseImplement/Models/Client.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using ZooContracts.BindingModels;
|
||||
using ZooContracts.ViewModels;
|
||||
using ZooDataModels.Models;
|
||||
|
||||
namespace ZooDataBaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string EMail { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Route> Routes { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
EMail = model.EMail,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public static Client Create(ClientViewModel model)
|
||||
{
|
||||
return new Client
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
EMail = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
EMail = model.EMail;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = EMail,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
66
git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs
Normal file
66
git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using ZooContracts.BindingModels;
|
||||
using ZooContracts.ViewModels;
|
||||
using ZooDataModels.Enums;
|
||||
using ZooDataModels.Models;
|
||||
|
||||
namespace ZooDataBaseImplement.Models
|
||||
{
|
||||
public class Route : IRouteModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
public virtual Client Client { get; private set; } = new();
|
||||
[Required]
|
||||
public string RouteName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double RoutePrice { get; set; }
|
||||
[Required]
|
||||
public RouteStatus Status { get; private set; } = RouteStatus.Неизвестен;
|
||||
public DateTime DateStart { get; private set; }
|
||||
public DateTime? DateFinish { get; private set; }
|
||||
|
||||
private Dictionary<int, (IPreserveModel, int)>? _routepreserves =
|
||||
null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IPreserveModel, int)> RoutePreserves
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_routepreserves == null)
|
||||
{
|
||||
_routepreserves = Preserves
|
||||
.ToDictionary(recRP => recRP.PreserveID, recRP =>
|
||||
(recRP.Preserve as IPreserveModel, recRP.Count));
|
||||
}
|
||||
return _routepreserves;
|
||||
}
|
||||
}
|
||||
[ForeignKey("PreserveID")]
|
||||
public virtual List<RoutePreserve> Preserves { get; set; } = new();
|
||||
public static Route Create(ZooDatabase context, RouteBindingModel model)
|
||||
{
|
||||
return new Route()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId,
|
||||
Client = context.Clients.First(x => x.Id == model.ClientId),
|
||||
|
||||
};
|
||||
}
|
||||
public void Update(PreserveBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
public PreserveViewModel GetViewModel => new()
|
||||
{
|
||||
};
|
||||
}
|
||||
}
|
24
git/JurasicZoo/ZooDataBaseImplement/Models/RoutePreserve.cs
Normal file
24
git/JurasicZoo/ZooDataBaseImplement/Models/RoutePreserve.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZooDataBaseImplement.Models
|
||||
{
|
||||
public class RoutePreserve
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int RouteID { get; set; }
|
||||
[Required]
|
||||
public int PreserveID { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Preserve Preserve { get; set; } = new();
|
||||
public virtual Route Route { get; set; } = new();
|
||||
}
|
||||
}
|
@ -21,7 +21,10 @@ namespace ZooDataBaseImplement
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Employee> Employees { set; get; }
|
||||
public virtual DbSet<Preserve> Preserves { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Route> Routes { set; get; }
|
||||
public virtual DbSet<RoutePreserve> RoutePreserves { set; get; }
|
||||
public virtual DbSet<Preserve> Preserves { set; get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user