2023-04-09 17:23:33 +04:00
|
|
|
|
using ConstructionCompanyContracts.BindingModels;
|
|
|
|
|
using ConstructionCompanyContracts.ViewModels;
|
|
|
|
|
using ConstructionCompanyDataModels.Enums;
|
|
|
|
|
using ConstructionCompanyDataModels.Models;
|
2023-05-11 13:03:42 +04:00
|
|
|
|
using MongoDB.Bson;
|
2023-04-09 17:23:33 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ConstructionCompanyPsqlImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
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 void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
if (model.DateEnd.HasValue) DateEnd = model.DateEnd;
|
|
|
|
|
}
|
|
|
|
|
public static string CreateCommand(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
return $"INSERT INTO \"order\"(description, adress, price, status, " +
|
|
|
|
|
$"customer_number, date_begin, date_end) VALUES(\'{model.Description}\', \'{model.Adress}\', {model.Price}, " +
|
|
|
|
|
$"\'{model.Status}\', \'{model.CustomerNumber}\', \'{model.DateBegin}\', " +
|
|
|
|
|
$"{(model.DateEnd.HasValue ? $"\'{model.DateEnd}\'" : "null")});";
|
|
|
|
|
}
|
|
|
|
|
public static string UpdateCommand(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2023-04-10 13:02:23 +04:00
|
|
|
|
return $"UPDATE \"order\" SET status = \'{model.Status}\', date_end = {(model.DateEnd.HasValue ? $"\'{model.DateEnd}\'" : "null")} " +
|
2023-04-09 17:23:33 +04:00
|
|
|
|
$"WHERE id = {model.Id}";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public static string DeleteCommand(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
return $"DELETE FROM \"order\" WHERE id = {model.Id}";
|
|
|
|
|
}
|
2023-05-11 13:03:42 +04:00
|
|
|
|
|
|
|
|
|
public BsonDocument CreateBSON =>
|
|
|
|
|
new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"_id", Id},
|
|
|
|
|
{"description", $"{Description}"},
|
|
|
|
|
{"adress", $"{Adress}"},
|
|
|
|
|
{"price", Price},
|
|
|
|
|
{"status", $"{Status}"},
|
|
|
|
|
{"customerNumber", $"{CustomerNumber}"},
|
|
|
|
|
{"dateBegin", new BsonDateTime(DateBegin)},
|
|
|
|
|
{"dateEnd", DateEnd.HasValue ? new BsonDateTime(DateEnd.Value) : ""},
|
|
|
|
|
{"employeesId", new BsonArray() },
|
|
|
|
|
{"materials", new BsonArray()}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public BsonDocument UpdateBSON(BsonArray employeesId, BsonArray materials) =>
|
|
|
|
|
new BsonDocument
|
|
|
|
|
{
|
|
|
|
|
{"_id", Id - 1},
|
|
|
|
|
{"description", $"{Description}"},
|
|
|
|
|
{"adress", $"{Adress}"},
|
|
|
|
|
{"price", Price},
|
|
|
|
|
{"status", $"{Status}"},
|
|
|
|
|
{"customerNumber", $"{CustomerNumber}"},
|
|
|
|
|
{"dateBegin", new BsonDateTime(DateBegin)},
|
|
|
|
|
{"dateEnd", DateEnd.HasValue ? new BsonDateTime(DateEnd.Value) : ""},
|
|
|
|
|
{"employeesId", employeesId },
|
|
|
|
|
{"materials", materials}
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-09 17:23:33 +04:00
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Description = Description,
|
|
|
|
|
Adress = Adress,
|
|
|
|
|
CustomerNumber = CustomerNumber,
|
|
|
|
|
Price = Price,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateBegin = DateBegin,
|
|
|
|
|
DateEnd = DateEnd
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|