diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/ClientLogic.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/ClientLogic.cs index 9c80d5c..2564c73 100644 --- a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/ClientLogic.cs @@ -142,9 +142,9 @@ namespace TransportCompanyBusinessLogic.BusinessLogic } //проверка на наличие телефонного номера - if (string.IsNullOrEmpty(model.TelephoneNumber)) + if (string.IsNullOrEmpty(model.Telephone)) { - throw new ArgumentNullException("Нет телефонного номера клиента", nameof(model.TelephoneNumber)); + throw new ArgumentNullException("Нет телефонного номера клиента", nameof(model.Telephone)); } //проверка на наличие почты @@ -155,7 +155,7 @@ namespace TransportCompanyBusinessLogic.BusinessLogic _logger.LogInformation("Client. Name:{Name}. Surname:{Surname}. Patronymic:{Patronymic}. " + "TelephoneNumber:{TelephoneNumber}. Email:{Email}. Id:{Id}", - model.Name, model.Surname, model.Patronymic, model.TelephoneNumber, model.Email, model.Id); + model.Name, model.Surname, model.Patronymic, model.Telephone, model.Email, model.Id); //проверка на наличие такой же почты в списке var element = _clientStorage.GetElement(new ClientSearchModel diff --git a/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs b/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs index 194baea..9322118 100644 --- a/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs +++ b/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs @@ -101,7 +101,7 @@ public partial class ElegevContext : DbContext entity.Property(e => e.DateStart).HasColumnName("date_start"); entity.Property(e => e.Price).HasColumnName("price"); entity.Property(e => e.TransportId).HasColumnName("transport_id"); - entity.Property(e => e.TypeTransportationId).HasColumnName("type_transportation_id"); + entity.Property(e => e.TransportationId).HasColumnName("transportation_id"); entity.HasOne(d => d.Cargo).WithMany(p => p.Truckings) .HasForeignKey(d => d.CargoId) @@ -119,7 +119,7 @@ public partial class ElegevContext : DbContext .HasConstraintName("transport_id"); entity.HasOne(d => d.TypeTransportation).WithMany(p => p.Truckings) - .HasForeignKey(d => d.TypeTransportationId) + .HasForeignKey(d => d.TransportationId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("type_transportation_id"); }); diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Implements/CargoStorage.cs b/TransportCompany/TransportCompanyDatabaseImplements/Implements/CargoStorage.cs new file mode 100644 index 0000000..d46ec27 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplements/Implements/CargoStorage.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplements.Models; + +namespace TransportCompanyDatabaseImplements.Implements +{ + public class CargoStorage : ICargoStorage + { + public CargoViewModel? Delete(CargoBindingModel model) + { + using var context = new ElegevContext(); + + var element = context.Cargos + .FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Cargos.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public CargoViewModel? GetElement(CargoSearchModel model) + { + if (string.IsNullOrEmpty(model.TypeCargo) && !model.Id.HasValue) + { + return null; + } + + using var context = new ElegevContext(); + + return context.Cargos + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(CargoSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + using var context = new ElegevContext(); + + return context.Cargos + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new ElegevContext(); + + return context.Cargos + .Select(x => x.GetViewModel) + .ToList(); + } + + public CargoViewModel? Insert(CargoBindingModel model) + { + using var context = new ElegevContext(); + + model.Id = context.Cargos.Count() > 0 ? context.Cargos.Max(x => x.Id) + 1 : 1; + + var newCargo = Cargo.Create(model); + + if (newCargo == null) + { + return null; + } + + context.Cargos.Add(newCargo); + context.SaveChanges(); + + return newCargo.GetViewModel; + } + + public CargoViewModel? Update(CargoBindingModel model) + { + using var context = new ElegevContext(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var cargo = context.Cargos.FirstOrDefault(rec => rec.Id == model.Id); + + if (cargo == null) + { + return null; + } + + cargo.Update(model); + context.SaveChanges(); + transaction.Commit(); + + return cargo.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Implements/ClientStorage.cs b/TransportCompany/TransportCompanyDatabaseImplements/Implements/ClientStorage.cs index 4b128f4..46bbc8e 100644 --- a/TransportCompany/TransportCompanyDatabaseImplements/Implements/ClientStorage.cs +++ b/TransportCompany/TransportCompanyDatabaseImplements/Implements/ClientStorage.cs @@ -7,6 +7,7 @@ using TransportCompanyContracts.BindingModels; using TransportCompanyContracts.SearchModels; using TransportCompanyContracts.StoragesContracts; using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplements.Models; namespace TransportCompanyDatabaseImplements.Implements { @@ -16,32 +17,102 @@ namespace TransportCompanyDatabaseImplements.Implements { using var context = new ElegevContext(); - return context.Clients.ToList(); + return context.Clients + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(ClientSearchModel model) { - throw new NotImplementedException(); + if (!model.Id.HasValue) + { + return new(); + } + + using var context = new ElegevContext(); + + return context.Clients + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public ClientViewModel? GetElement(ClientSearchModel model) { - throw new NotImplementedException(); + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + + using var context = new ElegevContext(); + + return context.Clients + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ClientViewModel? Insert(ClientBindingModel model) { - throw new NotImplementedException(); + using var context = new ElegevContext(); + + model.Id = context.Clients.Count() > 0 ? context.Clients.Max(x => x.Id) + 1 : 1; + + var newClient = Client.Create(model); + + if (newClient == null) + { + return null; + } + + context.Clients.Add(newClient); + context.SaveChanges(); + + return newClient.GetViewModel; } public ClientViewModel? Update(ClientBindingModel model) { - throw new NotImplementedException(); + using var context = new ElegevContext(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var client = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + + if (client == null) + { + return null; + } + + client.Update(model); + context.SaveChanges(); + transaction.Commit(); + + return client.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } } public ClientViewModel? Delete(ClientBindingModel model) { - throw new NotImplementedException(); + using var context = new ElegevContext(); + + var element = context.Clients + .FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Clients.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; } } } diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Implements/TranportationStorage.cs b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TranportationStorage.cs new file mode 100644 index 0000000..1af94e7 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TranportationStorage.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplements.Models; + +namespace TransportCompanyDatabaseImplements.Implements +{ + public class TranportationStorage : ITransportationStorage + { + public TransportationViewModel? Delete(TransportationBindingModel model) + { + using var context = new ElegevContext(); + + var element = context.TypeTransportations + .FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.TypeTransportations.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public TransportationViewModel? GetElement(TransportationSearchModel model) + { + if (string.IsNullOrEmpty(model.TransportationType) && !model.Id.HasValue) + { + return null; + } + + using var context = new ElegevContext(); + + return context.TypeTransportations + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(TransportationSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + using var context = new ElegevContext(); + + return context.TypeTransportations + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new ElegevContext(); + + return context.TypeTransportations + .Select(x => x.GetViewModel) + .ToList(); + } + + public TransportationViewModel? Insert(TransportationBindingModel model) + { + using var context = new ElegevContext(); + + model.Id = context.TypeTransportations.Count() > 0 ? context.TypeTransportations.Max(x => x.Id) + 1 : 1; + + var newTypeTransportation = TypeTransportation.Create(model); + + if (newTypeTransportation == null) + { + return null; + } + + context.TypeTransportations.Add(newTypeTransportation); + context.SaveChanges(); + + return newTypeTransportation.GetViewModel; + } + + public TransportationViewModel? Update(TransportationBindingModel model) + { + using var context = new ElegevContext(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var typeTransportations = context.TypeTransportations.FirstOrDefault(rec => rec.Id == model.Id); + + if (typeTransportations == null) + { + return null; + } + + typeTransportations.Update(model); + context.SaveChanges(); + transaction.Commit(); + + return typeTransportations.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Implements/TransportStorage.cs b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TransportStorage.cs new file mode 100644 index 0000000..2f0ae4e --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TransportStorage.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplements.Models; + +namespace TransportCompanyDatabaseImplements.Implements +{ + public class TransportStorage : ITransportStorage + { + public TransportViewModel? Delete(TransportBindingModel model) + { + using var context = new ElegevContext(); + + var element = context.Transports + .FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Transports.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public TransportViewModel? GetElement(TransportSearchModel model) + { + if (string.IsNullOrEmpty(model.Tranport) && !model.Id.HasValue) + { + return null; + } + + using var context = new ElegevContext(); + + return context.Transports + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(TransportSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + using var context = new ElegevContext(); + + return context.Transports + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new ElegevContext(); + + return context.Transports + .Select(x => x.GetViewModel) + .ToList(); + } + + public TransportViewModel? Insert(TransportBindingModel model) + { + using var context = new ElegevContext(); + + model.Id = context.Transports.Count() > 0 ? context.Transports.Max(x => x.Id) + 1 : 1; + + var newTransport = Transport.Create(model); + + if (newTransport == null) + { + return null; + } + + context.Transports.Add(newTransport); + context.SaveChanges(); + + return newTransport.GetViewModel; + } + + public TransportViewModel? Update(TransportBindingModel model) + { + using var context = new ElegevContext(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var transport = context.Transports.FirstOrDefault(rec => rec.Id == model.Id); + + if (transport == null) + { + return null; + } + + transport.Update(model); + context.SaveChanges(); + transaction.Commit(); + + return transport.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs new file mode 100644 index 0000000..b6272af --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TransportCompanyContracts.BindingModels; +using TransportCompanyContracts.SearchModels; +using TransportCompanyContracts.StoragesContracts; +using TransportCompanyContracts.ViewModels; +using TransportCompanyDatabaseImplements.Models; + +namespace TransportCompanyDatabaseImplements.Implements +{ + public class TruckingStorage : ITruckingStorage + { + public TruckingViewModel? Delete(TruckingBindingModel model) + { + using var context = new ElegevContext(); + + var element = context.Truckings + .FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Truckings.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + + public TruckingViewModel? GetElement(TruckingSearchModel model) + { + if (!model.Id.HasValue || !model.ClientId.HasValue) + { + return null; + } + + using var context = new ElegevContext(); + + return context.Truckings + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(TruckingSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + using var context = new ElegevContext(); + + return context.Truckings + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new ElegevContext(); + + return context.Truckings + .Select(x => x.GetViewModel) + .ToList(); + } + + public TruckingViewModel? Insert(TruckingBindingModel model) + { + using var context = new ElegevContext(); + + model.Id = context.Truckings.Count() > 0 ? context.Truckings.Max(x => x.Id) + 1 : 1; + + var newTrucking = Trucking.Create(model); + + if (newTrucking == null) + { + return null; + } + + context.Truckings.Add(newTrucking); + context.SaveChanges(); + + return newTrucking.GetViewModel; + } + + public TruckingViewModel? Update(TruckingBindingModel model) + { + using var context = new ElegevContext(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var trucking = context.Truckings.FirstOrDefault(rec => rec.Id == model.Id); + + if (trucking == null) + { + return null; + } + + trucking.Update(model); + context.SaveChanges(); + transaction.Commit(); + + return trucking.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Migrations/20230412213501_FirstMigra.Designer.cs b/TransportCompany/TransportCompanyDatabaseImplements/Migrations/20230412213501_FirstMigra.Designer.cs new file mode 100644 index 0000000..ae09b0d --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplements/Migrations/20230412213501_FirstMigra.Designer.cs @@ -0,0 +1,239 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using TransportCompanyDatabaseImplements; + +#nullable disable + +namespace TransportCompanyDatabaseImplements.Migrations +{ + [DbContext(typeof(ElegevContext))] + [Migration("20230412213501_FirstMigra")] + partial class FirstMigra + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.HasSequence("seq_cargo"); + + modelBuilder.HasSequence("seq_client"); + + modelBuilder.HasSequence("seq_trucking"); + + modelBuilder.HasSequence("seq_type_transport"); + + modelBuilder.HasSequence("seq_type_transportation"); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Cargo", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("TypeCargo") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("type_cargo"); + + b.HasKey("Id") + .HasName("cargo_pkey"); + + b.ToTable("cargo", (string)null); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Client", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("email"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("name"); + + b.Property("Patronymic") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("patronymic"); + + b.Property("Surname") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("surname"); + + b.Property("Telephone") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("telephone"); + + b.HasKey("Id") + .HasName("client_pkey"); + + b.ToTable("client", (string)null); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Transport", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("TransportType") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("transport_type"); + + b.HasKey("Id") + .HasName("transport_pkey"); + + b.ToTable("transport", (string)null); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Trucking", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("CargoId") + .HasColumnType("integer") + .HasColumnName("cargo_id"); + + b.Property("ClientId") + .HasColumnType("integer") + .HasColumnName("client_id"); + + b.Property("DateEnd") + .HasColumnType("timestamp with time zone") + .HasColumnName("date_end"); + + b.Property("DateStart") + .HasColumnType("timestamp with time zone") + .HasColumnName("date_start"); + + b.Property("Price") + .HasColumnType("double precision") + .HasColumnName("price"); + + b.Property("TransportId") + .HasColumnType("integer") + .HasColumnName("transport_id"); + + b.Property("TransportationId") + .HasColumnType("integer") + .HasColumnName("transportation_id"); + + b.HasKey("Id") + .HasName("trucking_pkey"); + + b.HasIndex("CargoId"); + + b.HasIndex("ClientId"); + + b.HasIndex("TransportId"); + + b.HasIndex("TransportationId"); + + b.ToTable("trucking", (string)null); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.TypeTransportation", b => + { + b.Property("Id") + .HasColumnType("integer") + .HasColumnName("id"); + + b.Property("TransportationType") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)") + .HasColumnName("transportation_type"); + + b.HasKey("Id") + .HasName("type_transportation_pkey"); + + b.ToTable("type_transportation", (string)null); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Trucking", b => + { + b.HasOne("TransportCompanyDatabaseImplements.Models.Cargo", "Cargo") + .WithMany("Truckings") + .HasForeignKey("CargoId") + .IsRequired() + .HasConstraintName("cargo_id"); + + b.HasOne("TransportCompanyDatabaseImplements.Models.Client", "Client") + .WithMany("Truckings") + .HasForeignKey("ClientId") + .IsRequired() + .HasConstraintName("client_id"); + + b.HasOne("TransportCompanyDatabaseImplements.Models.Transport", "Transport") + .WithMany("Truckings") + .HasForeignKey("TransportId") + .IsRequired() + .HasConstraintName("transport_id"); + + b.HasOne("TransportCompanyDatabaseImplements.Models.TypeTransportation", "TypeTransportation") + .WithMany("Truckings") + .HasForeignKey("TransportationId") + .IsRequired() + .HasConstraintName("type_transportation_id"); + + b.Navigation("Cargo"); + + b.Navigation("Client"); + + b.Navigation("Transport"); + + b.Navigation("TypeTransportation"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Cargo", b => + { + b.Navigation("Truckings"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Client", b => + { + b.Navigation("Truckings"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.Transport", b => + { + b.Navigation("Truckings"); + }); + + modelBuilder.Entity("TransportCompanyDatabaseImplements.Models.TypeTransportation", b => + { + b.Navigation("Truckings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Migrations/20230412213501_FirstMigra.cs b/TransportCompany/TransportCompanyDatabaseImplements/Migrations/20230412213501_FirstMigra.cs new file mode 100644 index 0000000..902e467 --- /dev/null +++ b/TransportCompany/TransportCompanyDatabaseImplements/Migrations/20230412213501_FirstMigra.cs @@ -0,0 +1,87 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace TransportCompanyDatabaseImplements.Migrations +{ + /// + public partial class FirstMigra : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "type_transportation_id", + table: "trucking", + newName: "transportation_id"); + + migrationBuilder.RenameIndex( + name: "IX_trucking_type_transportation_id", + table: "trucking", + newName: "IX_trucking_transportation_id"); + + migrationBuilder.AlterColumn( + name: "price", + table: "trucking", + type: "double precision", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "date_start", + table: "trucking", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateOnly), + oldType: "date"); + + migrationBuilder.AlterColumn( + name: "date_end", + table: "trucking", + type: "timestamp with time zone", + nullable: false, + oldClrType: typeof(DateOnly), + oldType: "date"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "transportation_id", + table: "trucking", + newName: "type_transportation_id"); + + migrationBuilder.RenameIndex( + name: "IX_trucking_transportation_id", + table: "trucking", + newName: "IX_trucking_type_transportation_id"); + + migrationBuilder.AlterColumn( + name: "price", + table: "trucking", + type: "integer", + nullable: false, + oldClrType: typeof(double), + oldType: "double precision"); + + migrationBuilder.AlterColumn( + name: "date_start", + table: "trucking", + type: "date", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + + migrationBuilder.AlterColumn( + name: "date_end", + table: "trucking", + type: "date", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "timestamp with time zone"); + } + } +} diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Migrations/ElegevContextModelSnapshot.cs b/TransportCompany/TransportCompanyDatabaseImplements/Migrations/ElegevContextModelSnapshot.cs index b10b48a..65069f1 100644 --- a/TransportCompany/TransportCompanyDatabaseImplements/Migrations/ElegevContextModelSnapshot.cs +++ b/TransportCompany/TransportCompanyDatabaseImplements/Migrations/ElegevContextModelSnapshot.cs @@ -124,25 +124,25 @@ namespace TransportCompanyDatabaseImplements.Migrations .HasColumnType("integer") .HasColumnName("client_id"); - b.Property("DateEnd") - .HasColumnType("date") + b.Property("DateEnd") + .HasColumnType("timestamp with time zone") .HasColumnName("date_end"); - b.Property("DateStart") - .HasColumnType("date") + b.Property("DateStart") + .HasColumnType("timestamp with time zone") .HasColumnName("date_start"); - b.Property("Price") - .HasColumnType("integer") + b.Property("Price") + .HasColumnType("double precision") .HasColumnName("price"); b.Property("TransportId") .HasColumnType("integer") .HasColumnName("transport_id"); - b.Property("TypeTransportationId") + b.Property("TransportationId") .HasColumnType("integer") - .HasColumnName("type_transportation_id"); + .HasColumnName("transportation_id"); b.HasKey("Id") .HasName("trucking_pkey"); @@ -153,7 +153,7 @@ namespace TransportCompanyDatabaseImplements.Migrations b.HasIndex("TransportId"); - b.HasIndex("TypeTransportationId"); + b.HasIndex("TransportationId"); b.ToTable("trucking", (string)null); }); @@ -198,7 +198,7 @@ namespace TransportCompanyDatabaseImplements.Migrations b.HasOne("TransportCompanyDatabaseImplements.Models.TypeTransportation", "TypeTransportation") .WithMany("Truckings") - .HasForeignKey("TypeTransportationId") + .HasForeignKey("TransportationId") .IsRequired() .HasConstraintName("type_transportation_id");