2023-05-09 13:13:47 +04:00
|
|
|
|
using ConstructionCompanyContracts.BindingModels;
|
2023-05-09 22:06:53 +04:00
|
|
|
|
using ConstructionCompanyContracts.ViewModels;
|
2023-05-09 13:13:47 +04:00
|
|
|
|
using ConstructionCompanyDataModels.Enums;
|
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ConstructionCompanyMongoDBImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
public string Description { get; private set; } = string.Empty;
|
|
|
|
|
public string Adress { get; private set; } = string.Empty;
|
|
|
|
|
public string CustomerNumber { get; private set; } = string.Empty;
|
|
|
|
|
public double Price { get; private set; }
|
|
|
|
|
public OrderStatus Status { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DateTime DateBegin { get; private set; }
|
|
|
|
|
|
|
|
|
|
public DateTime? DateEnd { get; private set; }
|
|
|
|
|
|
|
|
|
|
public static Order? Create(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Description = model.Description,
|
|
|
|
|
Adress = model.Adress,
|
|
|
|
|
CustomerNumber = model.CustomerNumber,
|
|
|
|
|
Price = model.Price,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateBegin = model.DateBegin,
|
|
|
|
|
DateEnd = model.DateEnd
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BsonDocument? CreateBSON(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
BsonArray bsonArray = new BsonArray();
|
|
|
|
|
return new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"_id", model.Id},
|
|
|
|
|
{"description", $"{model.Description}"},
|
|
|
|
|
{"adress", $"{model.Adress}"},
|
|
|
|
|
{"price", $"{model.Price}"},
|
|
|
|
|
{"status", $"{model.Status}"},
|
2023-05-09 22:06:53 +04:00
|
|
|
|
{"customerNumber", $"{model.CustomerNumber}"},
|
|
|
|
|
{"dateBegin", new BsonDateTime(model.DateBegin)},
|
|
|
|
|
{"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""},
|
2023-05-09 13:13:47 +04:00
|
|
|
|
{"employeesId", new BsonArray() },
|
|
|
|
|
{"materials", new BsonArray()}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BsonDocument? UpdateBSON(OrderBindingModel? model, BsonArray employeesId, BsonArray materials)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"_id", model.Id},
|
|
|
|
|
{"description", $"{model.Description}"},
|
|
|
|
|
{"adress", $"{model.Adress}"},
|
|
|
|
|
{"price", $"{model.Price}"},
|
|
|
|
|
{"status", $"{model.Status}"},
|
2023-05-09 22:06:53 +04:00
|
|
|
|
{"customerNumber", $"{model.CustomerNumber}"},
|
|
|
|
|
{"dateBegin", new BsonDateTime(model.DateBegin)},
|
|
|
|
|
{"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""},
|
2023-05-09 13:13:47 +04:00
|
|
|
|
{"employeesId", employeesId },
|
|
|
|
|
{"materials", materials}
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-05-09 22:06:53 +04:00
|
|
|
|
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Description = Description,
|
|
|
|
|
Adress = Adress,
|
|
|
|
|
CustomerNumber = CustomerNumber,
|
|
|
|
|
Price = Price,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateBegin = DateBegin,
|
|
|
|
|
DateEnd = DateEnd
|
|
|
|
|
};
|
2023-05-09 13:13:47 +04:00
|
|
|
|
}
|
|
|
|
|
}
|