public IActionResult CreateTopping(CreateToppingViewModel newItem) { var newCreatedItem = new Topping { Active = newItem.Active == "true" ? true : false, ToppingName = newItem.Name, CreateBy = 1, CreateTime = DateTime.UtcNow, UpdateBy = 1, UpdateTime = DateTime.UtcNow }; _ctx.Topping.Add(newCreatedItem); _ctx.SaveChanges(); foreach (var toppingTypeId in newItem.ToppingTypeIds) { var toppingSysRef = new ToppingSystemReference { ToppingId = newCreatedItem.Id, ToppingTypeId = toppingTypeId, CreateBy = 1, CreateTime = DateTime.UtcNow, UpdateBy = 1, UpdateTime = DateTime.UtcNow }; _ctx.ToppingSystemReference.Add(toppingSysRef); } _ctx.SaveChanges(); var success = newItem.Name.ToString(); ViewBag.Create = success; return(Redirect("CreateTopping")); }
public IActionResult CreateTopping() { var toppingTypes = _ctx.SystemReference.Where(x => x.AltValue == "Topping").ToList(); var toppingTypesViewModel = new CreateToppingViewModel { ToppingTypes = toppingTypes }; return(View(toppingTypesViewModel)); }