// GET: Goals/Create public ActionResult Create(int? SelectedEmp) { if (SelectedEmp == null && TempData["SelectedEmp"] != null) { SelectedEmp = Convert.ToInt16(TempData["SelectedEmp"]); } string empName = ""; try { //string employeeID = Request.QueryString["EmployeeID"]; //selectedEmp = Convert.ToInt16(employeeID); empName = (db.tblHOTP_Employees.Where(e => e.EmployeeID == SelectedEmp).Select(e => e.FirstName + " " + e.LastName)).First(); //(db.tblHOTP_Codes.Where(c => c.CodeKey == "YearEnding" && c.Code == year).Select(c => c.CodeId)).First(); } catch { } if (SelectedEmp != null) { tblHOTP_Goals goal = new tblHOTP_Goals(); goal.Rating1 = 0; goal.Rating2 = 0; goal.Rating3 = 0; goal.Rating4 = 0; goal.Rating5 = 0; goal.NumDecimals = 0; goal.Status = "Active"; goal.GoalType = "Individual"; TempData["SelectedEmp"] = SelectedEmp; ViewBag.Pillar = PopulateCodesDDL("Pillar"); ViewBag.YearEnding = PopulateCodesDDL("YearEnding"); ViewBag.ResultsMeasured = PopulateCodesDDL("ResultsMeasured"); ViewBag.BestRating = PopulateCodesDDL("BestRating"); ViewBag.YearEndCalculation = PopulateCodesDDL("YearEndCalculation"); ViewBag.UnitsMeasuredIn = PopulateCodesDDL("UnitsMeasuredIn"); ViewBag.ResultsEntered = PopulateCodesDDL("ResultsEntered"); EvalViewModel evalViewModel = new EvalViewModel { EmployeeID = (int)SelectedEmp, EmployeeName = empName, Goal = goal }; return View(evalViewModel); } return View("index"); }
public ActionResult Edit(EvalViewModel returnedEvalViewModel) { if (ModelState.IsValid) { var goal = db.tblHOTP_Goals.Find(returnedEvalViewModel.Goal.GoalID); if (returnedEvalViewModel.Goal.GoalType == "Individual") { goal.YearEnding = returnedEvalViewModel.Goal.YearEnding; goal.GoalType = returnedEvalViewModel.Goal.GoalType; goal.Pillar = returnedEvalViewModel.Goal.Pillar; goal.GoalName = returnedEvalViewModel.Goal.GoalName; goal.PillarGoalName = returnedEvalViewModel.Goal.PillarGoalName; goal.Goal = returnedEvalViewModel.Goal.Goal; goal.Status = returnedEvalViewModel.Goal.Status; goal.ResultsMeasured = returnedEvalViewModel.Goal.ResultsMeasured; goal.BestRating = returnedEvalViewModel.Goal.BestRating; goal.YearEndCalculation = returnedEvalViewModel.Goal.YearEndCalculation; goal.UnitsMeasuredIn = returnedEvalViewModel.Goal.UnitsMeasuredIn; goal.NumDecimals = returnedEvalViewModel.Goal.NumDecimals; goal.ResultsEntered = returnedEvalViewModel.Goal.ResultsEntered; goal.EnteredBy = returnedEvalViewModel.Goal.EnteredBy; goal.NonEditableByLeader = returnedEvalViewModel.Goal.NonEditableByLeader; goal.Rating1 = returnedEvalViewModel.Goal.Rating1; goal.Rating2 = returnedEvalViewModel.Goal.Rating2; goal.Rating3 = returnedEvalViewModel.Goal.Rating3; goal.Rating4 = returnedEvalViewModel.Goal.Rating4; goal.Rating5 = returnedEvalViewModel.Goal.Rating5; goal.Rating1Suffix = returnedEvalViewModel.Goal.Rating1Suffix; goal.Rating2End = returnedEvalViewModel.Goal.Rating2End; goal.Rating3End = returnedEvalViewModel.Goal.Rating3End; goal.Rating4End = returnedEvalViewModel.Goal.Rating4End; goal.Rating5Suffix = returnedEvalViewModel.Goal.Rating5Suffix; goal.Jan = returnedEvalViewModel.Goal.Jan; goal.Feb = returnedEvalViewModel.Goal.Feb; goal.Mar = returnedEvalViewModel.Goal.Mar; goal.Apr = returnedEvalViewModel.Goal.Apr; goal.May = returnedEvalViewModel.Goal.May; goal.Jun = returnedEvalViewModel.Goal.Jun; goal.Jul = returnedEvalViewModel.Goal.Jul; goal.Aug = returnedEvalViewModel.Goal.Aug; goal.Sep = returnedEvalViewModel.Goal.Sep; goal.Oct = returnedEvalViewModel.Goal.Oct; goal.Nov = returnedEvalViewModel.Goal.Nov; goal.Dec = returnedEvalViewModel.Goal.Dec; } tblHOTP_EmployeeGoals existing_EmployeeGoals = db.tblHOTP_EmployeeGoals.Find(returnedEvalViewModel.EmployeeGoalID); existing_EmployeeGoals.Weight = returnedEvalViewModel.Weight; existing_EmployeeGoals.ItemScore = Math.Round(Convert.ToDecimal(returnedEvalViewModel.Weight * goal.Score) / 100, 2); db.SaveChanges(); return RedirectToAction("Index"); } tblHOTP_EmployeeGoals tblHOTP_EmployeeGoals = db.tblHOTP_EmployeeGoals.Find(returnedEvalViewModel.EmployeeGoalID); tblHOTP_Goals tblHOTP_Goals2 = db.tblHOTP_Goals.Find(tblHOTP_EmployeeGoals.GoalID); tblHOTP_Employees tblHOTP_Employees = db.tblHOTP_Employees.Find(tblHOTP_EmployeeGoals.EmployeeID); EvalViewModel evalViewModel = new EvalViewModel { Goal = tblHOTP_Goals2, EmployeeGoalID = tblHOTP_EmployeeGoals.EmployeeGoalID, EmployeeID = tblHOTP_EmployeeGoals.EmployeeID, EmployeeName = tblHOTP_Employees.LastName, ItemScore = tblHOTP_EmployeeGoals.ItemScore, Weight = tblHOTP_EmployeeGoals.Weight }; ViewBag.Pillar = PopulateCodesDDL("Pillar", tblHOTP_Goals2.Pillar); ViewBag.YearEnding = PopulateCodesDDL("YearEnding", tblHOTP_Goals2.YearEnding); ViewBag.ResultsMeasured = PopulateCodesDDL("ResultsMeasured", tblHOTP_Goals2.ResultsMeasured); ViewBag.BestRating = PopulateCodesDDL("BestRating", tblHOTP_Goals2.BestRating); ViewBag.YearEndCalculation = PopulateCodesDDL("YearEndCalculation", tblHOTP_Goals2.YearEndCalculation); ViewBag.UnitsMeasuredIn = PopulateCodesDDL("UnitsMeasuredIn", tblHOTP_Goals2.UnitsMeasuredIn); ViewBag.ResultsEntered = PopulateCodesDDL("ResultsEntered", tblHOTP_Goals2.ResultsEntered); return View(evalViewModel); }
public EvalViewModel GetEvalViewModel(int? id) { tblHOTP_EmployeeGoals tblHOTP_EmployeeGoals = db.tblHOTP_EmployeeGoals.Find(id); tblHOTP_Goals tblHOTP_Goals = db.tblHOTP_Goals.Find(tblHOTP_EmployeeGoals.GoalID); tblHOTP_Employees tblHOTP_Employees = db.tblHOTP_Employees.Find(tblHOTP_EmployeeGoals.EmployeeID); ViewBag.Pillar = PopulateCodesDDL("Pillar", tblHOTP_Goals.Pillar); ViewBag.YearEnding = PopulateCodesDDL("YearEnding", tblHOTP_Goals.YearEnding); ViewBag.ResultsMeasured = PopulateCodesDDL("ResultsMeasured", tblHOTP_Goals.ResultsMeasured); ViewBag.BestRating = PopulateCodesDDL("BestRating", tblHOTP_Goals.BestRating); ViewBag.YearEndCalculation = PopulateCodesDDL("YearEndCalculation", tblHOTP_Goals.YearEndCalculation); ViewBag.UnitsMeasuredIn = PopulateCodesDDL("UnitsMeasuredIn", tblHOTP_Goals.UnitsMeasuredIn); ViewBag.ResultsEntered = PopulateCodesDDL("ResultsEntered", tblHOTP_Goals.ResultsEntered); EvalViewModel evalViewModel = new EvalViewModel { Goal = tblHOTP_Goals, EmployeeGoalID = tblHOTP_EmployeeGoals.EmployeeGoalID, EmployeeID = tblHOTP_EmployeeGoals.EmployeeID, EmployeeName = tblHOTP_Employees.FirstName + " " + tblHOTP_Employees.LastName, ItemScore = tblHOTP_EmployeeGoals.ItemScore, Weight = tblHOTP_EmployeeGoals.Weight }; if (evalViewModel == null) { return (evalViewModel); } return (evalViewModel); }
public ActionResult Create(EvalViewModel returnedEvalViewModel) { if (ModelState.IsValid) { tblHOTP_Goals newGoal = new tblHOTP_Goals(); //var goal = db.tblHOTP_Goals.Find(returnedEvalViewModel.Goal.GoalID); newGoal.YearEnding = returnedEvalViewModel.Goal.YearEnding; newGoal.GoalType = returnedEvalViewModel.Goal.GoalType; newGoal.Pillar = returnedEvalViewModel.Goal.Pillar; newGoal.GoalName = returnedEvalViewModel.Goal.GoalName; newGoal.PillarGoalName = returnedEvalViewModel.Goal.PillarGoalName; newGoal.Goal = returnedEvalViewModel.Goal.Goal; newGoal.Status = returnedEvalViewModel.Goal.Status; newGoal.ResultsMeasured = returnedEvalViewModel.Goal.ResultsMeasured; newGoal.BestRating = returnedEvalViewModel.Goal.BestRating; newGoal.YearEndCalculation = returnedEvalViewModel.Goal.YearEndCalculation; newGoal.UnitsMeasuredIn = returnedEvalViewModel.Goal.UnitsMeasuredIn; newGoal.NumDecimals = returnedEvalViewModel.Goal.NumDecimals; newGoal.ResultsEntered = returnedEvalViewModel.Goal.ResultsEntered; newGoal.EnteredBy = returnedEvalViewModel.Goal.EnteredBy; newGoal.NonEditableByLeader = returnedEvalViewModel.Goal.NonEditableByLeader; newGoal.Rating1 = returnedEvalViewModel.Goal.Rating1; newGoal.Rating2 = returnedEvalViewModel.Goal.Rating2; newGoal.Rating3 = returnedEvalViewModel.Goal.Rating3; newGoal.Rating4 = returnedEvalViewModel.Goal.Rating4; newGoal.Rating5 = returnedEvalViewModel.Goal.Rating5; newGoal.Rating1Suffix = returnedEvalViewModel.Goal.Rating1Suffix; newGoal.Rating2End = returnedEvalViewModel.Goal.Rating2End; newGoal.Rating3End = returnedEvalViewModel.Goal.Rating3End; newGoal.Rating4End = returnedEvalViewModel.Goal.Rating4End; newGoal.Rating5Suffix = returnedEvalViewModel.Goal.Rating5Suffix; newGoal.Jan = returnedEvalViewModel.Goal.Jan; newGoal.Feb = returnedEvalViewModel.Goal.Feb; newGoal.Mar = returnedEvalViewModel.Goal.Mar; newGoal.Apr = returnedEvalViewModel.Goal.Apr; newGoal.May = returnedEvalViewModel.Goal.May; newGoal.Jun = returnedEvalViewModel.Goal.Jun; newGoal.Jul = returnedEvalViewModel.Goal.Jul; newGoal.Aug = returnedEvalViewModel.Goal.Aug; newGoal.Sep = returnedEvalViewModel.Goal.Sep; newGoal.Oct = returnedEvalViewModel.Goal.Oct; newGoal.Nov = returnedEvalViewModel.Goal.Nov; newGoal.Dec = returnedEvalViewModel.Goal.Dec; db.tblHOTP_Goals.Add(newGoal); db.SaveChanges(); int goalID = newGoal.GoalID; tblHOTP_EmployeeGoals newEmployeeGoal = new tblHOTP_EmployeeGoals(); // db.tblHOTP_EmployeeGoals.Find(returnedEvalViewModel.EmployeeGoalID); newEmployeeGoal.GoalID = goalID; newEmployeeGoal.EmployeeID = returnedEvalViewModel.EmployeeID; newEmployeeGoal.Weight = returnedEvalViewModel.Weight; newEmployeeGoal.ItemScore = 0; // returnedEvalViewModel.ItemScore; db.tblHOTP_EmployeeGoals.Add(newEmployeeGoal); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.Pillar = PopulateCodesDDL("Pillar"); ViewBag.YearEnding = PopulateCodesDDL("YearEnding"); ViewBag.ResultsMeasured = PopulateCodesDDL("ResultsMeasured"); ViewBag.BestRating = PopulateCodesDDL("BestRating"); ViewBag.YearEndCalculation = PopulateCodesDDL("YearEndCalculation"); ViewBag.UnitsMeasuredIn = PopulateCodesDDL("UnitsMeasuredIn"); ViewBag.ResultsEntered = PopulateCodesDDL("ResultsEntered"); return View(returnedEvalViewModel); }