public ActionResult Start(FormCollection fc)
        {
            if (MissingEmployeeID)
                return RedirectToLogin();

            if (Request.QueryString["EmployeeID"] != null)
            {
                ViewBag.EmployeeID = Request.QueryString["EmployeeID"];
            }

            if (Request.QueryString["SubscriptionID"] != null)
            {
                ViewBag.SubscriptionID = Request.QueryString["SubscriptionID"];
            }


            NewAssignment newAssignment = new NewAssignment(ViewBag.EmployeeID);

            if (newAssignment.AvailableModules.Count == 0)
            {
                //TODO:  Redirect the user to a page that tells them that there are no available modules to choose from or let the SelectModule page handle it.
                return RedirectToAction("Dashboard", "Admin", new { EmployeeID = ViewBag.EmployeeID, CCApp = ViewBag.CCApp });
            }
            return View("SelectModule", newAssignment);
        }
        public ActionResult SelectStaff(NewAssignment assignment)
        {
            if (MissingEmployeeID)
                return RedirectToLogin();

            if (assignment.SelectedSubscriptionId == null)
            {

                ModelState.AddModelError("SelectSubscriptionToAssign", Literals.SelectSubscriptionToAssign);
            }


            if (assignment.SelectedSubscriptionId != null)
            {

                assignment.SelectedModuleId = assignment.SelectedSubscriptionId;
            }


            if (!ModelState.IsValid)
            {
                return View("SelectModule", assignment);
            }

            if (assignment.Employee.ReportingScope < 2)
            {
                return RedirectToAction("Start", "Access", new { EmployeeID = ViewBag.EmployeeID, CCApp = ViewBag.CCApp });
            }

            //Check if any top level values have been changed and adjust accordingly.
            if (assignment.Zones != null &&
                !assignment.Zones.Any(z => z.Value == assignment.SelectedZoneCode))
            {
                assignment.SelectedZoneCode = null;
                assignment.SelectedDistrictCode = null;
            }
            if (assignment.Districts != null &&
                !assignment.Districts.Any(d => d.Value == assignment.SelectedDistrictCode))
            {
                assignment.SelectedDistrictCode = null;
            }

            //Pre-set values based on the employee's reporting scope and assigned area.
            if (assignment.Employee != null &&
                assignment.Employee.Area != null)
            {
                if (assignment.Employee.ReportingScope < 5 &&
                    assignment.Employee.Area.RegionID.HasValue)
                {
                    assignment.SelectedRegionId = assignment.Employee.Area.RegionID.Value.ToString();
                    assignment.RegionSelectionDisabled = true;
                }

                if (assignment.Employee.ReportingScope < 4 &&
                    assignment.Employee.Area.RegionID.HasValue &&
                    !string.IsNullOrEmpty(assignment.Employee.Area.ZoneCode))
                {
                    assignment.SelectedRegionId = assignment.Employee.Area.RegionID.Value.ToString();
                    assignment.SelectedZoneCode = assignment.Employee.Area.ZoneCode;
                    assignment.ZoneSelectionDisabled = true;
                }
                else if (assignment.Employee.ReportingScope < 4)
                {
                    RedirectToAction("Start", "Access", new { EmployeeID = ViewBag.EmployeeID, CCApp = ViewBag.CCApp });
                }

                if (assignment.Employee.ReportingScope < 3 &&
                    assignment.Employee.Area.RegionID.HasValue &&
                    !string.IsNullOrEmpty(assignment.Employee.Area.ZoneCode) &&
                    !string.IsNullOrEmpty(assignment.Employee.Area.DistrictCode))
                {
                    assignment.SelectedZoneCode = assignment.Employee.Area.ZoneCode;
                    assignment.SelectedDistrictCode = assignment.Employee.Area.DistrictCode;
                }
                else if (assignment.Employee.ReportingScope < 3)
                {
                    return RedirectToAction("Start", "Access", new { EmployeeID = ViewBag.EmployeeID, CCApp = ViewBag.CCApp });
                }
            }


            assignment.StartDate = DateTime.Now;
            if (assignment.SelectedDistrictCode != null)
            {
                if (assignment.DueDate == DateTime.MinValue)
                {
                    assignment.DueDate = assignment.DefaultDueDate;
                }
                return View(assignment);
            }
            else
            {
                return View("SelectDistrict", assignment);
            }
        }
        public ActionResult CreateCategoryAssignment(NewAssignment assignment)
        {
            if (assignment.SelectedCategoryItems.Count <= 0)
            {
                ModelState.AddModelError("SelectedCategoryItems", Resources.Literals.ModuleGroupAssignmentIsRequired);
            }

            if (!ModelState.IsValid)
            {
                return View("SelectCategory", assignment);
            }

            try
            {
                ViewBag.Count = assignment.CreateCategoryAssignments();
                return View("Success", assignment);
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "We're sorry, but we were unable to complete the assignment at this time.  Please try again or contact the system administrator.");
                return View("SelectCategory", assignment);
            }
        }
        public ActionResult CreateAssignment(NewAssignment assignment)
        {
            if (MissingEmployeeID)
                return RedirectToLogin();

            if (assignment.SelectedSubordinates.Count <= 0)
            {
                ModelState.AddModelError("SelectedSubordinates", Resources.Literals.SubscriptionIsRequired);
            }

            if (!ModelState.IsValid)
            {
                return View("SelectStaff", assignment);
            }

            try
            {
                ViewBag.Count = assignment.CreateAssignments();
                return View("Success", assignment);
            }
            catch (Exception)
            {
                ModelState.AddModelError("", "We're sorry, but we were unable to complete the assignment at this time.  Please try again or contact the system administrator.");
                return View("SelectStaff", assignment);
            }
        }
 public ActionResult OnSelectedZoneChanged(NewAssignment assignment)
 {
     return PartialView("_SelectDistrict", assignment);
 }
 public ActionResult OnSelectedRegionChanged(NewAssignment assignment)
 {
     return PartialView("_SelectZone", assignment);
 }
        public ActionResult SelectCategory(NewAssignment assignment)
        {
            if (!Context.EmployeeCategoryEnabled)
            {
                return RedirectToAction("Start");
            }

            if (assignment.SelectedModuleId == null)
            {
                ModelState.AddModelError("SelectedModuleId", Literals.ModuleSelectionRequired);
            }

            if (!ModelState.IsValid)
            {
                return View("SelectModule", assignment);
            }

            if (assignment.DueDate == DateTime.MinValue)
            {
                assignment.DueDate = assignment.DefaultDueDate;
            }
            return View(assignment);
        }
        public ActionResult SelectGroup(NewAssignment assignment)
        {
            if (MissingEmployeeID)
                return RedirectToLogin();

            if (assignment.SelectedSubscriptionId == null)
            {
                ModelState.AddModelError("SelectedSubscriptionId", Literals.SelectSubscriptionToAssign);
            }

            if (!ModelState.IsValid)
            {
                return View("SelectModule", assignment);
            }


  
            if (assignment.DueDate == DateTime.MinValue)
            {
                assignment.DueDate = assignment.DefaultDueDate;
            }
            return View(assignment);
        }