89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
|
using ConstructionCompanyContracts.BindingModels;
|
|||
|
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}"},
|
|||
|
{"customerNumber", $"{model.CustomerNumber}"},
|
|||
|
{"price", $"{model.Price}"},
|
|||
|
{"status", $"{model.Status}"},
|
|||
|
{"dateBegin", $"{model.DateBegin}"},
|
|||
|
{"dateEnd", $"{model.DateEnd}"},
|
|||
|
{"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}"},
|
|||
|
{"customerNumber", $"{model.CustomerNumber}"},
|
|||
|
{"price", $"{model.Price}"},
|
|||
|
{"status", $"{model.Status}"},
|
|||
|
{"dateBegin", $"{model.DateBegin}"},
|
|||
|
{"dateEnd", $"{model.DateEnd}"},
|
|||
|
{"employeesId", employeesId },
|
|||
|
{"materials", materials}
|
|||
|
};
|
|||
|
}
|
|||
|
}
|
|||
|
}
|