feat(bll, dal): distributionPeriod - добавили типы, адаптировали методы
This commit is contained in:
@@ -362,10 +362,21 @@ namespace PARR.DAL.Context
|
||||
modelBuilder.Entity<DistributionPeriod>(f =>
|
||||
{
|
||||
f.HasData(
|
||||
new() { Id = new Guid("3A7341A8-085C-461C-BABC-6B78DD5D2C67"), Name = "Ежемесячно", Duration = new TimeSpan(28, 0, 0, 0) },
|
||||
new() { Id = new Guid("0AD2DFDB-3833-46D9-979A-C408B7EADC6C"), Name = "Каждые 90 дней", Duration = new TimeSpan(90, 0, 0, 0) }
|
||||
new() { Id = new Guid("3A7341A8-085C-461C-BABC-6B78DD5D2C67"), Name = "Ежемесячно", Duration = "1", Type = DistributionPeriodTypeEnum.Month.ToString() },
|
||||
new() { Id = new Guid("0AD2DFDB-3833-46D9-979A-C408B7EADC6C"), Name = "Каждые 90 дней", Duration = "90", Type = DistributionPeriodTypeEnum.Day.ToString() }
|
||||
);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<DistributionPeriodType>(f =>
|
||||
{
|
||||
f.HasData(
|
||||
new() { Type = DistributionPeriodTypeEnum.Day.ToString(), Description = "День" },
|
||||
new() { Type = DistributionPeriodTypeEnum.Month.ToString(), Description = "Месяц" },
|
||||
new() { Type = DistributionPeriodTypeEnum.Year.ToString(), Description = "Год" }
|
||||
//new() { Type = DistributionPeriodTypeEnum.TimeSpan.ToString(), Description = "TimeSpan" }
|
||||
);
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
2931
PARR.DAL/Migrations/20240701061944_tblDistributionPerioadAddTypes.Designer.cs
generated
Normal file
2931
PARR.DAL/Migrations/20240701061944_tblDistributionPerioadAddTypes.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
||||
|
||||
namespace PARR.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class tblDistributionPerioadAddTypes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Duration",
|
||||
table: "DistributionPeriods",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
oldClrType: typeof(TimeSpan),
|
||||
oldType: "interval");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Type",
|
||||
table: "DistributionPeriods",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "DistributionPeriodTypes",
|
||||
columns: table => new
|
||||
{
|
||||
Type = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_DistributionPeriodTypes", x => x.Type);
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "DistributionPeriodTypes",
|
||||
columns: new[] { "Type", "Description" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ "Day", "День" },
|
||||
{ "Month", "Месяц" },
|
||||
{ "TimeSpan", "TimeSpan" },
|
||||
{ "Year", "Год" }
|
||||
});
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DistributionPeriods",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("0ad2dfdb-3833-46d9-979a-c408b7eadc6c"),
|
||||
columns: new[] { "Duration", "Type" },
|
||||
values: new object[] { "90", "Day" });
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DistributionPeriods",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("3a7341a8-085c-461c-babc-6b78dd5d2c67"),
|
||||
columns: new[] { "Duration", "Type" },
|
||||
values: new object[] { "1", "Month" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DistributionPeriods_Type",
|
||||
table: "DistributionPeriods",
|
||||
column: "Type");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_DistributionPeriods_DistributionPeriodTypes_Type",
|
||||
table: "DistributionPeriods",
|
||||
column: "Type",
|
||||
principalTable: "DistributionPeriodTypes",
|
||||
principalColumn: "Type",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_DistributionPeriods_DistributionPeriodTypes_Type",
|
||||
table: "DistributionPeriods");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "DistributionPeriodTypes");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_DistributionPeriods_Type",
|
||||
table: "DistributionPeriods");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Type",
|
||||
table: "DistributionPeriods");
|
||||
|
||||
migrationBuilder.AlterColumn<TimeSpan>(
|
||||
name: "Duration",
|
||||
table: "DistributionPeriods",
|
||||
type: "interval",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DistributionPeriods",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("0ad2dfdb-3833-46d9-979a-c408b7eadc6c"),
|
||||
column: "Duration",
|
||||
value: new TimeSpan(90, 0, 0, 0, 0));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DistributionPeriods",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("3a7341a8-085c-461c-babc-6b78dd5d2c67"),
|
||||
column: "Duration",
|
||||
value: new TimeSpan(28, 0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
2926
PARR.DAL/Migrations/20240701065100_tblDistributionPeriodTypeRemoveTimeSpan.Designer.cs
generated
Normal file
2926
PARR.DAL/Migrations/20240701065100_tblDistributionPeriodTypeRemoveTimeSpan.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PARR.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class tblDistributionPeriodTypeRemoveTimeSpan : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "DistributionPeriodTypes",
|
||||
keyColumn: "Type",
|
||||
keyValue: "TimeSpan");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "DistributionPeriodTypes",
|
||||
columns: new[] { "Type", "Description" },
|
||||
values: new object[] { "TimeSpan", "TimeSpan" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,29 +309,69 @@ namespace PARR.DAL.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<TimeSpan>("Duration")
|
||||
.HasColumnType("interval");
|
||||
b.Property<string>("Duration")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Type");
|
||||
|
||||
b.ToTable("DistributionPeriods");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = new Guid("3a7341a8-085c-461c-babc-6b78dd5d2c67"),
|
||||
Duration = new TimeSpan(28, 0, 0, 0, 0),
|
||||
Name = "Ежемесячно"
|
||||
Duration = "1",
|
||||
Name = "Ежемесячно",
|
||||
Type = "Month"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = new Guid("0ad2dfdb-3833-46d9-979a-c408b7eadc6c"),
|
||||
Duration = new TimeSpan(90, 0, 0, 0, 0),
|
||||
Name = "Каждые 90 дней"
|
||||
Duration = "90",
|
||||
Name = "Каждые 90 дней",
|
||||
Type = "Day"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.DistributionPeriodType", b =>
|
||||
{
|
||||
b.Property<string>("Type")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Type");
|
||||
|
||||
b.ToTable("DistributionPeriodTypes");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Type = "Day",
|
||||
Description = "День"
|
||||
},
|
||||
new
|
||||
{
|
||||
Type = "Month",
|
||||
Description = "Месяц"
|
||||
},
|
||||
new
|
||||
{
|
||||
Type = "Year",
|
||||
Description = "Год"
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2450,6 +2490,17 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.DistributionPeriod", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.DistributionPeriodType", "DistributionPeriodType")
|
||||
.WithMany("Periods")
|
||||
.HasForeignKey("Type")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("DistributionPeriodType");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.EsppSchTypeConfig", b =>
|
||||
{
|
||||
b.HasOne("PARR.DAL.Models.EsppSchType", "EsppSchType")
|
||||
@@ -2736,6 +2787,11 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("EsppSchTypeValues");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.DistributionPeriodType", b =>
|
||||
{
|
||||
b.Navigation("Periods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.EkStatus", b =>
|
||||
{
|
||||
b.Navigation("Hosts");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using PARR.DAL.Models.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Models.Base;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
@@ -21,9 +22,45 @@ namespace PARR.DAL.Models
|
||||
|
||||
public required string Name { get; set; }
|
||||
|
||||
public TimeSpan Duration { get; set; }
|
||||
public required string Duration { get; set; }
|
||||
|
||||
public required string Type { get; set; }
|
||||
|
||||
//public DateTimeOffset AddDate
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// var typeEnum = Enum.Parse(typeof(DistributionPeriodTypeEnum), Type);
|
||||
|
||||
// switch (typeEnum)
|
||||
// {
|
||||
// case (DistributionPeriodTypeEnum.Day):
|
||||
// int.TryParse(Duration, out var intDays);
|
||||
// return new DateTimeOffset().AddDays(intDays);
|
||||
|
||||
// case (DistributionPeriodTypeEnum.Month):
|
||||
// int.TryParse(Duration, out var intMonth);
|
||||
// return new DateTimeOffset().AddMonths(intMonth);
|
||||
|
||||
// case (DistributionPeriodTypeEnum.Year):
|
||||
// int.TryParse(Duration, out var intYear);
|
||||
// return new DateTimeOffset().AddYears(intYear);
|
||||
|
||||
// case (DistributionPeriodTypeEnum.TimeSpan):
|
||||
// TimeSpan.TryParse(Duration, out var timeSpan);
|
||||
// return new DateTimeOffset().Add(timeSpan);
|
||||
// }
|
||||
|
||||
// return new DateTimeOffset();
|
||||
// }
|
||||
//}
|
||||
|
||||
[ForeignKey(nameof(Type))]
|
||||
public DistributionPeriodType? DistributionPeriodType { get; set; }
|
||||
|
||||
public ICollection<EsppSchTypeValue> EsppSchTypeValues { get; set; } = new HashSet<EsppSchTypeValue>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
16
PARR.DAL/Models/DistributionPeriodType.cs
Normal file
16
PARR.DAL/Models/DistributionPeriodType.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PARR.DAL.Models
|
||||
{
|
||||
[Table("DistributionPeriodTypes")]
|
||||
public class DistributionPeriodType
|
||||
{
|
||||
[Key]
|
||||
public required string Type { get; set; }
|
||||
|
||||
public required string Description { get; set; }
|
||||
|
||||
public ICollection<DistributionPeriod> Periods { get; set; } = new HashSet<DistributionPeriod>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user