public ActionResult Delete(int id) { using (BusinessDataBaseEntities db = new BusinessDataBaseEntities()) { ReportTimeSystem r = db.ReportTimeSystems.Where(x => x.ReportID == id).FirstOrDefault <ReportTimeSystem>(); db.ReportTimeSystems.Remove(r); db.SaveChanges(); return(Json(new { success = true, message = "刪除成功" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit([Bind(Include = "ReportID,ReportName,employeeID,StartTime,EndTime,EventHours,EventID,Note,ApplyDateTime,Discontinue")] ReportTimeSystem reportTimeSystem) { if (ModelState.IsValid) { db.Entry(reportTimeSystem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.employeeID = new SelectList(db.Employees, "employeeID", "EmployeeName", reportTimeSystem.employeeID); ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", reportTimeSystem.EventID); return(View(reportTimeSystem)); }
// GET: ReportTimeSystems/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ReportTimeSystem reportTimeSystem = db.ReportTimeSystems.Find(id); if (reportTimeSystem == null) { return(HttpNotFound()); } return(View(reportTimeSystem)); }
// GET: ReportTimeSystems/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ReportTimeSystem reportTimeSystem = db.ReportTimeSystems.Find(id); if (reportTimeSystem == null) { return(HttpNotFound()); } ViewBag.employeeID = new SelectList(db.Employees, "employeeID", "EmployeeName", reportTimeSystem.employeeID); ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", reportTimeSystem.EventID); return(View(reportTimeSystem)); }
public ActionResult AddOrEdit(ReportTimeSystem r) { ViewBag.employeeID = new SelectList(db.Employees, "employeeID", "EmployeeName"); ViewBag.eventID = new SelectList(db.Events, "eventID", "EventName"); using (BusinessDataBaseEntities db = new BusinessDataBaseEntities()) { if (r.ReportID == 0) { db.ReportTimeSystems.Add(new ReportTimeSystem() { ReportName = r.ReportName, employeeID = EmployeeDetail.EmployeeID, StartTime = r.StartTime, EndTime = r.EndTime, EventHours = (r.EndTime - r.StartTime).TotalHours, EventID = r.EventID, Note = r.Note, ApplyDateTime = DateTime.Now, Discontinue = true, }); db.SaveChanges(); return(Json(new { success = true, message = "發布成功" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(r).State = EntityState.Modified; db.Entry(r).OriginalValues.SetValues(r.EventHours = (r.EndTime - r.StartTime).TotalHours); db.ReportTimeSystems.First().ApplyDateTime = DateTime.Now; db.SaveChanges(); return(Json(new { success = true, message = "修改成功" }, JsonRequestBehavior.AllowGet)); } } }