PIbd-22. Safiulova K.N. LabWork_03_hard #15

Closed
safiulova.k wants to merge 11 commits from LabWork_03_hard into LabWork_02_hard
7 changed files with 39 additions and 21 deletions
Showing only changes of commit 72202d2d74 - Show all commits

View File

@ -15,7 +15,7 @@ namespace AircraftPlantDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-6QDRI0N\SQLEXPRESS;Initial Catalog=AircraftPlantDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-6QDRI0N\SQLEXPRESS;Initial Catalog=AircraftPlantDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -13,7 +13,7 @@ namespace AircraftPlantDatabaseImplement.Implements
{
using var context = new AircraftPlantDatabase();
return context.Orders
.Include(x => x.Plant)
.Include(x => x.Plane)
.Select(x => x.GetViewModel)
.ToList();
}
@ -26,7 +26,7 @@ namespace AircraftPlantDatabaseImplement.Implements
}
using var context = new AircraftPlantDatabase();
return context.Orders
.Include(x => x.Plant)
.Include(x => x.Plane)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
@ -40,7 +40,7 @@ namespace AircraftPlantDatabaseImplement.Implements
}
using var context = new AircraftPlantDatabase();
return context.Orders
.Include(x => x.Plant)
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
@ -56,7 +56,7 @@ namespace AircraftPlantDatabaseImplement.Implements
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders
.Include(x => x.Plant)
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
@ -72,7 +72,7 @@ namespace AircraftPlantDatabaseImplement.Implements
order.Update(model);
context.SaveChanges();
return context.Orders
.Include(x => x.Plant)
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
@ -84,7 +84,7 @@ namespace AircraftPlantDatabaseImplement.Implements
if (element != null)
{
var deletedElement = context.Orders
.Include(x => x.Plant)
.Include(x => x.Plane)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element);

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace AircraftPlantDatabaseImplement.Migrations
{
[DbContext(typeof(AircraftPlantDatabase))]
[Migration("20240326134051_InitialCreate")]
[Migration("20240326170504_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -126,11 +126,13 @@ namespace AircraftPlantDatabaseImplement.Migrations
modelBuilder.Entity("AircraftPlantDatabaseImplement.Models.Order", b =>
{
b.HasOne("AircraftPlantDatabaseImplement.Models.Plane", null)
b.HasOne("AircraftPlantDatabaseImplement.Models.Plane", "Plane")
.WithMany("Orders")
.HasForeignKey("PlaneId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Plane");
});
modelBuilder.Entity("AircraftPlantDatabaseImplement.Models.PlaneComponent", b =>

View File

@ -1,6 +1,8 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@ -9,12 +11,16 @@ namespace AircraftPlantDatabaseImplement.Models
public class Component : IComponentModel
{
public int Id { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("ComponentId")]
public virtual List<PlaneComponent> PlaneComponents { get; set; } = new();
public static Component? Create(ComponentBindingModel model)
{
if (model == null)
@ -28,6 +34,7 @@ namespace AircraftPlantDatabaseImplement.Models
Cost = model.Cost
};
}
public static Component Create(ComponentViewModel model)
{
return new Component
@ -37,6 +44,7 @@ namespace AircraftPlantDatabaseImplement.Models
Cost = model.Cost
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
@ -46,6 +54,7 @@ namespace AircraftPlantDatabaseImplement.Models
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
@ -53,4 +62,4 @@ namespace AircraftPlantDatabaseImplement.Models
Cost = Cost
};
}
}
}

View File

@ -2,36 +2,40 @@
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Enums;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; set; }
[Required]
public int PlaneId { get; set; }
[Required]
public int Count { get; set; }
[Required]
public double Sum { get; set; }
[Required]
public OrderStatus Status { get; set; }
[Required]
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public virtual Plane Plane { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order
return new Order()
{
Id = model.Id,
PlaneId = model.PlaneId,
@ -42,16 +46,17 @@ namespace AircraftPlantDatabaseImplement.Models
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
@ -60,7 +65,8 @@ namespace AircraftPlantDatabaseImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
DateImplement = DateImplement,
PlaneName = Plane.PlaneName
};
}
}
}

View File

@ -119,7 +119,7 @@ namespace AircraftPlantView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonOrderReady_Click(object sender, EventArgs e)
private void buttonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
@ -127,7 +127,7 @@ namespace AircraftPlantView
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
var operationResult = _logic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -141,6 +141,7 @@ namespace AircraftPlantView
}
}
}
/// <summary>
/// Кнопка "Заказ выдан"
/// </summary>