ОНООООООО РАБОТАЕЕЕЕЕЕЕЕЕЕТ!!!!!!

This commit is contained in:
Кашин Максим 2023-03-28 00:27:02 +04:00
parent 368338db82
commit c315095758
16 changed files with 158 additions and 184 deletions

View File

@ -151,6 +151,7 @@
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormCreateOrder"; this.Name = "FormCreateOrder";
this.Text = "Заказ"; this.Text = "Заказ";
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@ -63,11 +63,6 @@ namespace PrecastConcretePlantView
} }
} }
private void FormCreateOrder_Load(object sender, EventArgs e)
{
LoadData();
}
private void CalcSum() private void CalcSum()
{ {
if (ReinforcedComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text)) if (ReinforcedComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text))
@ -125,7 +120,6 @@ namespace PrecastConcretePlantView
{ {
ClientId = Convert.ToInt32(ClientСomboBox.SelectedValue), ClientId = Convert.ToInt32(ClientСomboBox.SelectedValue),
ReinforcedId = Convert.ToInt32(ReinforcedComboBox.SelectedValue), ReinforcedId = Convert.ToInt32(ReinforcedComboBox.SelectedValue),
ReinforcedName = ReinforcedComboBox.Text,
Count = Convert.ToInt32(CountTextBox.Text), Count = Convert.ToInt32(CountTextBox.Text),
Sum = Convert.ToDouble(SumTextBox.Text) Sum = Convert.ToDouble(SumTextBox.Text)
}); });
@ -156,5 +150,10 @@ namespace PrecastConcretePlantView
{ {
CalcSum(); CalcSum();
} }
private void FormCreateOrder_Load(object sender, EventArgs e)
{
LoadData();
}
} }
} }

View File

@ -47,6 +47,7 @@ namespace PrecastConcretePlantView
{ {
DataGridView.DataSource = list; DataGridView.DataSource = list;
DataGridView.Columns["ReinforcedId"].Visible = false; DataGridView.Columns["ReinforcedId"].Visible = false;
DataGridView.Columns["ClientId"].Visible = false;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
@ -101,12 +102,7 @@ namespace PrecastConcretePlantView
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = id, Id = id,
ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value),
ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
@ -136,12 +132,6 @@ namespace PrecastConcretePlantView
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = id, Id = id,
ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value),
ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
@ -171,12 +161,7 @@ namespace PrecastConcretePlantView
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = id, Id = id,
ReinforcedId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ReinforcedId"].Value),
ReinforcedName = DataGridView.SelectedRows[0].Cells["ReinforcedName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)

View File

@ -27,53 +27,67 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) if (model.Status != OrderStatus.Неизвестен)
{ {
_logger.LogWarning("Insert operation failed. Order status incorrect."); _logger.LogWarning("Insert operation failed. Order status incorrect.");
return false; return false;
} }
model.Status = OrderStatus.Принят; model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null) if (_orderStorage.Insert(model) == null)
{ {
model.Status = OrderStatus.Неизвестен; model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
return true; return true;
} }
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) public bool StatusUpdate(OrderBindingModel rawModel, OrderStatus newStatus)
{ {
CheckModel(model); var viewModel = _orderStorage.GetElement(new OrderSearchModel
{
Id = rawModel.Id
});
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
}
OrderBindingModel model = new OrderBindingModel
{
Id = viewModel.Id,
ReinforcedId = viewModel.ReinforcedId,
Status = viewModel.Status,
DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum
};
CheckModel(model, false);
if (model.Status + 1 != newStatus) if (model.Status + 1 != newStatus)
{ {
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false; return false;
} }
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (model.Status == OrderStatus.Выдан)
model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
model.Status--; model.Status--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }
return true; return true;
} }
public bool TakeOrderInWork(OrderBindingModel model) public bool TakeOrderInWork(OrderBindingModel model)
{ {
return StatusUpdate(model, OrderStatus.Выполняется); return StatusUpdate(model, OrderStatus.Выполняется);
} }
public bool DeliveryOrder(OrderBindingModel model) public bool DeliveryOrder(OrderBindingModel model)
{ {
return StatusUpdate(model, OrderStatus.Готов); return StatusUpdate(model, OrderStatus.Готов);
@ -83,18 +97,16 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{ {
return StatusUpdate(model, OrderStatus.Выдан); return StatusUpdate(model, OrderStatus.Выдан);
} }
public List<OrderViewModel>? ReadList(OrderSearchModel? model) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{ {
_logger.LogInformation("Order. OrderId:{Id}", model?.Id); _logger.LogInformation("Order. OrderID:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
return null; return null;
} }
_logger.LogInformation("ReadList. Count:{Count}", list.Count); _logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list; return list;
} }
@ -104,28 +116,23 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
if (!withParams) if (!withParams)
{ {
return; return;
} }
if (model.ReinforcedId < 0) if (model.ReinforcedId < 0)
{ {
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ReinforcedId)); throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.ReinforcedId));
} }
if (model.Count <= 0) if (model.Count <= 0)
{ {
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); throw new ArgumentNullException("Количество документов в заказе должно быть больше 0", nameof(model.Count));
} }
if (model.Sum <= 0) if (model.Sum <= 0)
{ {
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
} }
_logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. ReinforcedId: { ReinforcedId}", model.Id, model.Sum, model.ReinforcedId);
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. ReinforcedId: { ReinforcedId}", model.Id, model.Sum, model.ReinforcedId);
} }
} }
} }

View File

@ -9,12 +9,10 @@ namespace PrecastConcretePlantClientApp.Controllers
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger)
{ {
_logger = logger; _logger = logger;
} }
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
@ -23,7 +21,6 @@ namespace PrecastConcretePlantClientApp.Controllers
} }
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}")); return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
} }
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
@ -33,7 +30,6 @@ namespace PrecastConcretePlantClientApp.Controllers
} }
return View(APIClient.Client); return View(APIClient.Client);
} }
[HttpPost] [HttpPost]
public void Privacy(string login, string password, string fio) public void Privacy(string login, string password, string fio)
{ {
@ -45,37 +41,37 @@ namespace PrecastConcretePlantClientApp.Controllers
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/client/updatedata", new ClientBindingModel APIClient.PostRequest("api/client/updatedata", new
ClientBindingModel
{ {
Id = APIClient.Client.Id, Id = APIClient.Client.Id,
ClientFIO = fio, ClientFIO = fio,
Email = login, Email = login,
Password = password Password = password
}); });
APIClient.Client.ClientFIO = fio; APIClient.Client.ClientFIO = fio;
APIClient.Client.Email = login; APIClient.Client.Email = login;
APIClient.Client.Password = password; APIClient.Client.Password = password;
Response.Redirect("Index"); Response.Redirect("Index");
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
});
} }
[HttpGet] [HttpGet]
public IActionResult Enter() public IActionResult Enter()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Enter(string login, string password) public void Enter(string login, string password)
{ {
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{ {
throw new Exception("Введите логин и пароль"); throw new Exception("Введите логин и пароль");
} }
APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}"); APIClient.Client = APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
@ -85,18 +81,16 @@ namespace PrecastConcretePlantClientApp.Controllers
} }
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpGet] [HttpGet]
public IActionResult Register() public IActionResult Register()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Register(string login, string password, string fio) public void Register(string login, string password, string fio)
{ {
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/client/register", new ClientBindingModel APIClient.PostRequest("api/client/register", new ClientBindingModel
@ -108,14 +102,12 @@ namespace PrecastConcretePlantClientApp.Controllers
Response.Redirect("Enter"); Response.Redirect("Enter");
return; return;
} }
[HttpGet] [HttpGet]
public IActionResult Create() public IActionResult Create()
{ {
ViewBag.Reinforcedies = APIClient.GetRequest<List<ReinforcedViewModel>>("api/main/getreinforcedlist"); ViewBag.Reinforcedies = APIClient.GetRequest<List<ReinforcedViewModel>>("api/main/getreinforcedlist");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Create(int reinforced, int count) public void Create(int reinforced, int count)
{ {
@ -136,12 +128,11 @@ namespace PrecastConcretePlantClientApp.Controllers
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public double Calc(int count, int reinforced) public double Calc(int count, int reinforced)
{ {
var prod = APIClient.GetRequest<ReinforcedViewModel>($"api/main/getreinforced?reinforcedId={reinforced}"); var doc = APIClient.GetRequest<ReinforcedViewModel>($"api/main/getreinforced?reinforcedId={reinforced}");
return count * (prod?.Price ?? 1); return count * (doc?.Price ?? 1);
} }
} }
} }

View File

@ -13,7 +13,6 @@ namespace PrecastConcretePlantContracts.BindingModels
public int Id { get; set; } public int Id { get; set; }
public int ReinforcedId { get; set; } public int ReinforcedId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public string ReinforcedName { get; set; } = string.Empty;
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -11,22 +11,29 @@ namespace PrecastConcretePlantContracts.ViewModels
{ {
public class OrderViewModel : IOrderModel public class OrderViewModel : IOrderModel
{ {
public int ClientId { get; set; }
public int ReinforcedId { get; set; }
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Фамилия клиента")] public int ReinforcedId { get; set; }
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Изделие")] [DisplayName("Документ")]
public string ReinforcedName { get; set; } = string.Empty; public string ReinforcedName { get; set; } = string.Empty;
public int ClientId { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма")]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус")] [DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")] [DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")] [DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }

View File

@ -10,7 +10,7 @@ namespace PrecastConcretePlantDataModels.Enums
public interface IOrderModel : IId public interface IOrderModel : IId
{ {
int ReinforcedId { get; } int ReinforcedId { get; }
string ReinforcedName { get; } int ClientId { get; }
int Count { get; } int Count { get; }
double Sum { get; } double Sum { get; }
OrderStatus Status { get; } OrderStatus Status { get; }

View File

@ -1,4 +1,5 @@
using PrecastConcretePlantContracts.BindingModels; using Microsoft.EntityFrameworkCore;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels; using PrecastConcretePlantContracts.ViewModels;
@ -13,86 +14,80 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
{ {
public class OrderStorage : IOrderStorage public class OrderStorage : IOrderStorage
{ {
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDataBase();
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue)
{ {
return null; return null;
} }
using var context = new PrecastConcretePlantDataBase(); using var context = new PrecastConcretePlantDataBase();
return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
{ {
return new(); return new();
} }
using var context = new PrecastConcretePlantDataBase(); using var context = new PrecastConcretePlantDataBase();
if (model.ClientId.HasValue)
return context.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); {
return context.Orders
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders
.Include(x => x.Reinforced)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new PrecastConcretePlantDataBase(); using var context = new PrecastConcretePlantDataBase();
return context.Orders.Include(x => x.Reinforced).Select(x => x.GetViewModel).ToList();
return context.Orders.Select(x => x.GetViewModel).ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
var newOrder = Order.Create(model); var newOrder = Order.Create(model);
if (newOrder == null) if (newOrder == null)
{ {
return null; return null;
} }
using var context = new PrecastConcretePlantDataBase(); using var context = new PrecastConcretePlantDataBase();
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
return newOrder.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
using var context = new PrecastConcretePlantDataBase(); using var context = new PrecastConcretePlantDataBase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null) if (order == null)
{ {
return null; return null;
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
return order.GetViewModel; }
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDataBase();
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
} }
} }
} }

View File

@ -12,7 +12,7 @@ using PrecastConcretePlantDatabaseImplement;
namespace PrecastConcretePlantDatabaseImplement.Migrations namespace PrecastConcretePlantDatabaseImplement.Migrations
{ {
[DbContext(typeof(PrecastConcretePlantDataBase))] [DbContext(typeof(PrecastConcretePlantDataBase))]
[Migration("20230326191118_Restart")] [Migration("20230327202214_Restart")]
partial class Restart partial class Restart
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -78,7 +78,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId") b.Property<int>("ClientId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Count") b.Property<int>("Count")
@ -93,10 +93,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Property<int>("ReinforcedId") b.Property<int>("ReinforcedId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
@ -160,9 +156,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", null) b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("ClientId"); .HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders") .WithMany("Orders")
@ -170,6 +168,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Reinforced"); b.Navigation("Reinforced");
}); });

View File

@ -61,13 +61,12 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
ReinforcedId = table.Column<int>(type: "int", nullable: false), ReinforcedId = table.Column<int>(type: "int", nullable: false),
ReinforcedName = table.Column<string>(type: "nvarchar(max)", nullable: false), ClientId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false), Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false), Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false), DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true), DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
ClientId = table.Column<int>(type: "int", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
@ -76,7 +75,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
name: "FK_Orders_Clients_ClientId", name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId, column: x => x.ClientId,
principalTable: "Clients", principalTable: "Clients",
principalColumn: "Id"); principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Orders_Reinforcedies_ReinforcedId", name: "FK_Orders_Reinforcedies_ReinforcedId",
column: x => x.ReinforcedId, column: x => x.ReinforcedId,

View File

@ -75,7 +75,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId") b.Property<int>("ClientId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("Count") b.Property<int>("Count")
@ -90,10 +90,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Property<int>("ReinforcedId") b.Property<int>("ReinforcedId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
@ -157,9 +153,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", null) b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("ClientId"); .HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders") .WithMany("Orders")
@ -167,6 +165,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Reinforced"); b.Navigation("Reinforced");
}); });

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Reflection.Metadata;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -13,26 +14,22 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int ReinforcedId { get; private set; } public int ReinforcedId { get; private set; }
[Required]
public string ReinforcedName { get; private set; } = string.Empty; public int ClientId { get; private set; }
[Required] [Required]
public int Count { get; private set; } public int Count { get; private set; }
[Required] [Required]
public double Sum { get; private set; } public double Sum { get; private set; }
[Required] [Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required] [Required]
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public virtual Reinforced Reinforced { get; set; } public virtual Reinforced Reinforced { get; set; }
public virtual Client Client { get; set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
@ -40,17 +37,16 @@ namespace PrecastConcretePlantDatabaseImplement.Models
{ {
return null; return null;
} }
return new Order
return new Order()
{ {
Id = model.Id,
ReinforcedId = model.ReinforcedId, ReinforcedId = model.ReinforcedId,
ReinforcedName = model.ReinforcedName, ClientId = model.ClientId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement DateImplement = model.DateImplement,
Id = model.Id,
}; };
} }
@ -60,26 +56,30 @@ namespace PrecastConcretePlantDatabaseImplement.Models
{ {
return; return;
} }
ReinforcedId = model.ReinforcedId;
ReinforcedName = model.ReinforcedName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status; Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel
{ {
Id = Id, get
ReinforcedId = ReinforcedId, {
ReinforcedName = ReinforcedName, var context = new PrecastConcretePlantDataBase();
Count = Count, return new()
Sum = Sum, {
Status = Status,
DateCreate = DateCreate, ReinforcedId = ReinforcedId,
DateImplement = DateImplement ClientId = ClientId,
}; Count = Count,
Sum = Sum,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
Status = Status,
ReinforcedName = context.Reinforcedies.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty
};
}
}
} }
} }

View File

@ -15,8 +15,6 @@ namespace PrecastConcretePlantFileImplement.Models
public int ReinforcedId { get; private set; } public int ReinforcedId { get; private set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public string ReinforcedName { get; private set; } = string.Empty;
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
@ -39,7 +37,6 @@ namespace PrecastConcretePlantFileImplement.Models
{ {
Id = model.Id, Id = model.Id,
ReinforcedId = model.ReinforcedId, ReinforcedId = model.ReinforcedId,
ReinforcedName = model.ReinforcedName,
ClientId = model.ClientId, ClientId = model.ClientId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
@ -61,7 +58,6 @@ namespace PrecastConcretePlantFileImplement.Models
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
ReinforcedName = element.Element("ReinforcedName")!.Value,
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
@ -81,7 +77,6 @@ namespace PrecastConcretePlantFileImplement.Models
return; return;
} }
ReinforcedId = model.ReinforcedId; ReinforcedId = model.ReinforcedId;
ReinforcedName = model.ReinforcedName;
Count = model.Count; Count = model.Count;
Sum = model.Sum; Sum = model.Sum;
Status = model.Status; Status = model.Status;
@ -105,7 +100,6 @@ namespace PrecastConcretePlantFileImplement.Models
public XElement GetXElement => new("Order", public XElement GetXElement => new("Order",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("ReinforcedName", ReinforcedName),
new XElement("ReinforcedId", ReinforcedId.ToString()), new XElement("ReinforcedId", ReinforcedId.ToString()),
new XElement("ClientId", ClientId), new XElement("ClientId", ClientId),
new XElement("Count", Count.ToString()), new XElement("Count", Count.ToString()),

View File

@ -15,7 +15,6 @@ namespace PrecastConcretePlantListImplement.Models
{ {
public int ReinforcedId { get; private set; } public int ReinforcedId { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public string ReinforcedName { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
@ -40,7 +39,6 @@ namespace PrecastConcretePlantListImplement.Models
Id = model.Id, Id = model.Id,
ReinforcedId = model.ReinforcedId, ReinforcedId = model.ReinforcedId,
ClientId = model.ClientId, ClientId = model.ClientId,
ReinforcedName = model.ReinforcedName,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -56,7 +54,6 @@ namespace PrecastConcretePlantListImplement.Models
return; return;
} }
ReinforcedId = model.ReinforcedId; ReinforcedId = model.ReinforcedId;
ReinforcedName = model.ReinforcedName;
Count = model.Count; Count = model.Count;
Sum = model.Sum; Sum = model.Sum;
Status = model.Status; Status = model.Status;
@ -69,7 +66,6 @@ namespace PrecastConcretePlantListImplement.Models
Id = Id, Id = Id,
ReinforcedId = ReinforcedId, ReinforcedId = ReinforcedId,
ClientId = ClientId, ClientId = ClientId,
ReinforcedName = ReinforcedName,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,

View File

@ -1,23 +1,14 @@
{ {
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:43427",
"sslPort": 44365
}
},
"profiles": { "profiles": {
"PrecastConcretePlantRestApi": { "PrecastConcretePlantRestApi": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger", "launchUrl": "swagger",
"applicationUrl": "https://localhost:7197;http://localhost:5197",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} },
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7197;http://localhost:5197"
}, },
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
@ -27,5 +18,14 @@
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
} }
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64248/",
"sslPort": 44372
}
} }
} }