public ActionResult Create(CreateCategoryProductFormModel model) { if (ModelState.IsValid) { var category = new DANHMUC(); category.MaDM = model.MaDM; category.TenDM = model.TenDM; category.Ngaytao = DateTime.Now; try { db.DANHMUCs.Add(category); db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("save_error", "Lỗi khi lưu: " + ex.Message); return(View(model)); } return(RedirectToAction("Index", "CategoryProduct")); } return(View(model)); }
public ActionResult Themdanhmuc(FormCollection form) { if (Session["admin"] == null) { return(RedirectToAction("Login", "AdminSite")); } var tendanhmuc = form["tendanhmuc"]; var kiemtratontai = data.DANHMUCs.SingleOrDefault(x => x.TENDM == tendanhmuc); if (kiemtratontai != null) { ViewBag.tendanhmuc = "***Tên danh mục đã tồn tại!"; return(View()); } else { DANHMUC danhmuc = new DANHMUC(); danhmuc.MADM = Capma_tudong("DM"); danhmuc.TENDM = tendanhmuc; danhmuc.ACTIVE = true; data.DANHMUCs.InsertOnSubmit(danhmuc); data.SubmitChanges(); ViewBag.thongbao = "Thêm thành công!"; Update_ma("DM"); } return(View()); }
public string AddDANHMUC(DANHMUC_ViewModel model) { try { using (var db = new RestaurantManagerDataEntities()) { var checkDanhMuc = db.DANHMUCs.FirstOrDefault(x => x.iddmuc == model.iddmuc); if (checkDanhMuc == null) { var danhMuc = new DANHMUC { tendmuc = model.tendmuc, CreateBy = model.CreateBy, CreateDate = DateTime.Now, }; var result = db.DANHMUCs.Add(danhMuc); db.SaveChanges(); return("Thêm danh mục món ăn thành công!"); } else { checkDanhMuc.tendmuc = model.tendmuc; checkDanhMuc.ModifyBy = model.ModifyBy; checkDanhMuc.ModifyDate = DateTime.Now; db.SaveChanges(); return("Cập nhật danh mục món ăn thành công!"); } } } catch (Exception ex) { return(ex.Message); } }
public bool insertCategory(DANHMUC entity) { bool check = false; int maDM = 1; while (!check) { if (maDM < 10) { entity.MaDM = "DM0" + maDM.ToString(); } else { entity.MaDM = "DM" + maDM.ToString(); } try { db.DANHMUCs.Add(entity); db.SaveChanges(); check = true; return(true); } catch { } maDM++; } return(false); }
public ActionResult Edit(DANHMUC dm) { if (ModelState.IsValid) { db.Entry(dm).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult ThemDM(DANHMUC dm) { if (ModelState.IsValid) { db.DANHMUCs.InsertOnSubmit(dm); db.SubmitChanges(); } return(RedirectToAction("QLdanhmuc")); }
public ActionResult SuaDM(int id) { if (ModelState.IsValid) { DANHMUC danhmuc = db.DANHMUCs.SingleOrDefault(a => a.MaDM == id); UpdateModel(danhmuc); db.SubmitChanges(); } return(RedirectToAction("QLdanhmuc")); }
public ActionResult Create(DANHMUC dm) { if (ModelState.IsValid) { // chèn dũ liệu vào bảng nguoidung trong model db.DANHMUCs.Add(dm); // lưu vào csdl db.SaveChanges(); } return(View("Index")); }
public ActionResult Edit(string MADM) { DANHMUC dm = db.DANHMUCs.SingleOrDefault(n => n.MADM == MADM); if (dm == null) { Response.StatusCode = 404; return(null); } return(View(dm)); }
public ActionResult SPDanhmuc(int id, int?page) { int pageSize = 16; int pageNum = (page ?? 1); var a = from tt in db.SANPHAMs where tt.LOAISP.DANHMUC.MADM == id select tt; DANHMUC dm = db.DANHMUCs.SingleOrDefault(N => N.MADM == id); ViewBag.DM = dm.TENDANHMUC; return(View(a.ToPagedList(pageNum, pageSize))); }
public int Insert(DANHMUC model) { DANHMUC dbEntry = context.DANHMUCs.Find(model.ID_DM); if (dbEntry != null) { return(0); } context.DANHMUCs.Add(model); context.SaveChanges(); return(1); }
public int Delete(DANHMUC model) { DANHMUC dbEntry = context.DANHMUCs.Find(model.ID_DM); if (dbEntry == null) { return(0); } context.DANHMUCs.Remove(dbEntry); context.SaveChanges(); return(1); }
public ActionResult Xoa(string MADM) { // lấy ra đt dm theo mã DANHMUC dm = db.DANHMUCs.SingleOrDefault(n => n.MADM == MADM); if (dm == null) { Response.StatusCode = 404; return(null); } return(View(dm)); }
public ActionResult XacnhanXoa(string MADM) { DANHMUC dm = db.DANHMUCs.SingleOrDefault(n => n.MADM == MADM); if (dm == null) { Response.StatusCode = 404; return(null); } db.DANHMUCs.Remove(dm); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DanhMucAdd(DANHMUC model) { try { context.DANHMUCs.Add(model); context.SaveChanges(); return(RedirectToAction("DanhMuc")); } catch { return(View()); } }
public ActionResult Edit(DANHMUC category) { if (ModelState.IsValid) { var th = new CategoryModel(); bool res = th.updateCategory(category); if (res) { return(RedirectToAction("Edit", "Category", new { maDM = category.MaDM, type = "success" })); } } return(View(category)); }
public ActionResult FilterSPofDM(int?id) { var db = new SANPHAMFunction(); MyDB context = new MyDB(); DANHMUC dm = context.DANHMUCs.Find(id); if (dm != null) { ViewBag.TenDM = dm.tendanhmuc; } var sp = db.SANPHAMs.Where(p => p.ID_DM == id); return(View(sp)); }
public int Update(DANHMUC model) { DANHMUC dbEntry = context.DANHMUCs.Find(model.ID_DM); if (dbEntry == null) { return(0); } dbEntry.ID_DM = model.ID_DM; dbEntry.tendanhmuc = model.tendanhmuc; context.SaveChanges(); return(1); }
public ActionResult Delete(DANHMUC model) { try { var obj = context.DANHMUCs.Find(model.MaDM); context.DANHMUCs.Remove(obj); context.SaveChanges(); return(RedirectToAction("DanhMuc")); } catch { return(View()); } }
public ActionResult Delete(int id, DANHMUC model) { try { model.ID_DM = id; var result = new DANHMUCFunction.DanhMucFunction().Delete(model); return(RedirectToAction("Index")); } catch { return(View()); } }
public bool ThemDanhMuc(DANHMUC danhmuc) { try { MyDBContext context = new MyDBContext(); context.DANHMUCs.Add(danhmuc); context.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult DanhMucEdit(DANHMUC model) { try { var obj = context.DANHMUCs.Find(model.MaDM); obj.TenDM = model.TenDM; context.SaveChanges(); return(RedirectToAction("DanhMuc")); } catch { return(View()); } }
public async Task <ActionResult> Edit_DanhMuc(DANHMUC model) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44366/api/"); var putTask = await client.PutAsJsonAsync <DANHMUC>("danhmuc/updatedanhmuc", model); if (!putTask.IsSuccessStatusCode) { ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } } return(RedirectToAction("DanhMuc")); }
public bool updateCategory(DANHMUC entity) { object[] sqlParams = { new SqlParameter("@MaDM", entity.MaDM), new SqlParameter("@TenDM", entity.TenDM) }; try { db.Database.ExecuteSqlCommand("SuaDANHMUC @MaDM,@TenDM", sqlParams); return(true); } catch { } return(false); }
public ActionResult Deletedanhmuc(string iddm) { if (Session["Logedadname"] != null) { laptrinhweb1Entities1 db = new laptrinhweb1Entities1(); DANHMUC dm = new DANHMUC(); var hai = db.DANHMUCs.First(p => p.maDM == iddm); db.DANHMUCs.Remove(hai); db.SaveChanges(); return(RedirectToAction("quanlydanhmuc")); } else { return(View("fail_admin")); } }
public ActionResult Create(DANHMUC model) { try { // TODO: Add insert logic here var result = new DANHMUCFunction.DanhMucFunction().Insert(model); if (result == 0) { return(View()); } return(RedirectToAction("Index")); } catch { return(View()); } }
public List <DANHMUC> LayTenDanhMuc() { List <DANHMUC> lstTabDanhMuc = new List <DANHMUC>(); QuanLyNhaHangProjectEntities ql = new QuanLyNhaHangProjectEntities(); var tdm = from dm in ql.DANHMUCs where dm.TrangThai == false select new { dm.IDDanhMuc, dm.TenDanhMuc }; foreach (var item in tdm.ToList()) { DANHMUC dm = new DANHMUC(); dm.IDDanhMuc = item.IDDanhMuc; dm.TenDanhMuc = item.TenDanhMuc; lstTabDanhMuc.Add(dm); } return(lstTabDanhMuc); }
// Action thêm Danh Mục public ActionResult ThemDanhMuc(FormCollection f, DANHMUC DanhMuc) { try { string TENDM = f["TENDM"].ToString(); int MAMN = int.Parse(f["MAMN"].ToString()); DanhMuc.TENDM = TENDM; DanhMuc.MAMN = MAMN; DanhMuc.TRANGTHAI = true; db.DANHMUCs.Add(DanhMuc); db.SaveChanges(); } catch (Exception) { } return(RedirectToAction("DanhMuc", "QLDanhMuc")); }
public ActionResult Edit(int id, DANHMUC model) { try { model.ID_DM = id; var result = new DANHMUCFunction.DanhMucFunction().Update(model); //if (result == null) //{ // return View(); //} return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Insert(DANHMUC entity) { if (ModelState.IsValid) { var dm = new CategoryModel(); bool res = dm.insertCategory(entity); if (res) { return(RedirectToAction("Insert", "Category", new { type = "success" })); } else { return(RedirectToAction("Insert", "Category", new { type = "fail" })); } } return(View(entity)); }