public void PopulatePlan(int? id) { var plans = from p in db.tblHOTP_Plan90 where p.EmployeeGoalID == id select p.PlanID; if (plans.Count() > 0) return; for (int quarter = 1; quarter < 5; quarter++) { tblHOTP_Plan90 newPlan = new tblHOTP_Plan90(); newPlan.EmployeeGoalID = Convert.ToInt16(id); newPlan.Quarter = quarter; newPlan.Goal = ""; db.tblHOTP_Plan90.Add(newPlan); db.SaveChanges(); int planID = newPlan.PlanID; tblHOTP_ActionSteps actionStep = new tblHOTP_ActionSteps(); actionStep.PlanID = planID; actionStep.ActionStep = ""; actionStep.Result = ""; actionStep.Status = ""; db.tblHOTP_ActionSteps.Add(actionStep); db.SaveChanges(); } }
public ActionResult All(List<GoalFull> GoalFull) { if (ModelState.IsValid) { foreach (GoalFull goalFull in GoalFull) { foreach (Plan90Full plan90 in goalFull.Plans) { tblHOTP_Plan90 existingPlan = db.tblHOTP_Plan90.Find(plan90.Plan.PlanID); existingPlan.Goal = plan90.Plan.Goal; if (plan90.ActionSteps != null) { foreach (tblHOTP_ActionSteps actionStep in plan90.ActionSteps) { if (actionStep.ActionID != 99999 && actionStep.Status == "Remove") { tblHOTP_ActionSteps existingAction = db.tblHOTP_ActionSteps.Find(actionStep.ActionID); db.tblHOTP_ActionSteps.Remove(existingAction); } else if (actionStep.ActionID == 99999 && actionStep.Status != "Remove") { tblHOTP_ActionSteps newActionStep = new tblHOTP_ActionSteps(); newActionStep.PlanID = plan90.Plan.PlanID; newActionStep.ActionStep = actionStep.ActionStep; newActionStep.Result = actionStep.Result; newActionStep.Status = actionStep.Status; db.tblHOTP_ActionSteps.Add(newActionStep); } else { if (actionStep.ActionID != 99999) { tblHOTP_ActionSteps existingAction = db.tblHOTP_ActionSteps.Find(actionStep.ActionID); existingAction.Result = actionStep.Result; existingAction.ActionStep = actionStep.ActionStep; existingAction.Status = actionStep.Status; } } } } } } db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.PlanStatus = PopulateCodesDDL("PlanStatus"); return View(GoalFull); }
public ActionResult Copy1Quarter() { //foreach (string _formData in formCollection) //{ // ViewData[_formData] = formCollection[_formData]; //} string EmployeeGoalID = Request["EmployeeGoalID"].ToString(); string copyFrom = Request["copyFrom"].ToString(); string copyTo = Request["copyTo"].ToString(); int copyFromInt = Convert.ToInt16(copyFrom); int copyToInt = Convert.ToInt16(copyTo); int employeeGoalID = Convert.ToInt16(EmployeeGoalID); for (int g = 0; g < 5; g++) { tblHOTP_Plan90 fromPlan = db.tblHOTP_Plan90.Where(p => p.EmployeeGoalID == employeeGoalID && p.Quarter == copyFromInt).First(); tblHOTP_Plan90 toPlan = db.tblHOTP_Plan90.Where(p => p.EmployeeGoalID == employeeGoalID && p.Quarter == copyToInt).First(); toPlan.Goal = fromPlan.Goal; var toSteps = from step in db.tblHOTP_ActionSteps where step.PlanID == toPlan.PlanID select step; foreach (tblHOTP_ActionSteps step in toSteps) { db.tblHOTP_ActionSteps.Remove(step); } var fromSteps = from step in db.tblHOTP_ActionSteps where step.PlanID == fromPlan.PlanID select step; foreach (tblHOTP_ActionSteps step in fromSteps) { tblHOTP_ActionSteps newActionStep = new tblHOTP_ActionSteps(); newActionStep.PlanID = toPlan.PlanID; newActionStep.ActionStep = step.ActionStep; newActionStep.Result = step.Result; newActionStep.Status = step.Status; db.tblHOTP_ActionSteps.Add(newActionStep); } db.SaveChanges(); } return RedirectToAction("Index", "Plan90"); }