public ActionResult Create(int tastingId) { var tastingSvc = CreateTastingService(); var tasting = tastingSvc.GetTastingById(tastingId); var wineSvc = CreateWineService(); var model = new WineCreate { TastingId = tastingId, TastingDate = tasting.TastingDate }; return(View(model)); }
public ActionResult Create(WineCreate model, int tastingId) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWineService(); if (service.CreateWine(model)) { TempData["SaveResult"] = "Your Wine was created."; return(RedirectToAction("Index", "Wine", new { tastingId })); } ; ModelState.AddModelError("", "Wine could not be created."); return(View(model)); }
public bool CreateWine(WineCreate model) { var entity = new Wine() { OwnerId = _userId, WineId = model.WineId, TastingId = model.TastingId, Brand = model.Brand, SubBrand = model.SubBrand, WineVarietal = model.WineVarietal, Region = model.Region, Year = model.Year, CodeForTasting = model.CodeForTasting, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Wines.Add(entity); return(ctx.SaveChanges() == 1); } }