102 lines
3.4 KiB
C#
102 lines
3.4 KiB
C#
using ConstructionCompanyContracts.BindingModels;
|
|
using ConstructionCompanyContracts.ViewModels;
|
|
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}"},
|
|
{"customerNumber", $"{model.CustomerNumber}"},
|
|
{"dateBegin", new BsonDateTime(model.DateBegin)},
|
|
{"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""},
|
|
{"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}"},
|
|
{"customerNumber", $"{model.CustomerNumber}"},
|
|
{"dateBegin", new BsonDateTime(model.DateBegin)},
|
|
{"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""},
|
|
{"employeesId", employeesId },
|
|
{"materials", materials}
|
|
};
|
|
}
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Description = Description,
|
|
Adress = Adress,
|
|
CustomerNumber = CustomerNumber,
|
|
Price = Price,
|
|
Status = Status,
|
|
DateBegin = DateBegin,
|
|
DateEnd = DateEnd
|
|
};
|
|
}
|
|
}
|