public ActionResult DeleteConfirmed(int id) { var context = new DLSMEntities(); Document dd = context.Documents.Where(p => p.CreateBy == id || p.ApproveBy == id).FirstOrDefault(); if (dd != null) { TempData["Msg"] = "ลบไม่ได้ เนื่องจากข้อมูลมีการถูกใช้งานอยู่"; } else { TransferStaff df = context.TransferStaffs.Where(p => p.StID == id).FirstOrDefault(); if (df != null) { TempData["Msg"] = "ลบไม่ได้ เนื่องจากข้อมูลมีการถูกใช้งานอยู่"; } else { db.StaffWarehouses.RemoveRange(db.StaffWarehouses.Where(x => x.StID == id)); db.SaveChanges(); Staff staff = db.Staffs.Find(id); db.Staffs.Remove(staff); db.SaveChanges(); TempData["Msg"] = "ลบข้อมูลเรียบร้อยแล้ว"; } } return(RedirectToAction("Index")); }
// GET: TransferStaffs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TransferStaff transferStaff = db.TransferStaffs.Find(id); if (transferStaff == null) { return(HttpNotFound()); } return(View(transferStaff)); }
public ActionResult Create(TransferStaff transferStaff) { transferStaff.IsActive = 1; db.TransferStaffs.Add(transferStaff); db.SaveChanges(); return(Json("success")); //return RedirectToAction("Index"); //ViewBag.StID = db.Staffs.ToList(); //ViewBag.WhID = db.Warehouses.ToList(); //ViewBag.ToWhID = db.Warehouses.ToList(); //return View(transferStaff); }
public ActionResult DeleteConfirmed(int id) { //TransferStaff transferStaff = db.TransferStaffs.Find(id); //transferStaff.IsActive = 0; //db.Entry(transferStaff).State = EntityState.Modified; //db.SaveChanges(); TransferStaff transferStaff = db.TransferStaffs.Find(id); db.TransferStaffs.Remove(transferStaff); db.SaveChanges(); TempData["Msg"] = "ลบข้อมูลเรียบร้อยแล้ว"; return(RedirectToAction("Index")); }
// GET: TransferStaffs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TransferStaff transferStaff = db.TransferStaffs.Find(id); if (transferStaff == null) { return(HttpNotFound()); } var context = new DLSMEntities(); var frwh = context.Warehouses.SingleOrDefault(u => u.ID == transferStaff.FromWhID); transferStaff.FromWhName = frwh.Name; var twh = context.Warehouses.SingleOrDefault(u => u.ID == transferStaff.ToWhID); transferStaff.ToWhName = twh.Name; var st = context.Staffs.SingleOrDefault(u => u.ID == transferStaff.StID); transferStaff.StName = st.Name; var lst = new[] { new { ID = 1, Name = "ผู้จัดการ" }, new { ID = 2, Name = "เจ้าหน้าที่" }, }; transferStaff.EffectiveDate = transferStaff.EffectiveDate.Value.AddYears(543); //List<SelectListItem> ls = new List<SelectListItem>(); //ls.Add(new SelectListItem() { Value = "1", Text = "ผู้จัดการ", Selected = (transferStaff.IsManager == "1" ? true : false) }); //ls.Add(new SelectListItem() { Value = "2", Text = "เจ้าหน้าที่", Selected = (transferStaff.IsManager == "2" ? true : false) }); ViewBag.IsManager = new SelectList(lst.ToList(), "ID", "Name", transferStaff.IsManager); //ViewBag.ListIsManager = ls; ViewBag.StID = db.Staffs.ToList(); ViewBag.WhID = db.Warehouses.ToList(); ViewBag.ToWhID = db.Warehouses.ToList(); return(View(transferStaff)); }
public ActionResult Edit(TransferStaff transferStaff) { if (ModelState.IsValid) { transferStaff.IsActive = 1; db.Entry(transferStaff).State = EntityState.Modified; db.SaveChanges(); return(Json("success")); } var lst = new[] { new { Id = 1, Name = "ผู้จัดการ" }, new { Id = 2, Name = "เจ้าหน้าที่" }, }; transferStaff.EffectiveDate = transferStaff.EffectiveDate.Value.AddYears(543); ViewBag.IsManager = new SelectList(lst, "Id", "Name"); ViewBag.StID = db.Staffs.ToList(); ViewBag.WhID = db.Warehouses.ToList(); ViewBag.ToWhID = db.Warehouses.ToList(); return(View(transferStaff)); }