ISEbd-21 Melnikov I.O. Lab Work 05 Base #11

Closed
Igor-Melnikov wants to merge 15 commits from lab5 into lab4
16 changed files with 327 additions and 26 deletions
Showing only changes of commit 095edd6a24 - Show all commits

View File

@ -12,5 +12,6 @@ namespace BlacksmithWorkshopContracts.BindingModels
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
public int ClientId { get; set; }
}
}

View File

@ -5,5 +5,6 @@
public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ClientId { get; set; }
}
}

View File

@ -21,5 +21,7 @@ namespace BlacksmithWorkshopContracts.ViewModels
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
[DisplayName("Клиент")]
public int ClientId { get; set; }
}
}

View File

@ -32,7 +32,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
{
return null;
}
return context.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel;
return context.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)
{

View File

@ -24,7 +24,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return new();
}
@ -44,6 +44,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ClientId.HasValue)
{
orderList = context.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
foreach (var order in orderList)
{
string manufactureName = context.Manufactures

View File

@ -0,0 +1,210 @@
// <auto-generated />
using System;
using BlacksmithWorkshopDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BlacksmithWorkshopDatebaseImplement.Migrations
{
[DbContext(typeof(BlacksmithWorkshopDatabase))]
[Migration("20230327145305_Lab5Migration")]
partial class Lab5Migration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ManufactureName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Manufactures");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ManufactureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ManufactureId");
b.ToTable("ManufactureComponents");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("ManufactureId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ManufactureId");
b.ToTable("Orders");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
{
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component")
.WithMany("ManufactureComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture")
.WithMany("Components")
.HasForeignKey("ManufactureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Manufacture");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
{
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", null)
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
.WithMany("Orders")
.HasForeignKey("ManufactureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
{
b.Navigation("ManufactureComponents");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BlacksmithWorkshopDatebaseImplement.Migrations
{
/// <inheritdoc />
public partial class Lab5Migration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Orders",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ClientId",
table: "Orders",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id");
}
}
}

View File

@ -121,7 +121,7 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("ClientId")
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
@ -174,7 +174,9 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
{
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", null)
.WithMany("Orders")
.HasForeignKey("ClientId");
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
.WithMany("Orders")

View File

@ -20,6 +20,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
[Required]
public int ClientId { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
@ -34,7 +36,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
DateImplement = model.DateImplement,
ClientId = model.ClientId
};
}
public static Order Create(OrderViewModel model)
@ -47,7 +50,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
DateImplement = model.DateImplement,
ClientId = model.ClientId
};
}
public void Update(OrderBindingModel? model)
@ -70,7 +74,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
DateImplement = DateImplement,
ClientId = ClientId
};
}
}

View File

@ -36,7 +36,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
return null;
}
return source.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel;
return source.Clients.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO)))?.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)
{

View File

@ -27,7 +27,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return new();
}
@ -45,7 +45,14 @@ namespace BlacksmithWorkshopFileImplement.Implements
.Select(x => AddManufactureName(x.GetViewModel))
.ToList();
}
return new();//если нет ни того, ни другого, возвращаем пустой список
else if (model.ClientId.HasValue)//далее ищем по Id клиента
{
return source.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => AddManufactureName(x.GetViewModel))
.ToList();
}
return new();//если нет ни того, ни другого, ни третьего, возвращаем пустой список
}
public OrderViewModel? GetElement(OrderSearchModel model)
{

View File

@ -15,6 +15,7 @@ namespace BlacksmithWorkshopFileImplement.Models
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public int ClientId { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@ -29,7 +30,8 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
DateImplement = model.DateImplement,
ClientId = model.ClientId
};
}
public static Order? Create(XElement element)
@ -51,7 +53,8 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = dateImplement
DateImplement = dateImplement,
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
};
}
public void Update(OrderBindingModel? model)
@ -74,7 +77,8 @@ namespace BlacksmithWorkshopFileImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
DateImplement = DateImplement,
ClientId = ClientId
};
public XElement GetXElement => new
(
@ -85,7 +89,8 @@ namespace BlacksmithWorkshopFileImplement.Models
new XElement("Sum", Sum),
new XElement("Status", (int)Status),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement)
new XElement("DateImplement", DateImplement),
new XElement("ClientId", ClientId)
);
}
}

View File

@ -53,11 +53,7 @@ namespace BlacksmithWorkshopListImplement.Implements
{
return client.GetViewModel;
}
if (model.Email != null && client.Email.Contains(model.Email))//затем по логину
{
return client.GetViewModel;
}
if (model.ClientFIO != null && client.ClientFIO.Contains(model.ClientFIO))//затем по ФИО
if (model.Email != null && client.Email.Contains(model.Email) && model.Password != null && client.Password.Contains(model.Password))//затем по логину и паролю
{
return client.GetViewModel;
}

View File

@ -28,7 +28,7 @@ namespace BlacksmithWorkshopListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return result;
}
@ -58,6 +58,19 @@ namespace BlacksmithWorkshopListImplement.Implements
}
}
}
else if (model.ClientId.HasValue)//далее ищем по Id клиента
{
foreach (var order in _source.Orders)
{
if (order.ClientId == model.ClientId)
{
OrderViewModel vm = order.GetViewModel;
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
result.Add(vm);
}
}
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)

View File

@ -15,6 +15,7 @@ namespace BlacksmithWorkshopListImplement.Models
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public int ClientId { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@ -29,7 +30,8 @@ namespace BlacksmithWorkshopListImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
DateImplement = model.DateImplement,
ClientId = model.ClientId
};
}
public void Update(OrderBindingModel? model)
@ -52,7 +54,8 @@ namespace BlacksmithWorkshopListImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
DateImplement = DateImplement,
ClientId = ClientId
};
}
}

View File

@ -40,14 +40,12 @@ namespace BlacksmithWorkshopRestAPI.Controllers
{
return _manufacture.ReadElement(new ManufactureSearchModel
{
Id =
manufactureId
Id = manufactureId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта по id={Id}",
manufactureId);
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", manufactureId);
throw;
}
}