public ActionResult DeleteConfirmed(int id) { SprintActivities sprintActivities = db.SprintActivities.Find(id); db.SprintActivities.Remove(sprintActivities); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ConfigureNewSprint() { var user = db.Users.Where(a => a.username.ToLower() == User.Identity.Name.ToLower()).FirstOrDefault(); var lastsprint = db.Sprints.Where(a => a.UserId == user.Id).OrderByDescending(a => a.DateFrom).FirstOrDefault(); var newSprint = new Sprint(); newSprint.SprintGoal = lastsprint.SprintGoal; newSprint.DateFrom = DateTime.Now; newSprint.UserId = user.Id; db.Sprints.Add(newSprint); db.SaveChanges(); var sprintActivities = lastsprint.SprintActivities; foreach (SprintActivities sp in sprintActivities.ToList()) { var newsprintA = new SprintActivities(); newsprintA = sp; newsprintA.SprintId = newSprint.Id; db.SprintActivities.Add(newsprintA); db.SaveChanges(); } var sprintGoals = lastsprint.Goals; var goal1 = new Goal(); var goal2 = new Goal(); var goal3 = new Goal(); foreach (Goal g in sprintGoals.ToList()) { var newGoal = new Goal(); newGoal = g; newGoal.SprintId = newSprint.Id; db.Goals.Add(newGoal); db.SaveChanges(); switch (newGoal.CategoryId) { case 1: goal1 = newGoal; break; case 2: goal2 = newGoal; break; case 3: goal3 = newGoal; break; } } ViewBag.goalJoy = goal1.Description; ViewBag.goalPassion = goal2.Description; ViewBag.goalGB = goal3.Description; TempData["newSprint"] = newSprint; TempData.Keep("newSprint"); return(View(newSprint)); }
public ActionResult Edit([Bind(Include = "Id,Specifics,SprintId,ActivityId")] SprintActivities sprintActivities) { if (ModelState.IsValid) { db.Entry(sprintActivities).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SprintId = new SelectList(db.Sprints, "Id", "SprintGoal", sprintActivities.SprintId); ViewBag.ActivityId = new SelectList(db.Activities, "Id", "Name", sprintActivities.ActivityId); return(View(sprintActivities)); }
// GET: SprintActivities/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SprintActivities sprintActivities = db.SprintActivities.Find(id); if (sprintActivities == null) { return(HttpNotFound()); } return(View(sprintActivities)); }
public PartialViewResult UpdateSprint(Act[] activities, string cat) { var newacts = new List <SprintActivities>(); if (activities == null || !activities.Any()) { return(PartialView("ErrorPartial")); } var user = db.Users.Where(a => a.username.ToLower() == User.Identity.Name.ToLower()).FirstOrDefault(); var sprint = db.Sprints.Find(activities[0].sprintId); var activity = db.Activities.Find(activities[0].activityId); if (sprint == null || activity == null || user == null) { return(PartialView("ErrorPartial")); } db.SprintActivities.RemoveRange(db.SprintActivities.Where(a => a.SprintId == sprint.Id && a.Activity.Category.Id == activity.Category.Id).AsEnumerable().ToList()); db.SaveChanges(); foreach (var act in activities) { var newSprintAct = new SprintActivities(); newSprintAct.SprintId = act.sprintId; newSprintAct.ActivityId = act.activityId; newSprintAct.Specifics = act.spec; db.SprintActivities.Add(newSprintAct); newacts.Add(newSprintAct); } if (newacts.Any()) { db.SprintActivities.AddRange(newacts); db.SaveChanges(); } var res = db.SprintActivities.Where(a => a.Activity.Category.Name == "Giving Back" && a.Sprint.Id == sprint.Id).Include(a => a.Activity); if (cat == "joy") { res = db.SprintActivities.Where(a => a.Activity.Category.Name == "Joy" && a.Sprint.Id == sprint.Id).Include(a => a.Activity); return(PartialView("Joy", res.ToList())); } if (cat == "passion") { res = db.SprintActivities.Where(a => a.Activity.Category.Name == "Passion" && a.Sprint.Id == sprint.Id).Include(a => a.Activity); return(PartialView("Passion", res.ToList())); } return(PartialView("GivingBack", res.ToList())); }
// GET: SprintActivities/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SprintActivities sprintActivities = db.SprintActivities.Find(id); if (sprintActivities == null) { return(HttpNotFound()); } ViewBag.SprintId = new SelectList(db.Sprints, "Id", "SprintGoal", sprintActivities.SprintId); ViewBag.ActivityId = new SelectList(db.Activities, "Id", "Name", sprintActivities.ActivityId); return(View(sprintActivities)); }
public ActionResult Create(Sprint newSprint) { try { // TODO: Add insert logic here var user = (db.Users.Where(a => a.username.ToLower() == (User.Identity.Name).ToLower()).FirstOrDefault()); var lastsprint = db.Sprints.Where(a => a.UserId == user.Id).OrderByDescending(a => a.DateFrom).FirstOrDefault(); if (user != null) { newSprint.UserId = user.Id; db.Sprints.Add(newSprint); db.SaveChanges(); var sprintActivities = lastsprint.SprintActivities; foreach (SprintActivities sp in sprintActivities.ToList()) { var newsprintA = new SprintActivities(); newsprintA = sp; newsprintA.SprintId = newSprint.Id; db.SprintActivities.Add(newsprintA); db.SaveChanges(); } var sprintGoals = lastsprint.Goals; var goal1 = new Goal(); var goal2 = new Goal(); var goal3 = new Goal(); foreach (Goal g in sprintGoals.ToList()) { var newGoal = new Goal(); newGoal = g; newGoal.SprintId = newSprint.Id; db.Goals.Add(newGoal); db.SaveChanges(); switch (newGoal.CategoryId) { case 1: goal1 = newGoal; break; case 2: goal2 = newGoal; break; case 3: goal3 = newGoal; break; } } ViewBag.goalJoy = goal1.Description; ViewBag.goalPassion = goal2.Description; ViewBag.goalGB = goal3.Description; TempData["newSprint"] = newSprint; TempData.Keep("newSprint"); return(View("ConfigureNewSprint", newSprint)); } else { ViewBag.ErrorMsg = "There is no user logged in"; return(PartialView("ErrorPartial")); } } catch { ViewBag.ErrorMsg = "There was an unexpected error"; return(PartialView("ErrorPartial")); } }