public ActionResult DeleteConfirmed(int id) { TobeSend tobeSend = db.TobeSends.Find(id); db.TobeSends.Remove(tobeSend); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,SendTime,SendStatus,ContactDetailID,WarningID")] TobeSend tobeSend) { if (ModelState.IsValid || tobeSend.SendTime <= DateTime.Now) { db.Entry(tobeSend).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ContactDetailID = new SelectList(db.ContactDetails, "Id", "Name", tobeSend.ContactDetailID); ViewBag.WarningID = new SelectList(db.Warnings, "Id", "Title", tobeSend.WarningID); return(View(tobeSend)); }
// GET: Home/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TobeSend tobeSend = db.TobeSends.Find(id); if (tobeSend == null) { return(HttpNotFound()); } return(View(tobeSend)); }
// GET: Home/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TobeSend tobeSend = db.TobeSends.Find(id); if (tobeSend == null) { return(HttpNotFound()); } ViewBag.ContactDetailID = new SelectList(db.ContactDetails, "Id", "Name", tobeSend.ContactDetailID); ViewBag.WarningID = new SelectList(db.Warnings, "Id", "Title", tobeSend.WarningID); return(View(tobeSend)); }
public ActionResult Create([Bind(Include = "Id,SendTime,SendStatus,ContactDetailID,WarningID")] TobeSend tobeSend, string SendDate, string SendTime, string TimeOption) { if (TimeOption == "set") { DateTime timeString = DateTime.Now; bool validated = true; try { DateTime.ParseExact(SendDate.Trim(), "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString(); } catch { validated = false; ViewBag.DateError = "Date is not valid!"; } try { DateTime.ParseExact(SendTime.Trim(), "HH:mm:ss", CultureInfo.InvariantCulture).ToString(); } catch { validated = false; @ViewBag.TimeError = "Time is not valid!"; } if (validated == true) { timeString = DateTime.ParseExact(SendDate + " " + SendTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); if (timeString <= DateTime.Now) { validated = false; @ViewBag.DateTimeError = "Inputed DateTime must be greater than current DateTime"; } } if (validated == true) { tobeSend.SendTime = timeString; tobeSend.SendStatus = "To be Send"; if (ModelState.IsValid) { foreach (ContactDetail item in db.ContactDetails.ToList()) { tobeSend.ContactDetail = item; db.TobeSends.Add(tobeSend); db.SaveChanges(); } return(RedirectToAction("Index")); } } @ViewBag.DateValue = SendDate; @ViewBag.TimeValue = SendTime; ViewBag.ContactDetailID = new SelectList(db.ContactDetails, "Id", "Name", tobeSend.ContactDetailID); ViewBag.WarningID = new SelectList(db.Warnings, "Id", "Title", tobeSend.WarningID); var tobeSends = db.TobeSends.Include(t => t.ContactDetail).Include(t => t.Warning); ViewBag.tobeSends = tobeSends.ToList(); return(View(tobeSend)); } tobeSend.SendTime = DateTime.Now; tobeSend.SendStatus = "To be Send"; foreach (ContactDetail item in db.ContactDetails.ToList()) { tobeSend.ContactDetail = item; db.TobeSends.Add(tobeSend); db.SaveChanges(); } return(RedirectToAction("Index")); }