public ActionResult CreateUpdateKCCD(CTKhoanChiCD kccd) { if (Session["User"] == null) { return(RedirectToAction("Login", "Account")); } var user = (NguoiDung)Session["User"]; List <LoaiKhoanChi> list = service.LoaiKhoanChi().ToList(); int ma = list.Single(s => s.tenloaichi == kccd.tenloaichi).maloaichi; kccd.maloaichi = ma; kccd.mand = user.mand; if (ModelState.IsValid) { if (kccd.makhoanchi > 0) { service.UpdateKCCD(kccd); } else { service.AddKCCD(kccd); } } return(RedirectToAction("ChiTieu")); }
public bool UpdateKCCD(CTKhoanChiCD news) { try { KhoanChiCD kt = context.KhoanChiCDs.Single(sv => sv.makhoanchi == news.makhoanchi && sv.mand == news.mand); kt.tenkhoanchi = news.tenkhoanchi; kt.tienchicd = news.tienchicd; kt.thangbd = news.thangbd; kt.thangkt = news.thangkt; kt.maloaichi = news.maloaichi; context.SubmitChanges(); return(true); } catch { return(false); } }
public bool AddKCCD(CTKhoanChiCD news) { try { KhoanChiCD kt = new KhoanChiCD(); kt.tenkhoanchi = news.tenkhoanchi; kt.tienchicd = news.tienchicd; kt.thangbd = news.thangbd; kt.thangkt = news.thangkt; kt.maloaichi = news.maloaichi; kt.mand = news.mand; context.KhoanChiCDs.InsertOnSubmit(kt); context.SubmitChanges(); return(true); } catch { return(false); } }
public ActionResult AddEditKhoanChiCD(int itemId) { if (Session["User"] == null) { return(RedirectToAction("Login", "Account")); } var user = (NguoiDung)Session["User"]; CTKhoanChiCD model = new CTKhoanChiCD(); if (itemId > 0) { model = service.kccd(itemId, user.mand); } ViewBag.khoanchi = model; List <LoaiKhoanChi> list = service.LoaiKhoanChi().ToList(); ViewBag.listkhoanchi = list; return(PartialView("KhoanChiCDForm")); }