public HttpResponseMessage Get() { VendsRepository VenteRepo = new VendsRepository(connexion); var user = VenteRepo.GetAll().ToList(); return(Request.CreateResponse(HttpStatusCode.OK, user)); }
public HttpResponseMessage Get(DateTime debut, DateTime fin, int idPF) { ProduitRepository ProdRepo = new ProduitRepository(connexion); VendsRepository venteRepo = new VendsRepository(connexion); var result = ProdRepo.GetByDate(debut, fin, idPF); if (result == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, "prod with ID: " + result.ToString() + "not found")); } var ventes = new Ventes(); foreach (var item in venteRepo.GetAll()) { int month = item.DateVente.Month; string prodName = ProdRepo.GetOne(item.IdProduit).NomProduit; double prodPrix = ProdRepo.GetOne(item.IdProduit).Prix; switch (prodName) { case "Marc": ventes.MarcCollectes[month] += prodPrix; break; case "Kit": ventes.Kit[month] += prodPrix; break; case "Fungipop": ventes.Fungipop[month] += prodPrix; break; default: break; } } var productions = new Productions(); foreach (var item in venteRepo.GetAll()) { int month = item.DateVente.Month; string prodName = ProdRepo.GetOne(item.IdProduit).NomProduit; double prodQuantite = ProdRepo.GetOne(item.IdProduit).Quantite; switch (prodName) { case "Marc": productions.Pleurottes[month] += prodQuantite; break; case "Kit": productions.Pieds[month] += prodQuantite; break; case "Fungipop": productions.Panicaults[month] += prodQuantite; break; default: break; } } var finalResult = new VenteEtProduction() { ventes = ventes, productions = productions }; return(Request.CreateResponse(HttpStatusCode.OK, finalResult)); }