/// <summary> /// UPDATE /// </summary> /// <param name="depotDto"></param> public void UpdateDepot(DepotDTO depotDto) { var dbContext = new RentAVehicleDB(); Depot depot = _mapper.Map <Depot>(depotDto); dbContext.Depots.Attach(depot); dbContext.SaveChanges(); }
//INSERT public void InsertBrand(BrandDTO brandDTO) { RentAVehicleDB dbContext = new RentAVehicleDB(); Brand brand = Mapper.Map <Brand>(brandDTO); brand.Id = Guid.NewGuid(); dbContext.Brands.Add(brand); dbContext.SaveChanges(); }
/// <summary> /// INSERT /// </summary> /// <param name="depotDto"></param> public void InsertDepot(DepotDTO depotDto) { var dbContext = new RentAVehicleDB(); Depot depot = _mapper.Map <Depot>(depotDto); depot.Id = Guid.NewGuid(); dbContext.Depots.Add(depot); dbContext.SaveChanges(); }
/// <summary> /// INSERT /// </summary> public void InsertModel(ModelDTO modelDto) { var dbContext = new RentAVehicleDB(); Model model = _mapper.Map <Model>(modelDto); model.Id = Guid.NewGuid(); model.BrandId = model.Brand.Id; dbContext.Models.Add(model); dbContext.SaveChanges(); }
//DELETE public void DeleteBrand(Guid brandId) { RentAVehicleDB dbContext = new RentAVehicleDB(); var brand = dbContext.Brands.SingleOrDefault(x => x.Id == brandId); if (brand == null) { throw new KeyNotFoundException(); } dbContext.Brands.Remove(brand); dbContext.SaveChanges(); }
/// <summary> /// DELETE /// </summary> /// <param name="id"></param> public void DeleteDepot(Guid id) { var dbContext = new RentAVehicleDB(); var depot = dbContext.Depots.FirstOrDefault(x => x.Id == id); if (depot == null) { throw new Exception("Depot n'existe pas"); } dbContext.Depots.Remove(depot); dbContext.SaveChanges(); }