public ActionResult Edit(int id) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { var data = database.tasks.Where(c => c.id == id).First(); ViewData["editID"] = data; } return(View()); }
public ActionResult EditTask(task task) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { var data = database.tasks.Where(c => c.id == task.id).First(); data.TaskName = task.TaskName; data.deadline = task.deadline; database.SaveChanges(); return(RedirectToAction("Index")); } }
public ActionResult DeleteTask(int id) { if (ModelState.IsValid) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { var data = database.tasks.Where(c => c.id == id).First(); database.tasks.Remove(data); database.SaveChanges(); return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
public ActionResult CreateTask(task task) { if (ModelState.IsValid) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { int uid = Convert.ToInt32(Session["userID"]); task.idUser = uid; database.tasks.Add(task); database.SaveChanges(); return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
// GET: Task public ActionResult Index() { if (ModelState.IsValid) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { int uid = Convert.ToInt32(Session["userID"]); var data = database.tasks.Where(c => c.idUser == uid).ToList(); if (data.Count() > 0) { string result = ""; int x = 1; foreach (var a in data) { result += "<tr>" + "<td>" + (x++).ToString() + "</td>" + "<td>" + a.TaskName + "</td>"; if (a.deadline.Year == 1) { result += "<td>" + "-" + "</td>"; } else { result += "<td>" + a.deadline + "</td>"; } result += "<td>" + "Edit | Delete" + "</td>" + "</tr>"; } ViewData["task"] = result; ViewData["taskList"] = data; return(View()); } else { return(View()); } } } return(View()); }
public ActionResult Login(string email, string password) { if (ModelState.IsValid) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { var data = database.users.Where(s => s.email.Equals(email) && s.password.Equals(password)).ToList(); if (data.Count() > 0) { //add session Session["email"] = data.FirstOrDefault().email; Session["userID"] = data.FirstOrDefault().id; return(RedirectToAction("Index", "Task", new { area = "" })); } else { ViewBag.error = "Login failed"; return(RedirectToAction("Login", "Home", new { area = "" })); } } } return(View()); }
public ActionResult CreateUser(user usr) { if (ModelState.IsValid) { using (bewaretaskaspEntities3 database = new bewaretaskaspEntities3()) { var check = database.users.FirstOrDefault(s => s.email == usr.email); if (check == null) { database.Configuration.ValidateOnSaveEnabled = false; database.users.Add(usr); database.SaveChanges(); return(RedirectToAction("Login", "Home", new { area = "" })); } else { ViewBag.error = "Email already exists"; return(RedirectToAction("Register", "Home", new { area = "" })); } } } return(RedirectToAction("Register", "Home", new { area = "" })); }