Ejemplo n.º 1
0
        // GET: Goals/AddOrg
        public ActionResult AddOrg(int? SelectedEmp, string YearEnding)
        {
            if (SelectedEmp == null && TempData["SelectedEmp"] != null)
            {
                SelectedEmp = Convert.ToInt16(TempData["SelectedEmp"]);
            }
            if (YearEnding == null && TempData["YearEnding"] != null)
            {
                YearEnding = TempData["YearEnding"].ToString();
            }
            TempData["YearEnding"] = YearEnding;

            string empName = (db.tblHOTP_Employees.Where(e => e.EmployeeID == SelectedEmp).Select(e => e.FirstName + " " + e.LastName)).First();
            var emps =
              db.tblHOTP_Employees
                .Where(s => s.Evaluations)
                .OrderBy(s => s.LastName)
                .ToList()
                .Select(s => new
                {
                    EmployeeId = s.EmployeeID,
                    FullName = string.Format("{0}, {1}", s.LastName, s.FirstName)
                });
            ViewBag.SelectedEmp = new SelectList(emps, "EmployeeID", "FullName", SelectedEmp);
            if (SelectedEmp != null)
            {
                TempData["SelectedEmp"] = SelectedEmp;
                AddOrg addOrg = new AddOrg();
                addOrg.EmpName = empName;
                addOrg.Weight = 0;
                addOrg.EmployeeID = Convert.ToInt16(SelectedEmp);
                var subselect = (from eg in db.tblHOTP_EmployeeGoals where eg.EmployeeID== SelectedEmp select eg.GoalID).ToList();
                var goalQuery = db.tblHOTP_Goals
                                .Where(g => g.GoalType == "Organizational" && g.YearEnding == YearEnding && !subselect.Contains(g.GoalID))
                                .OrderBy(g => g.YearEnding)
                                .Select(g => new
                                {
                                    GoalId = g.GoalID,
                                    GoalDisplayText = g.YearEnding + " " + g.PillarGoalName
                                });
                ViewBag.GoalID = new SelectList(goalQuery, "GoalID", "GoalDisplayText");
                return View(addOrg);
            }
            return View("index");
        }
Ejemplo n.º 2
0
        public ActionResult AddOrg(AddOrg addOrg)
        {
            if (ModelState.IsValid)
            {
                if (addOrg.GoalID > 0)
                {
                    tblHOTP_EmployeeGoals newEmployeeGoals = new tblHOTP_EmployeeGoals();
                    newEmployeeGoals.GoalID = addOrg.GoalID;
                    newEmployeeGoals.EmployeeID = addOrg.EmployeeID;
                    newEmployeeGoals.Weight = addOrg.Weight;
                    int? score = (db.tblHOTP_Goals.Where(g => g.GoalID == addOrg.GoalID).Select(g => g.Score)).First();
                    decimal rounded = decimal.Round(Convert.ToDecimal(newEmployeeGoals.Weight) * Convert.ToDecimal(score) / 100, 2);
                    newEmployeeGoals.ItemScore = rounded;
                    db.tblHOTP_EmployeeGoals.Add(newEmployeeGoals);
                    db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            return View(addOrg);
        }