public IActionResult Create(BeerFormViewModel model) { if (!ModelState.IsValid) { model.Breweries = this.GetBreweriesListItems(); model.Styles = this.GetStylesListItems(); return(View(model)); } var beerId = this.beers.Create( model.Name, model.Price, model.Quantity, model.Description, model.Alcohol, model.Volume, model.ServingTemp, model.Color, model.Bitterness, model.Density, model.Sweetness, model.Gasification, model.StyleId, model.BreweryId); if (model.Image.HasValidImage()) { var imageName = model.Image.SaveImage(beerId, BeerProduct, BeersImagesPath); this.beers.SetImage(beerId, imageName); } TempData.AddSuccessMessage(string.Format(SuccessfullAdd, model.Name)); return(RedirectToAction(nameof(All))); }
public IActionResult AddBeer(BeerFormViewModel addedBeer) { BeerBDD beerBDD = new BeerBDD(); addedBeer.Categories = populateCategorie(); addedBeer.Gammes = populateGamme(); IActionResult retour = null; if (ModelState.IsValid) { Beer beer = new Beer(); beer.Identifiant = addedBeer.Identifiant; beer.Libelle = addedBeer.Libelle; beer.DateProduction = addedBeer.DateProduction; beer.TauxAlcoolemie = float.Parse(addedBeer.TauxAlcoolemie); beer.IdentifiantCategorie = addedBeer.IdentifiantCategorie; beer.IdentifiantGamme = addedBeer.IdentifiantGamme; beer.Commentaire = addedBeer.Commentaire; bool isOK = beerBDD.Insert(beer); retour = RedirectToAction("Index"); } else { retour = View(addedBeer); } return(retour); }
public IActionResult Edit(BeerFormViewModel modifiedBeer) { BeerBDD beerBDD = new BeerBDD(); IActionResult retour = null; if (ModelState.IsValid) { Beer beer = new Beer(); beer.Identifiant = modifiedBeer.Identifiant; beer.Libelle = modifiedBeer.Libelle; beer.DateProduction = modifiedBeer.DateProduction; beer.TauxAlcoolemie = float.Parse(modifiedBeer.TauxAlcoolemie); beer.IdentifiantCategorie = modifiedBeer.IdentifiantCategorie; beer.IdentifiantGamme = modifiedBeer.IdentifiantGamme; beer.Commentaire = modifiedBeer.Commentaire; bool isOK = beerBDD.Update(beer); retour = RedirectToAction("Index"); } else { retour = View(modifiedBeer); } return(retour); }
public IActionResult AddBeer() { BeerFormViewModel model = new BeerFormViewModel(); model.Categories = populateCategorie(); model.Gammes = populateGamme(); return(View(model)); }
public IActionResult Edit(int id) { BeerBDD beerBDD = new BeerBDD(); Beer beer = beerBDD.Get(id); BeerFormViewModel beerModel = new BeerFormViewModel(); beerModel.Identifiant = beer.Identifiant; beerModel.Libelle = beer.Libelle; beerModel.DateProduction = beer.DateProduction; beerModel.TauxAlcoolemie = beer.TauxAlcoolemie.ToString(); beerModel.IdentifiantCategorie = beer.IdentifiantCategorie; beerModel.IdentifiantGamme = beer.IdentifiantGamme; beerModel.Commentaire = beer.Commentaire; beerModel.Categories = populateCategorie(); beerModel.Gammes = populateGamme(); return(View(beerModel)); }
public IActionResult Edit(int id, BeerFormViewModel model) { if (!ModelState.IsValid) { model.Breweries = this.GetBreweriesListItems(); model.Styles = this.GetStylesListItems(); return(View(model)); } if (model.Image.HasValidImage()) { this.beers.SetImage(id, model.Image.SaveImage(id, BeerProduct, BeersImagesPath)); } var success = this.beers.Edit( id, model.Name, model.Price, model.Quantity, model.Description, model.Alcohol, model.Volume, model.ServingTemp, model.Color, model.Bitterness, model.Density, model.Sweetness, model.Gasification, model.StyleId, model.BreweryId); if (!success) { return(BadRequest()); } TempData.AddWarningMessage(string.Format(SuccessfullEdit, model.Name)); return(RedirectToAction(nameof(All))); }