2023-05-09 22:54:35 +04:00
|
|
|
|
using MongoDB.Bson.Serialization.Attributes;
|
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TransportCompanyContracts.BindingModels;
|
|
|
|
|
using TransportCompanyContracts.ViewModels;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
|
|
|
|
|
namespace TransportCompamyMongoDBImplementer.Models
|
|
|
|
|
{
|
|
|
|
|
public class Trucking
|
|
|
|
|
{
|
|
|
|
|
[BsonId]
|
|
|
|
|
[BsonRepresentation(BsonType.ObjectId)]
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
public double Price { get; set; }
|
|
|
|
|
|
|
|
|
|
public DateTime DateStart { get; set; }
|
|
|
|
|
|
|
|
|
|
public DateTime DateEnd { get; set; }
|
|
|
|
|
|
2023-05-10 12:27:29 +04:00
|
|
|
|
public Cargo Cargo { get; set; }
|
2023-05-09 22:54:35 +04:00
|
|
|
|
|
2023-05-10 12:27:29 +04:00
|
|
|
|
public Client Client { get; set; }
|
2023-05-09 22:54:35 +04:00
|
|
|
|
|
2023-05-10 12:27:29 +04:00
|
|
|
|
public Transport Transport { get; set; }
|
2023-05-09 22:54:35 +04:00
|
|
|
|
|
|
|
|
|
public static Trucking? Create( DBMSContext context, TruckingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Trucking()
|
|
|
|
|
{
|
|
|
|
|
Id = model.MongoId,
|
|
|
|
|
Price = model.Price,
|
|
|
|
|
DateStart = model.DateStart,
|
|
|
|
|
DateEnd = model.DateEnd,
|
|
|
|
|
Cargo = context.ConnectToMongo<Cargo>("cargo").Find(x => x.Id == model.Cargo).FirstOrDefault(),
|
|
|
|
|
Client = context.ConnectToMongo<Client>("client").Find(x => x.Id == model.Client).FirstOrDefault(),
|
|
|
|
|
Transport = context.ConnectToMongo<Transport>("transport").Find(x => x.Id == model.Transport).FirstOrDefault()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(TruckingBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Price = model.Price;
|
|
|
|
|
DateStart = model.DateStart;
|
|
|
|
|
DateEnd = model.DateEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TruckingViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
MongoId = Id,
|
|
|
|
|
Price = Price,
|
|
|
|
|
DateStart = DateStart,
|
|
|
|
|
DateEnd = DateEnd,
|
|
|
|
|
ClientName = Client == null ? string.Empty : Client.Name,
|
|
|
|
|
ClientSurname = Client == null ? string.Empty : Client.Surname,
|
|
|
|
|
ClientPatronymic = Client == null ? string.Empty : Client.Patronymic,
|
|
|
|
|
TransportName = Transport == null ? string.Empty : Transport.TransportType,
|
|
|
|
|
Cargo = Cargo == null ? string.Empty : Cargo.TypeCargo
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|