Contractor: Fixes
This commit is contained in:
95
ComputerStoreDatabaseImplement/Models/Consignment.cs
Normal file
95
ComputerStoreDatabaseImplement/Models/Consignment.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Consignment : IConsignmentModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int OrderID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Price { get; private set; }
|
||||
|
||||
private Dictionary<int, (IProductModel, int)>? _consignmentProducts = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> ConsignmentProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_consignmentProducts == null)
|
||||
{
|
||||
_consignmentProducts = Products.ToDictionary(recPC => recPC.ProductID, recPC => (recPC.Product as IProductModel, recPC.Count));
|
||||
}
|
||||
return _consignmentProducts;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("ConsignmentId")]
|
||||
public virtual List<CarComponent> Components { get; set; } = new();
|
||||
|
||||
|
||||
public virtual Product Product { get; private set; }
|
||||
private Dictionary<int, (IProductModel, int)>? Products = null;
|
||||
|
||||
|
||||
|
||||
|
||||
[ForeignKey("ConsignmentID")]
|
||||
public virtual List<ConsignmentComponent> ConsignmentComponent { get; private set; } = new();
|
||||
|
||||
public static Consignment Create(ComputerStoreDatabase context, ConsignmentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Consignment()
|
||||
{
|
||||
ID = model.ID,
|
||||
OrderID = model.OrderID,
|
||||
Price = model.Price,
|
||||
_orderProducts = model.ConsignmentProducts
|
||||
|
||||
};
|
||||
|
||||
//return new Consignment()
|
||||
//{
|
||||
// ID = model.ID,
|
||||
// OrderID = model.OrderID,
|
||||
// Price = model.Price,
|
||||
// Products = model.ConsignmentProducts.Select(x => new ConsignmentComponent
|
||||
// {
|
||||
// Component = context.Components.First(y => y.ID == x.Key),
|
||||
// Count = x.Value.Item2
|
||||
// }).ToList()
|
||||
//};
|
||||
}
|
||||
public void Update(ConsignmentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OrderID = model.OrderID;
|
||||
Price = model.Price;
|
||||
}
|
||||
public ConsignmentViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
OrderID = OrderID,
|
||||
Price = Price
|
||||
};
|
||||
}
|
||||
}
|
||||
92
ComputerStoreDatabaseImplement/Models/Order.cs
Normal file
92
ComputerStoreDatabaseImplement/Models/Order.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ComputerStoreDataModels.Enums;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
|
||||
namespace ComputerStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Price { get; private set; }
|
||||
|
||||
public int? ConsignmentID { get; private set; }
|
||||
|
||||
public int? RequestID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int SellerID { get; private set; }
|
||||
|
||||
public virtual Seller Seller { get; set; }
|
||||
public virtual Consignment Consignment { get; private set; }
|
||||
public virtual Request Request { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order
|
||||
{
|
||||
Price = model.Price,
|
||||
ConsignmentID = model.ConsignmentID,
|
||||
RequestID = model.RequestID,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
SellerID = model.SellerID,
|
||||
ID = model.ID,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
var context = new ComputerStoreDatabase();
|
||||
return new()
|
||||
{
|
||||
|
||||
ID = ID,
|
||||
ConsignmentID = ConsignmentID,
|
||||
RequestID = RequestID,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Status = Status,
|
||||
Price = Price,
|
||||
SellerID = SellerID,
|
||||
SellerUsername = context.Sellers.FirstOrDefault(x => x.ID == SellerID)?.Username ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
ComputerStoreDatabaseImplement/Models/Request.cs
Normal file
58
ComputerStoreDatabaseImplement/Models/Request.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Request : IRequestModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int OrderID { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Price { get; private set; }
|
||||
|
||||
[ForeignKey("RequestID")]
|
||||
public virtual List<RequestComponent> RequestComponents { get; private set; } = new();
|
||||
|
||||
public static Request? Create(RequestBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Request()
|
||||
{
|
||||
ID = model.ID,
|
||||
OrderID = model.OrderID,
|
||||
Price = model.Price
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(RequestBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OrderID = model.OrderID;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public RequestViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
OrderID = OrderID,
|
||||
Price = Price
|
||||
};
|
||||
}
|
||||
}
|
||||
66
ComputerStoreDatabaseImplement/Models/Seller.cs
Normal file
66
ComputerStoreDatabaseImplement/Models/Seller.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ComputerStoreDatabaseImplement.Models
|
||||
{
|
||||
public class Seller : ISellerModel
|
||||
{
|
||||
public int ID { get; private set; }
|
||||
[Required]
|
||||
public string Username { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public string? FirstName { get; private set; } = string.Empty;
|
||||
public string? LastName { get; private set; } = string.Empty;
|
||||
public string? MiddleName { get; private set; } = string.Empty;
|
||||
|
||||
[ForeignKey("OrderID")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Seller? Create(SellerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Seller()
|
||||
{
|
||||
ID = model.ID,
|
||||
Username = model.Username,
|
||||
Password = model.Password,
|
||||
FirstName = model.FirstName,
|
||||
LastName = model.LastName,
|
||||
MiddleName = model.MiddleName
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(SellerBindingModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
Username = model.Username;
|
||||
Password = model.Password;
|
||||
FirstName = model.FirstName;
|
||||
LastName = model.LastName;
|
||||
MiddleName = model.MiddleName;
|
||||
}
|
||||
|
||||
public SellerViewModel GetViewModel => new()
|
||||
{
|
||||
ID = ID,
|
||||
Username = Username,
|
||||
Password = Password,
|
||||
FirstName = FirstName,
|
||||
LastName = LastName,
|
||||
MiddleName = MiddleName
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user