public ActionResult Create(MenuModel model, HttpPostedFileBase file) { string gambar = ""; if (file != null) { string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/images/" + ImageName); file.SaveAs(physicalPath); gambar = ImageName; } try { // TODO: Add insert logic here tMenu menu = new tMenu() { IdMenu = model.IdMenu, Nama = model.Nama, Harga = (int)model.Harga, Stok = (int)model.Stok, Images = gambar }; context.tMenus.InsertOnSubmit(menu); context.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View(model)); } }
public ActionResult DeleteConfirmed(int id) { tMenu tmenu = db.tMenu.Find(id); db.tMenu.Remove(tmenu); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(tMenu tmenu) { if (ModelState.IsValid) { db.Entry(tmenu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tmenu)); }
public ActionResult Edit(int id = 0) { tMenu tmenu = db.tMenu.Find(id); if (tmenu == null) { return(HttpNotFound()); } return(View(tmenu)); }
public ActionResult Create(tMenu tmenu) { if (ModelState.IsValid) { tmenu.addeddate = DateTime.Now; db.tMenu.Add(tmenu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tmenu)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } tMenu = await _context.tMenu.SingleOrDefaultAsync(m => m.menu_id == id); if (tMenu == null) { return(NotFound()); } return(Page()); }
public ActionResult Delete(MenuModel model) { try { // TODO: Add delete logic here tMenu menu = context.tMenus.Where(some => some.IdMenu == model.IdMenu).SingleOrDefault(); context.tMenus.DeleteOnSubmit(menu); context.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } tMenu = await _context.tMenu.FindAsync(id); if (tMenu != null) { _context.tMenu.Remove(tMenu); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
protected void btnSave_Click(object sender, EventArgs e) { if (cl.checkRole(Session["userid_hcc"].ToString(), codeModule, 1)) { if (txtName.Text.Trim().Equals("")) { Mess("Nhập tên menu", ""); } else { try { tMenu t = new tMenu(); if (!dlParentMenu.SelectedValue.Trim().Equals("")) { t.ParentId = int.Parse(dlParentMenu.SelectedValue.Trim()); } t.Name = txtName.Text.Trim(); if (!txtLink.Text.Trim().Equals("")) { t.Link = txtLink.Text.Trim(); } t.CreateAt = DateTime.Now; t.Position = double.Parse(txtPosition.Text.Trim()); t.IsActive = ckActive.Checked; t.Code = cl.ConvertToUnSign(txtName.Text.Trim().ToLower()); db.tMenus.InsertOnSubmit(t); db.SubmitChanges(); ResetControl(); LoadGrid(); Mess("Lưu thành công", ""); } catch (Exception ax) { Mess(ax.Message, ""); } } } else { Mess("Bạn không có quyền sử dụng chức năng này", "/adhome"); } }
public long AddMenu(string menuName, string menuCode, int menuTypeID, int createdBy, long cycleId, int languageId) { tMenu menu = new tMenu(); menu.MenuName = menuName; menu.MenuCode = menuCode; menu.MenuTypeID = menuTypeID; menu.CreatedBy = createdBy; menu.CycleID = cycleId; menu.LanguageID = languageId; menu.CreatedAt = DateTime.Now; menu.IsDeleted = false; menu.CurrentApprovalStatusID = 1; _context.tMenu.Add(menu); _context.SaveChanges(); return(menu.ID); }
public ActionResult Edit(MenuModel model) { try { // TODO: Add update logic here tMenu menu = context.tMenus.Where(some => some.IdMenu == model.IdMenu).SingleOrDefault(); menu.IdMenu = model.IdMenu; menu.Nama = model.Nama; menu.Harga = model.Harga; menu.Stok = model.Stok; menu.Images = model.Images; context.SubmitChanges(); return(RedirectToAction("Index")); } catch { OrderModel modela = new OrderModel(); return(View(modela)); } }
public long CreateReorderMenuFromMenuid(long menuId, int userid) { var originalMenu = _menuManagement.GetMenuById(menuId); var currCycleId = (from c in _context.tCycle where c.Active == true select c.CycleID).FirstOrDefault(); if (originalMenu != null) { //getdata var getOldMenuData = (from om in _context.tMenu where om.ID == menuId select om).FirstOrDefault(); long newMenuId = 0; if (getOldMenuData != null) { //create new menu var ifDuplicate = '_'; var newmenu = new tMenu(); newmenu.MenuName = getOldMenuData.MenuName; if (getOldMenuData.MenuCode.Contains(ifDuplicate)) { string oldMenucode = getOldMenuData.MenuCode; string str1 = oldMenucode.Substring(0, 8); int str2 = Convert.ToInt16(oldMenucode.Substring(8)); //check if there is a higher version of the menu already exist for (var i = 1; i < 50; i++) { string str3 = Convert.ToString(str2 + i); string checkmenucode = str1 + str3; var checkmenu = _menuManagement.GetMenuIdByMenuCode(checkmenucode); if (checkmenu == 0) { newmenu.MenuCode = checkmenucode; break; } } } else { string oldMenucode = getOldMenuData.MenuCode; string str1 = oldMenucode + "_"; for (var i = 1; i < 50; i++) { string str2 = Convert.ToString(i); string checkmenucode = str1 + str2; var checkmenu = _menuManagement.GetMenuIdByMenuCode(checkmenucode); if (checkmenu == 0) { newmenu.MenuCode = checkmenucode; break; } } } newmenu.MenuTypeID = getOldMenuData.MenuTypeID; newmenu.IsDeleted = false; newmenu.CreatedAt = DateTime.Now; newmenu.CreatedBy = userid; newmenu.LanguageID = getOldMenuData.LanguageID; newmenu.CycleID = currCycleId; newmenu.CurrentApprovalStatusID = 1; newmenu.IsMovedToLiveOrder = false; newmenu.ReorderCount = null; _context.tMenu.Add(newmenu); _context.SaveChanges(); newMenuId = newmenu.ID; } //get and create new Menuforroutes var oldMenuforRoutesData = (from mfr in _context.tMenuForRoute where mfr.MenuID == menuId select mfr).ToList(); foreach (var mfrdata in oldMenuforRoutesData) { var newmfr = new tMenuForRoute(); newmfr.MenuID = newMenuId; newmfr.RouteID = mfrdata.RouteID; newmfr.Flights = mfrdata.Flights; _context.tMenuForRoute.Add(newmfr); _context.SaveChanges(); } //get and create new MenuItem var oldMenuItemData = (from mi in _context.tMenuItem where mi.MenuID == menuId select mi).ToList(); foreach (var midata in oldMenuItemData) { var newmi = new tMenuItem(); newmi.MenuID = newMenuId; newmi.BaseItemCode = midata.BaseItemCode; _context.tMenuItem.Add(newmi); _context.SaveChanges(); } //get and create new MenuTemplate var oldMenuTemplate = (from mt in _context.tMenuTemplates where mt.MenuID == menuId select mt).FirstOrDefault(); var newMenuTemp = new tMenuTemplates(); newMenuTemp.MenuID = newMenuId; newMenuTemp.TemplateID = oldMenuTemplate.TemplateID; newMenuTemp.ChiliDocumentID = oldMenuTemplate.ChiliDocumentID; _context.tMenuTemplates.Add(newMenuTemp); _context.SaveChanges(); return(newMenuId); } else { return(0); } }
private void CloneMenus(string fromCycle, Dictionary <long, long> NewClonedMenus, tCycle cycleFrom, tCycle cycleTo, long toCycleID, List <tMenu> oldMenus) { foreach (var oldMenu in oldMenus) { if (oldMenu == null) { continue; } //create menu var oldMenuId = oldMenu.ID; tMenu newMenu = new tMenu(); var menuName = oldMenu.MenuName.Replace(cycleFrom.CycleShortName, cycleTo.CycleShortName); newMenu.MenuName = menuName; //TODO : assign new menu code //newMenu.MenuCode = oldMenu.MenuCode; newMenu.MenuTypeID = oldMenu.MenuTypeID; newMenu.IsDeleted = oldMenu.IsDeleted; newMenu.CreatedAt = System.DateTime.Now; newMenu.CreatedBy = 2; newMenu.LanguageID = oldMenu.LanguageID; //assign new cycle id newMenu.CycleID = toCycleID; newMenu.CurrentApprovalStatusID = 1; _context.tMenu.Add(newMenu); _context.SaveChanges(); var newMenuId = newMenu.ID; //create menu for route var menuForRoutes = _context.tMenuForRoute.Where(mr => mr.MenuID == oldMenuId).ToList(); foreach (var menuForRoute in menuForRoutes) { tMenuForRoute newMenuForRoute = new tMenuForRoute(); newMenuForRoute.MenuID = newMenuId; newMenuForRoute.RouteID = menuForRoute.RouteID; newMenuForRoute.Flights = menuForRoute.Flights; _context.tMenuForRoute.Add(newMenuForRoute); _context.SaveChanges(); } //write to menu history tMenuHistory history = new tMenuHistory(); history.MenuID = newMenuId; history.ActionTaken = "Menu created by cloning from menu - " + oldMenu.MenuCode + " cycle -" + fromCycle; history.ActionByUserID = 2; history.ModifiedAt = System.DateTime.Now; _context.tMenuHistory.Add(history); _context.SaveChanges(); //clone menu chili doc tempalte and assign var oldMenuTemplate = _context.tMenuTemplates.Where(t => t.MenuID == oldMenuId).FirstOrDefault(); tMenuTemplates newMenuTemplate = new tMenuTemplates(); newMenuTemplate.MenuID = newMenuId; newMenuTemplate.ChiliDocumentID = ""; newMenuTemplate.TemplateID = oldMenuTemplate.TemplateID; _context.tMenuTemplates.Add(newMenuTemplate); _context.SaveChanges(); NewClonedMenus.Add(newMenuId, oldMenuId); } }