From 1087ccf57f502a57c9eff1d6e7b7fa53a7ab4d38 Mon Sep 17 00:00:00 2001 From: TNO Date: Mon, 20 May 2019 15:58:04 -0500 Subject: [PATCH 1/3] Fix some things. --- BizLogic/Administration/PaisViewModel.cs | 2 +- TripManager2.0/ViewModels/ViajeViewModel.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BizLogic/Administration/PaisViewModel.cs b/BizLogic/Administration/PaisViewModel.cs index aa00d70..01460f0 100644 --- a/BizLogic/Administration/PaisViewModel.cs +++ b/BizLogic/Administration/PaisViewModel.cs @@ -9,7 +9,7 @@ public class PaisViewModel { [Required, StringLength(15)] public string Name { get; set; } - [StringLength(20)] + [Required, StringLength(20)] public string RegionName { get; set; } public IEnumerable Regiones { get; set; } } diff --git a/TripManager2.0/ViewModels/ViajeViewModel.cs b/TripManager2.0/ViewModels/ViajeViewModel.cs index 321a374..a2eab69 100644 --- a/TripManager2.0/ViewModels/ViajeViewModel.cs +++ b/TripManager2.0/ViewModels/ViajeViewModel.cs @@ -7,8 +7,8 @@ namespace TripManager2._0.ViewModels { public class ViajeViewModel { - public List Start { get; set; } - public List End { get; set; } + public List Start { get; set; } + public List End { get; set; } public List Country { get; set;} public List City { get; set; } public List Motivo { get; set; } @@ -16,8 +16,8 @@ public class ViajeViewModel public ViajeViewModel() { - Start = new List(); - End = new List(); + Start = new List(); + End = new List(); City = new List(); Country = new List(); Motivo = new List(); From a8e07ff48e8ccc8a3156bc7defe0de6219a6cbda Mon Sep 17 00:00:00 2001 From: TNO Date: Mon, 20 May 2019 16:22:14 -0500 Subject: [PATCH 2/3] Updated Viaje. remove Usuario property. --- BizData/Entities/Viaje.cs | 1 - BizDbAccess/Repositories/HistorialDbAccess.cs | 15 ++++----------- BizDbAccess/Repositories/ViajeDbAccess.cs | 1 - .../Workflow/Concrete/RegisterHistorialAction.cs | 2 +- BizLogic/Workflow/ViajeCommand.cs | 7 ++----- ServiceLayer/WorkFlowServices/WorkflowServices.cs | 3 +-- TripManager2.0/Controllers/UserController.cs | 4 ++-- TripManager2.0/Views/Shared/Viaje.cshtml | 2 -- 8 files changed, 10 insertions(+), 25 deletions(-) diff --git a/BizData/Entities/Viaje.cs b/BizData/Entities/Viaje.cs index 44393e2..38b558c 100644 --- a/BizData/Entities/Viaje.cs +++ b/BizData/Entities/Viaje.cs @@ -20,6 +20,5 @@ public class Viaje public virtual Pais Pais { get; set; } public virtual Ciudad Ciudad { get; set; } public virtual Institucion Institucion { get; set; } - public virtual Itinerario Itinerario { get; set; } } } diff --git a/BizDbAccess/Repositories/HistorialDbAccess.cs b/BizDbAccess/Repositories/HistorialDbAccess.cs index b842348..6d79ed3 100644 --- a/BizDbAccess/Repositories/HistorialDbAccess.cs +++ b/BizDbAccess/Repositories/HistorialDbAccess.cs @@ -32,20 +32,13 @@ public void Delete(Historial entity) public Historial Update(Historial entity, Historial toUpd) { - if (toUpd == null) - throw new Exception("Historial to be updated no exist"); - - toUpd.EstadoViaje = entity.EstadoViaje ?? toUpd.EstadoViaje; - toUpd.Viaje = entity.Viaje ?? toUpd.Viaje; - - _context.Historial.Update(toUpd); - return toUpd; + throw new NotImplementedException(); } - public Historial GetHistorial(string estadoViaje, Itinerario viaje) + public Historial GetHistorial(Estado estadoViaje, Itinerario viaje) { - return _context.Historial.Where(h => h.EstadoViaje == estadoViaje && - h.Viaje.Usuario.Id == viaje.Usuario.Id) + return _context.Historial.Where(h => h.Estado == estadoViaje && + h.Itinerario.Usuario.Id == viaje.Usuario.Id) .SingleOrDefault(); } } diff --git a/BizDbAccess/Repositories/ViajeDbAccess.cs b/BizDbAccess/Repositories/ViajeDbAccess.cs index 0fd5507..4ed3702 100644 --- a/BizDbAccess/Repositories/ViajeDbAccess.cs +++ b/BizDbAccess/Repositories/ViajeDbAccess.cs @@ -38,7 +38,6 @@ public Viaje Update(Viaje entity, Viaje toUpd) toUpd.FechaInicio = entity.FechaInicio ?? toUpd.FechaFin; toUpd.MotivoViaje = entity.MotivoViaje ?? toUpd.MotivoViaje; toUpd.Pais = entity.Pais ?? toUpd.Pais; - toUpd.Usuario = entity.Usuario ?? toUpd.Usuario; toUpd.Ciudad = entity.Ciudad ?? toUpd.Ciudad; _context.Viajes.Update(toUpd); diff --git a/BizLogic/Workflow/Concrete/RegisterHistorialAction.cs b/BizLogic/Workflow/Concrete/RegisterHistorialAction.cs index 5b8ec9c..1000c06 100644 --- a/BizLogic/Workflow/Concrete/RegisterHistorialAction.cs +++ b/BizLogic/Workflow/Concrete/RegisterHistorialAction.cs @@ -20,7 +20,7 @@ public Historial Action(Historial dto) { try { - var result = _dbAccess.GetHistorial(dto.EstadoViaje, dto.Viaje); + var result = _dbAccess.GetHistorial(dto.Estado, dto.Itinerario); if (result != null) throw new InvalidOperationException(); diff --git a/BizLogic/Workflow/ViajeCommand.cs b/BizLogic/Workflow/ViajeCommand.cs index 4941bc7..a06edd6 100644 --- a/BizLogic/Workflow/ViajeCommand.cs +++ b/BizLogic/Workflow/ViajeCommand.cs @@ -14,16 +14,14 @@ public class ViajeCommand public DateTime? FechaInicio { get; set; } public DateTime? FechaFin { get; set; } - public Usuario Usuario { get; set; } public Pais Pais { get; set; } public Ciudad Ciudad { get; set; } //public Institucion Institucion { get; set; } public Itinerario Itinerario { get; set; } - public ViajeCommand(int itinerarioID, string usuarioID, string paisName, string motivo, DateTime? fechaInicio, DateTime? fechaFin) + public ViajeCommand(int itinerarioID, string paisName, string motivo, DateTime? fechaInicio, DateTime? fechaFin) { ItinerarioID = itinerarioID; - UsuarioId = usuarioID; FechaInicio = fechaInicio; FechaFin = fechaFin; PaisName = paisName; @@ -35,9 +33,8 @@ public Viaje ToViaje() return new Viaje() { MotivoViaje = Motivo, - Usuario = Usuario, Pais = Pais, - Ciudad = Ciudad + //Ciudad = Ciudad // Institucion = Institucion }; } diff --git a/ServiceLayer/WorkFlowServices/WorkflowServices.cs b/ServiceLayer/WorkFlowServices/WorkflowServices.cs index 7d9e49a..542dba7 100644 --- a/ServiceLayer/WorkFlowServices/WorkflowServices.cs +++ b/ServiceLayer/WorkFlowServices/WorkflowServices.cs @@ -70,9 +70,8 @@ public void Removeitinerario(Itinerario entity) _context.Commit(); } - public async Task RegisterViajeAsync(ViajeCommand cmd) + public long RegisterViajeAsync(ViajeCommand cmd) { - cmd.Usuario = await _userManager.FindByIdAsync(cmd.UsuarioId); //cmd.Ciudad = _ciudadDbAccess.GetCiudad(cmd.CiudadName); //cmd.Institucion = _institucionDbAccess.GetInstitucion(cmd.InstitucionName); cmd.Pais = _paisDbAccess.GetPais(cmd.PaisName); diff --git a/TripManager2.0/Controllers/UserController.cs b/TripManager2.0/Controllers/UserController.cs index 6abdd74..c38735f 100644 --- a/TripManager2.0/Controllers/UserController.cs +++ b/TripManager2.0/Controllers/UserController.cs @@ -71,8 +71,8 @@ public async Task Create(ViajeViewModel vm) for (int i = 0; i < vm.Country.Count(); i++) { - var viajeCmd = new ViajeCommand(iterID, iterCmd.UsuarioID, vm.Country[i], vm.Motivo[i], vm.Start[i], vm.End[i]); - await services.RegisterViajeAsync(viajeCmd); + var viajeCmd = new ViajeCommand(iterID, vm.Country[i], vm.Motivo[i], vm.Start[i], vm.End[i]); + services.RegisterViajeAsync(viajeCmd); } return View("Welcome"); diff --git a/TripManager2.0/Views/Shared/Viaje.cshtml b/TripManager2.0/Views/Shared/Viaje.cshtml index d57fb75..106249e 100644 --- a/TripManager2.0/Views/Shared/Viaje.cshtml +++ b/TripManager2.0/Views/Shared/Viaje.cshtml @@ -9,6 +9,4 @@ @Model.FechaFin -@Html.Partial("Usuario", Model.Usuario) - From 4d547115118de1b0fe8437a0cfee11d887b1019a Mon Sep 17 00:00:00 2001 From: TNO Date: Mon, 20 May 2019 22:05:55 -0500 Subject: [PATCH 3/3] Added new migrations. --- ...90520214442_FinalSprint-2.1.0.Designer.cs} | 38 +++++++++------ ...cs => 20190520214442_FinalSprint-2.1.0.cs} | 46 ++++++++++--------- .../Migrations/EfCoreContextModelSnapshot.cs | 34 ++++++++------ 3 files changed, 69 insertions(+), 49 deletions(-) rename DataLayer/Migrations/{20190515092956_FinalSprint-2.0.0.Designer.cs => 20190520214442_FinalSprint-2.1.0.Designer.cs} (96%) rename DataLayer/Migrations/{20190515092956_FinalSprint-2.0.0.cs => 20190520214442_FinalSprint-2.1.0.cs} (96%) diff --git a/DataLayer/Migrations/20190515092956_FinalSprint-2.0.0.Designer.cs b/DataLayer/Migrations/20190520214442_FinalSprint-2.1.0.Designer.cs similarity index 96% rename from DataLayer/Migrations/20190515092956_FinalSprint-2.0.0.Designer.cs rename to DataLayer/Migrations/20190520214442_FinalSprint-2.1.0.Designer.cs index 06502b0..f61b790 100644 --- a/DataLayer/Migrations/20190515092956_FinalSprint-2.0.0.Designer.cs +++ b/DataLayer/Migrations/20190520214442_FinalSprint-2.1.0.Designer.cs @@ -10,8 +10,8 @@ namespace DataLayer.Migrations { [DbContext(typeof(EfCoreContext))] - [Migration("20190515092956_FinalSprint-2.0.0")] - partial class FinalSprint200 + [Migration("20190520214442_FinalSprint-2.1.0")] + partial class FinalSprint210 { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -44,13 +44,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("EstadoViaje"); + b.Property("Comentario"); - b.Property("ViajeItinerarioID"); + b.Property("Estado"); + + b.Property("Fecha"); + + b.Property("ItinerarioID"); + + b.Property("UsuarioId"); b.HasKey("HistorialID"); - b.HasIndex("ViajeItinerarioID"); + b.HasIndex("ItinerarioID"); + + b.HasIndex("UsuarioId"); b.ToTable("Historial"); }); @@ -74,6 +82,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("Estado"); + b.Property("FechaFin"); b.Property("FechaInicio"); @@ -81,6 +91,8 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("UsuarioId") .IsRequired(); + b.Property("status"); + b.HasKey("ItinerarioID"); b.HasIndex("UsuarioId"); @@ -237,8 +249,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("PaisID"); - b.Property("UsuarioId"); - b.HasKey("ViajeID"); b.HasIndex("CiudadID"); @@ -249,8 +259,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasIndex("PaisID"); - b.HasIndex("UsuarioId"); - b.ToTable("Viajes"); }); @@ -394,9 +402,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) modelBuilder.Entity("BizData.Entities.Historial", b => { - b.HasOne("BizData.Entities.Itinerario", "Viaje") + b.HasOne("BizData.Entities.Itinerario", "Itinerario") + .WithMany() + .HasForeignKey("ItinerarioID"); + + b.HasOne("BizData.Entities.Usuario", "Usuario") .WithMany() - .HasForeignKey("ViajeItinerarioID"); + .HasForeignKey("UsuarioId"); }); modelBuilder.Entity("BizData.Entities.Itinerario", b => @@ -455,10 +467,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasOne("BizData.Entities.Pais", "Pais") .WithMany() .HasForeignKey("PaisID"); - - b.HasOne("BizData.Entities.Usuario", "Usuario") - .WithMany() - .HasForeignKey("UsuarioId"); }); modelBuilder.Entity("BizData.Entities.Visa", b => diff --git a/DataLayer/Migrations/20190515092956_FinalSprint-2.0.0.cs b/DataLayer/Migrations/20190520214442_FinalSprint-2.1.0.cs similarity index 96% rename from DataLayer/Migrations/20190515092956_FinalSprint-2.0.0.cs rename to DataLayer/Migrations/20190520214442_FinalSprint-2.1.0.cs index 90f1b0e..bdec12d 100644 --- a/DataLayer/Migrations/20190515092956_FinalSprint-2.0.0.cs +++ b/DataLayer/Migrations/20190520214442_FinalSprint-2.1.0.cs @@ -4,7 +4,7 @@ namespace DataLayer.Migrations { - public partial class FinalSprint200 : Migration + public partial class FinalSprint210 : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -190,8 +190,10 @@ protected override void Up(MigrationBuilder migrationBuilder) { ItinerarioID = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + status = table.Column(nullable: true), FechaInicio = table.Column(nullable: true), FechaFin = table.Column(nullable: true), + Estado = table.Column(nullable: false), UsuarioId = table.Column(nullable: false) }, constraints: table => @@ -258,18 +260,27 @@ protected override void Up(MigrationBuilder migrationBuilder) { HistorialID = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - EstadoViaje = table.Column(nullable: true), - ViajeItinerarioID = table.Column(nullable: true) + Comentario = table.Column(nullable: true), + Estado = table.Column(nullable: false), + Fecha = table.Column(nullable: false), + UsuarioId = table.Column(nullable: true), + ItinerarioID = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Historial", x => x.HistorialID); table.ForeignKey( - name: "FK_Historial_Itinerarios_ViajeItinerarioID", - column: x => x.ViajeItinerarioID, + name: "FK_Historial_Itinerarios_ItinerarioID", + column: x => x.ItinerarioID, principalTable: "Itinerarios", principalColumn: "ItinerarioID", onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Historial_AspNetUsers_UsuarioId", + column: x => x.UsuarioId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( @@ -353,11 +364,10 @@ protected override void Up(MigrationBuilder migrationBuilder) MotivoViaje = table.Column(nullable: true), FechaInicio = table.Column(nullable: true), FechaFin = table.Column(nullable: true), - UsuarioId = table.Column(nullable: true), + ItinerarioID = table.Column(nullable: true), PaisID = table.Column(nullable: true), CiudadID = table.Column(nullable: true), - InstitucionID = table.Column(nullable: true), - ItinerarioID = table.Column(nullable: true) + InstitucionID = table.Column(nullable: true) }, constraints: table => { @@ -386,12 +396,6 @@ protected override void Up(MigrationBuilder migrationBuilder) principalTable: "Paises", principalColumn: "PaisID", onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Viajes_AspNetUsers_UsuarioId", - column: x => x.UsuarioId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( @@ -439,9 +443,14 @@ protected override void Up(MigrationBuilder migrationBuilder) column: "PaisID"); migrationBuilder.CreateIndex( - name: "IX_Historial_ViajeItinerarioID", + name: "IX_Historial_ItinerarioID", + table: "Historial", + column: "ItinerarioID"); + + migrationBuilder.CreateIndex( + name: "IX_Historial_UsuarioId", table: "Historial", - column: "ViajeItinerarioID"); + column: "UsuarioId"); migrationBuilder.CreateIndex( name: "IX_Itinerarios_UsuarioId", @@ -493,11 +502,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Viajes", column: "PaisID"); - migrationBuilder.CreateIndex( - name: "IX_Viajes_UsuarioId", - table: "Viajes", - column: "UsuarioId"); - migrationBuilder.CreateIndex( name: "IX_Visas_RegionID", table: "Visas", diff --git a/DataLayer/Migrations/EfCoreContextModelSnapshot.cs b/DataLayer/Migrations/EfCoreContextModelSnapshot.cs index be92451..1d9a026 100644 --- a/DataLayer/Migrations/EfCoreContextModelSnapshot.cs +++ b/DataLayer/Migrations/EfCoreContextModelSnapshot.cs @@ -42,13 +42,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("EstadoViaje"); + b.Property("Comentario"); - b.Property("ViajeItinerarioID"); + b.Property("Estado"); + + b.Property("Fecha"); + + b.Property("ItinerarioID"); + + b.Property("UsuarioId"); b.HasKey("HistorialID"); - b.HasIndex("ViajeItinerarioID"); + b.HasIndex("ItinerarioID"); + + b.HasIndex("UsuarioId"); b.ToTable("Historial"); }); @@ -72,6 +80,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + b.Property("Estado"); + b.Property("FechaFin"); b.Property("FechaInicio"); @@ -79,6 +89,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UsuarioId") .IsRequired(); + b.Property("status"); + b.HasKey("ItinerarioID"); b.HasIndex("UsuarioId"); @@ -235,8 +247,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("PaisID"); - b.Property("UsuarioId"); - b.HasKey("ViajeID"); b.HasIndex("CiudadID"); @@ -247,8 +257,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("PaisID"); - b.HasIndex("UsuarioId"); - b.ToTable("Viajes"); }); @@ -392,9 +400,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("BizData.Entities.Historial", b => { - b.HasOne("BizData.Entities.Itinerario", "Viaje") + b.HasOne("BizData.Entities.Itinerario", "Itinerario") + .WithMany() + .HasForeignKey("ItinerarioID"); + + b.HasOne("BizData.Entities.Usuario", "Usuario") .WithMany() - .HasForeignKey("ViajeItinerarioID"); + .HasForeignKey("UsuarioId"); }); modelBuilder.Entity("BizData.Entities.Itinerario", b => @@ -453,10 +465,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("BizData.Entities.Pais", "Pais") .WithMany() .HasForeignKey("PaisID"); - - b.HasOne("BizData.Entities.Usuario", "Usuario") - .WithMany() - .HasForeignKey("UsuarioId"); }); modelBuilder.Entity("BizData.Entities.Visa", b =>