using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using ApiBack.Models; namespace ApiBack.Controllers { [Route("api/[controller]")] [ApiController] public class ResponsablesController : ControllerBase { private readonly gestion_livraisonContext _context; public ResponsablesController(gestion_livraisonContext context) { _context = context; } // GET: api/Responsables [HttpGet] public IEnumerable<Responsable> GetResponsable() { return _context.Responsable; } // GET: api/Responsables/5 [HttpGet("{id}")] public async Task<IActionResult> GetResponsable([FromRoute] int id) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var responsable = await _context.Responsable.FindAsync(id); if (responsable == null) { return NotFound(); } return Ok(responsable); } // PUT: api/Responsables/5 [HttpPut("{id}")] public async Task<IActionResult> PutResponsable([FromRoute] int id, [FromBody] Responsable responsable) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != responsable.IdResponsable) { return BadRequest(); } _context.Entry(responsable).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ResponsableExists(id)) { return NotFound(); } else { throw; } } return NoContent(); } // POST: api/Responsables [HttpPost] public async Task<IActionResult> PostResponsable([FromBody] Responsable responsable) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _context.Responsable.Add(responsable); await _context.SaveChangesAsync(); return CreatedAtAction("GetResponsable", new { id = responsable.IdResponsable }, responsable); } // DELETE: api/Responsables/5 [HttpDelete("{id}")] public async Task<IActionResult> DeleteResponsable([FromRoute] int id) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var responsable = await _context.Responsable.FindAsync(id); if (responsable == null) { return NotFound(); } _context.Responsable.Remove(responsable); await _context.SaveChangesAsync(); return Ok(responsable); } private bool ResponsableExists(int id) { return _context.Responsable.Any(e => e.IdResponsable == id); } } }
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace ApiBack.Models { public partial class Responsable { public Responsable() { Agence = new HashSet<Agence>(); } [Key] public int IdResponsable { get; set; } public string NomResponsable { get; set; } public string PrenomResponsable { get; set; } public string LoginResponsable { get; set; } public string MdpResponsable { get; set; } public int? Ville { get; set; } public Ville VilleNavigation { get; set; } public ICollection<Agence> Agence { get; set; } } }
using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; namespace ApiBack.Models { public partial class gestion_livraisonContext : DbContext { public gestion_livraisonContext(DbContextOptions options) : base(options) { } public virtual DbSet<Agence> Agence { get; set; } public virtual DbSet<ClientPar> ClientPar { get; set; } public virtual DbSet<ClientPro> ClientPro { get; set; } public virtual DbSet<Commande> Commande { get; set; } public virtual DbSet<Livreur> Livreur { get; set; } public virtual DbSet<Responsable> Responsable { get; set; } public virtual DbSet<Superadmin> Superadmin { get; set; } public virtual DbSet<Ville> Ville { get; set; } } }
http://localhost:28102/api/Responsables
Responsable
s
ResponsablesController
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)