public ActionResult CreateMenu(LunchMenu menuObj) { LunchMenuModel model = null; if (ModelState.IsValid) { try { if (menuObj.ImagePath != null) { string fileName = Saveimage(menuObj); model = new LunchMenuModel { DishName = menuObj.DishName, Price = menuObj.Price, ServedAt = menuObj.ServedAt, ImagePath = fileName }; } using (MongoContext<LunchMenuModel> db = new MongoContext<LunchMenuModel>("LunchMenu")) { db.context.Insert(model); return RedirectToAction("Index"); } } catch (Exception e) { ViewBag.Error = e.Message; return View(); } } return View(); }
public ActionResult Edit(LunchMenuModel menu) { if (ModelState.IsValid) { try { menu.ImagePath = GetPreviosImageName(menu.Id); using (MongoContext<LunchMenuModel> db = new MongoContext<LunchMenuModel>("LunchMenu")) { db.context.Save(menu); return RedirectToAction("Index"); } } catch (Exception e) { ViewBag.Error = e.Message; return RedirectToAction("Index"); } } return View(); }