Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions PetFinder/Migrations/AddDeliveryModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace PetFinder.Migrations
{
public partial class AddDeliveryModels : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Deliveries",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DeliveryNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
ClientName = table.Column<string>(type: "nvarchar(max)", nullable: true),
Address = table.Column<string>(type: "nvarchar(max)", nullable: true),
City = table.Column<string>(type: "nvarchar(max)", nullable: true),
CUIT = table.Column<string>(type: "nvarchar(max)", nullable: true),
IVAStatus = table.Column<string>(type: "nvarchar(max)", nullable: true),
SentBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
ReceivedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
Transport = table.Column<string>(type: "nvarchar(max)", nullable: true),
DeclaredValue = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
Observations = table.Column<string>(type: "nvarchar(max)", nullable: true),
Packages = table.Column<int>(type: "int", nullable: true),
Signature = table.Column<string>(type: "nvarchar(max)", nullable: true),
Status = table.Column<string>(type: "nvarchar(max)", nullable: true),
AcceptedDate = table.Column<DateTime>(type: "datetime2", nullable: true),
UserSends = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserReceives = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Deliveries", x => x.Id);
});

migrationBuilder.CreateTable(
name: "DeliveryEquipments",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DeliveryId = table.Column<int>(type: "int", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
MAC = table.Column<string>(type: "nvarchar(max)", nullable: true),
SerialNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
SoftwareId = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeliveryEquipments", x => x.Id);
table.ForeignKey(
name: "FK_DeliveryEquipments_Deliveries_DeliveryId",
column: x => x.DeliveryId,
principalTable: "Deliveries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateTable(
name: "DeliveryProducts",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DeliveryId = table.Column<int>(type: "int", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Quantity = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DeliveryProducts", x => x.Id);
table.ForeignKey(
name: "FK_DeliveryProducts_Deliveries_DeliveryId",
column: x => x.DeliveryId,
principalTable: "Deliveries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});

migrationBuilder.CreateIndex(
name: "IX_DeliveryEquipments_DeliveryId",
table: "DeliveryEquipments",
column: "DeliveryId");

migrationBuilder.CreateIndex(
name: "IX_DeliveryProducts_DeliveryId",
table: "DeliveryProducts",
column: "DeliveryId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DeliveryEquipments");

migrationBuilder.DropTable(
name: "DeliveryProducts");

migrationBuilder.DropTable(
name: "Deliveries");
}
}
}

42 changes: 42 additions & 0 deletions PetFinder/Models/Delivery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using PetFinder.Areas.Identity;

#nullable disable

namespace PetFinder.Models
{
public class Delivery
{
public Delivery()
{
DeliveryProducts = new HashSet<DeliveryProduct>();
DeliveryEquipments = new HashSet<DeliveryEquipment>();
}

public int Id { get; set; }
public string DeliveryNumber { get; set; }
public DateTime Date { get; set; }
public string ClientName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string CUIT { get; set; }
public string IVAStatus { get; set; }
public string SentBy { get; set; }
public string ReceivedBy { get; set; }
public string Transport { get; set; }
public decimal? DeclaredValue { get; set; }
public string Observations { get; set; }
public int? Packages { get; set; }
public string Signature { get; set; }
public string Status { get; set; }
public DateTime? AcceptedDate { get; set; }
public string UserSends { get; set; }
public string UserReceives { get; set; }

// Relaciones
public virtual ICollection<DeliveryProduct> DeliveryProducts { get; set; }
public virtual ICollection<DeliveryEquipment> DeliveryEquipments { get; set; }
}
}

20 changes: 20 additions & 0 deletions PetFinder/Models/DeliveryEquipment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

#nullable disable

namespace PetFinder.Models
{
public class DeliveryEquipment
{
public int Id { get; set; }
public int DeliveryId { get; set; }
public string Description { get; set; }
public string MAC { get; set; }
public string SerialNumber { get; set; }
public string SoftwareId { get; set; }

// Relación con el remito
public virtual Delivery Delivery { get; set; }
}
}

18 changes: 18 additions & 0 deletions PetFinder/Models/DeliveryProduct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

#nullable disable

namespace PetFinder.Models
{
public class DeliveryProduct
{
public int Id { get; set; }
public int DeliveryId { get; set; }
public string Description { get; set; }
public int Quantity { get; set; }

// Relación con el remito
public virtual Delivery Delivery { get; set; }
}
}

17 changes: 16 additions & 1 deletion PetFinder/Models/PetFinderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,29 @@ public PetFinderContext(DbContextOptions<PetFinderContext> options)
public DbSet<Gender> Genders { get; set; }
public DbSet<Pet> Pets { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<Delivery> Deliveries { get; set; }
public DbSet<DeliveryProduct> DeliveryProducts { get; set; }
public DbSet<DeliveryEquipment> DeliveryEquipments { get; set; }

// Creo los generos por defecto ya que no disponen de un CRUD
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var gender1 = new Gender {Id = 1, Name = "Macho", SerializedName = "MACHO"};
var gender2 = new Gender {Id = 2, Name = "Hembra", SerializedName = "HEMBRA"};
modelBuilder.Entity<Gender>().HasData(gender1, gender2);

// Configuración de relaciones para Delivery
modelBuilder.Entity<Delivery>()
.HasMany(d => d.DeliveryProducts)
.WithOne(p => p.Delivery)
.HasForeignKey(p => p.DeliveryId);

modelBuilder.Entity<Delivery>()
.HasMany(d => d.DeliveryEquipments)
.WithOne(e => e.Delivery)
.HasForeignKey(e => e.DeliveryId);

base.OnModelCreating(modelBuilder);
}
}
}
}
Loading