public ActionResult ToggleDone(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetTask item = db.PetTasks.Find(id); if (item == null) { return(HttpNotFound()); } if (item.IsDone) { item.IsDone = false; item.ApplicationUser = null; } else if (!item.IsDone) { item.IsDone = true; UserManager <User> UserManager = new UserManager <User>(new UserStore <User>(db)); User currentUser = UserManager.FindById(User.Identity.GetUserId()); item.ApplicationUser = currentUser; } db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: PetTasks/Edit/5 public ActionResult Edit(int?id) { if (Request.IsAuthenticated) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetTask petTask = db.PetTasks.Find(id); if (petTask == null) { return(HttpNotFound()); } ViewBag.ApplicationUserID = new SelectList(db.Users, "Id", "Email", petTask.ApplicationUserID); UserManager <User> UserManager = new UserManager <User>(new UserStore <User>(db)); User currentUser = UserManager.FindById(User.Identity.GetUserId()); var groupIds = currentUser.Groups.Select(g => g.GroupID); IEnumerable <Location> locations = db.Locations.Where(l => groupIds.Contains(l.GroupID)).AsEnumerable(); ViewBag.LocationID = new SelectList(locations, "LocationID", "LocationName"); IEnumerable <Pet> pets = db.Pets.Where(p => groupIds.Contains(p.Location.GroupID)).AsEnumerable(); ViewBag.PetID = new SelectList(pets, "PetID", "PetName"); ViewBag.TaskTypeID = new SelectList(db.TaskTypes, "TaskID", "TaskTypeName", petTask.TaskTypeID); ViewBag.Deadline = petTask.Deadline.Date; return(View(petTask)); } return(RedirectToAction("/Index")); }
public ActionResult DeleteConfirmed(int id) { PetTask petTask = db.PetTasks.Find(id); db.PetTasks.Remove(petTask); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "TaskID,TaskDescription,Frequency,Deadline,LocationID,PetID,TaskTypeID,ApplicationUserID")] PetTask petTask) { if (ModelState.IsValid) { db.Entry(petTask).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ApplicationUserID = new SelectList(db.ApplicationUsers, "Id", "Email", petTask.ApplicationUserID); ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "LocationName", petTask.LocationID); ViewBag.PetID = new SelectList(db.Pets, "PetID", "PetName", petTask.PetID); ViewBag.TaskTypeID = new SelectList(db.TaskTypes, "TaskID", "TaskTypeName", petTask.TaskTypeID); return(View(petTask)); }
// GET: PetTasks/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetTask petTask = db.PetTasks.Find(id); if (petTask == null) { return(HttpNotFound()); } return(View(petTask)); }
// GET: PetTasks/Details/5 public ActionResult Details(int?id) { if (Request.IsAuthenticated) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetTask petTask = db.PetTasks.Find(id); if (petTask == null) { return(HttpNotFound()); } return(View(petTask)); } return(RedirectToAction("/Index")); }
// GET: PetTasks/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetTask petTask = db.PetTasks.Find(id); if (petTask == null) { return(HttpNotFound()); } ViewBag.ApplicationUserID = new SelectList(db.ApplicationUsers, "Id", "Email", petTask.ApplicationUserID); ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "LocationName", petTask.LocationID); ViewBag.PetID = new SelectList(db.Pets, "PetID", "PetName", petTask.PetID); ViewBag.TaskTypeID = new SelectList(db.TaskTypes, "TaskID", "TaskTypeName", petTask.TaskTypeID); return(View(petTask)); }
public ActionResult Edit([Bind(Include = "TaskID,TaskDescription,Frequency,Deadline,PetID,TaskTypeID,ApplicationUserID")] PetTask petTask) { if (Request.IsAuthenticated) { if (ModelState.IsValid) { db.Entry(petTask).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ApplicationUserID = new SelectList(db.Users, "Id", "Email", petTask.ApplicationUserID); UserManager <User> UserManager = new UserManager <User>(new UserStore <User>(db)); User currentUser = UserManager.FindById(User.Identity.GetUserId()); var groupIds = currentUser.Groups.Select(g => g.GroupID); IEnumerable <Location> locations = db.Locations.Where(l => groupIds.Contains(l.GroupID)).AsEnumerable(); ViewBag.LocationID = new SelectList(locations, "LocationID", "LocationName"); IEnumerable <Pet> pets = db.Pets.Where(p => groupIds.Contains(p.Location.GroupID)).AsEnumerable(); ViewBag.PetID = new SelectList(pets, "PetID", "PetName"); ViewBag.TaskTypeID = new SelectList(db.TaskTypes, "TaskID", "TaskTypeName", petTask.TaskTypeID); return(View(petTask)); } return(RedirectToAction("/Index")); }
public SealPetTaskInfo(PetTask rTask) { Task = rTask; }
public SealPetTaskInfo(int rTaskId) { Task = ConfigManager.Get <PetTask>(rTaskId); }
public void TaskTick(User currentUser) { var groupIds = currentUser.Groups.Select(g => g.GroupID); IEnumerable <PetTask> userPetTasks = db.PetTasks.Where(p => groupIds.Contains(p.Pet.Location.GroupID)).Where(p => p.IsArchived == false).AsEnumerable(); IEnumerable <LocationTask> userLocationTasks = db.LocationTasks.Where(l => groupIds.Contains(l.Location.GroupID)).Where(l => l.IsArchived == false).AsEnumerable(); foreach (PetTask petTask in userPetTasks.ToList()) { int offset; switch (petTask.Frequency.ToLower()) { case "daily": offset = 1; break; case "weekly": offset = 7; break; case "monthly": offset = 30; break; default: continue; } if ((DateTime.Today - petTask.CreationDate).Days >= offset && (DateTime.Now < petTask.Deadline)) { petTask.IsArchived = true; PetTask newPetTask = new PetTask(petTask); db.PetTasks.Add(newPetTask); db.SaveChanges(); } } foreach (LocationTask locationTask in userLocationTasks.ToList()) { int offset; switch (locationTask.Frequency.ToLower()) { case "daily": offset = 1; break; case "weekly": offset = 7; break; case "monthly": offset = 30; break; default: continue; } if ((DateTime.Today - locationTask.CreationDate).Days >= offset && (DateTime.Now < locationTask.Deadline)) { locationTask.IsArchived = true; LocationTask newLocationTask = new LocationTask(locationTask); db.LocationTasks.Add(newLocationTask); db.SaveChanges(); } } }