public async Task <ActionResult> Edit(int id, MenuEdit note) { if (!ModelState.IsValid) { return(View(note)); } if (note.MenuId != id) { ModelState.AddModelError("", "ID Mismatch"); ViewBag.RestaurantId = await GetRestaurantAsync(); return(View(note)); } var service = CreateMenuService(); if (await service.UpdateMenuAsync(note)) { TempData["SaveResult"] = "Menu was successfully updated."; return(RedirectToAction("Index")); } ViewBag.RestaurantId = await GetRestaurantAsync(); ModelState.AddModelError("", "Menu could not be updated."); return(View(note)); }
// PUT public bool UpdateMenu(MenuEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Menus .Single(e => e.MenuId == model.MenuId /* Do I need e.ShopId == shopId here?*/); entity.Name = model.Name; return(ctx.SaveChanges() == 1); } }
private void View() { if (this.menuChild == null) { this.menuChild = new MenuEdit(); PageAnimation.back.Children.Add(this.menuChild); } Messenger.Default.Send(new ChildMessage() { currentObject = this.currentMenu, isEdit = false, action = ActionMenuButton.View, level = "Main" }); PageAnimation.ToBack(); }
public IHttpActionResult UpdateMenu(MenuEdit menu) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreatedMenuService(); if (!service.UpdateMenu(menu)) { return(InternalServerError()); } return(Ok()); }
public async Task <bool> UpdateMenuAsync(MenuEdit note) { using (var ctx = new ApplicationDbContext()) { var entity = await ctx .Menu .Where(e => e.MenuId == note.MenuId) .FirstOrDefaultAsync(); entity.Name = note.Name; entity.Description = note.Description; entity.Price = note.Price; //entity.RestaurantId = note.RestaurantId; return(await ctx.SaveChangesAsync() == 1); } }
public async Task <ActionResult> Edit(int id) { var service = CreateMenuService(); var detail = await service.GetMenuByIdAsync(id); var model = new MenuEdit { MenuId = detail.MenuId, Name = detail.Name, Description = detail.Description, Price = detail.Price, }; ViewBag.RestaurantId = await GetRestaurantAsync(); return(View(model)); }
/// <summary> /// 编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuEdit_Click(object sender, EventArgs e) { MenuEdit?.Invoke(sender, e); }