2023-02-19 22:48:53 +04:00
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using ConfectioneryDataModels.Enums;
|
|
|
|
|
using ConfectioneryDataModels.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
2023-03-18 20:16:32 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2023-02-19 22:48:53 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace ConfectioneryDatabaseImplement.Models
|
|
|
|
|
{
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataContract]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public int PastryId { get; private set; }
|
|
|
|
|
|
2023-03-04 15:03:40 +04:00
|
|
|
|
[Required]
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-03-04 15:03:40 +04:00
|
|
|
|
public int ClientId { get; private set; }
|
|
|
|
|
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-03-06 14:58:38 +04:00
|
|
|
|
public int? ImplementerId { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public int Count { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public double Sum { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public OrderStatus Status { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public DateTime DateCreate { get; private set; }
|
|
|
|
|
|
2023-03-18 20:16:32 +04:00
|
|
|
|
[DataMember]
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Pastry Pastry { get; private set; }
|
|
|
|
|
|
2023-03-04 14:39:23 +04:00
|
|
|
|
public Client Client { get; private set; }
|
|
|
|
|
|
2023-03-06 14:58:38 +04:00
|
|
|
|
public Implementer? Implementer { get; private set; }
|
|
|
|
|
|
2023-02-19 22:48:53 +04:00
|
|
|
|
public static Order? Create(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
PastryId = model.PastryId,
|
2023-03-04 15:03:40 +04:00
|
|
|
|
ClientId = model.ClientId,
|
2023-02-19 22:48:53 +04:00
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
2023-03-06 14:58:38 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
2023-02-19 22:48:53 +04:00
|
|
|
|
DateImplement = model.DateImplement,
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PastryId = model.PastryId;
|
|
|
|
|
Count = model.Count;
|
|
|
|
|
Sum = model.Sum;
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateCreate = model.DateCreate;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2023-03-06 17:14:11 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
2023-02-19 22:48:53 +04:00
|
|
|
|
Id = model.Id;
|
|
|
|
|
}
|
2023-02-28 22:14:49 +04:00
|
|
|
|
public OrderViewModel GetViewModel
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var context = new ConfectioneryDatabase();
|
|
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
PastryName = context.Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty,
|
2023-03-13 23:01:00 +04:00
|
|
|
|
ClientId = ClientId,
|
2023-03-13 17:32:16 +04:00
|
|
|
|
ClientFIO = Client?.ClientFIO ?? string.Empty,
|
2023-03-08 16:50:44 +04:00
|
|
|
|
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
|
2023-02-28 22:14:49 +04:00
|
|
|
|
PastryId = PastryId,
|
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
2023-03-06 14:58:38 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
2023-02-28 22:14:49 +04:00
|
|
|
|
Id = Id,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-19 22:48:53 +04:00
|
|
|
|
}
|
|
|
|
|
}
|