MODELS AND CONTROLLERS
This commit is contained in:
14
Models/BibliotecaContext.cs
Normal file
14
Models/BibliotecaContext.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using BibliotecaAPI.Models;
|
||||
|
||||
namespace BibliotecaAPI.Data
|
||||
{
|
||||
public class BibliotecaContext : DbContext
|
||||
{
|
||||
public BibliotecaContext(DbContextOptions<BibliotecaContext> options) : base(options) { }
|
||||
|
||||
public DbSet<Libro> Libros { get; set; }
|
||||
public DbSet<Usuario> Usuarios { get; set; }
|
||||
public DbSet<Prestamo> Prestamos { get; set; }
|
||||
}
|
||||
}
|
||||
16
Models/Libro.cs
Normal file
16
Models/Libro.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BibliotecaAPI.Models
|
||||
{
|
||||
public class Libro
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Titulo { get; set; } = string.Empty;
|
||||
public string Autor { get; set; } = string.Empty;
|
||||
public string ISBN { get; set; } = string.Empty;
|
||||
public int Año { get; set; }
|
||||
public string Categoria { get; set; } = string.Empty;
|
||||
public int CopiasDisponibles { get; set; }
|
||||
}
|
||||
}
|
||||
24
Models/Prestamo.cs
Normal file
24
Models/Prestamo.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BibliotecaAPI.Models
|
||||
{
|
||||
public class Prestamo
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[ForeignKey("Usuario")]
|
||||
public int UsuarioId { get; set; }
|
||||
public Usuario? Usuario { get; set; }
|
||||
|
||||
[ForeignKey("Libro")]
|
||||
public int LibroId { get; set; }
|
||||
public Libro? Libro { get; set; }
|
||||
|
||||
public DateTime FechaPrestamo { get; set; } = DateTime.Now;
|
||||
public DateTime? FechaDevolucion { get; set; }
|
||||
public bool Devuelto { get; set; } = false;
|
||||
}
|
||||
}
|
||||
12
Models/Usuario.cs
Normal file
12
Models/Usuario.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BibliotecaAPI.Models
|
||||
{
|
||||
public class Usuario
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Nombre { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user