public ActionResult Groups(IEnumerable <string> year, IEnumerable <string> grade, IEnumerable <string> counselor, IEnumerable <string> groupname)
 {
     if (AuthTokens[0] == "demo")
     {
         ViewBag.DemoNextStep = NextStep("!");
         return(View());
     }
     if (year != null && grade != null && counselor != null && groupname != null)
     {
         if (year.Count() == grade.Count() && year.Count() == counselor.Count() && year.Count() == groupname.Count())
         {
             AdminAccountClient aac    = new AdminAccountClient();
             AccessCodeClient   acc    = new AccessCodeClient();
             AdminAccount       admin  = aac.GetByPartitionAndRowKey("admin", AuthTokens[1].ToLower());
             string             school = admin.School;
             for (var i = 0; i < year.Count(); i++)
             {
                 acc.AddNewItem(new AccessCode {
                     RowKey = ShortGuidGenerator.NewGuid(), Code = PinCodeGenerator.NewPin(), Year = year.ElementAt(i), Grade = grade.ElementAt(i), Counselor = counselor.ElementAt(i), GroupName = groupname.ElementAt(i), School = school
                 });
             }
             ViewBag.CurrentYear = AccessCodeClient.CurrentGradYear();
             return(View());
         }
     }
     ViewBag.ErrorMessage = "error";
     ViewBag.CurrentYear  = AccessCodeClient.CurrentGradYear();
     return(View());
 }
 public ActionResult Index(IEnumerable <string> year, IEnumerable <string> grade, IEnumerable <string> groupname)
 {
     if (AuthTokens[0] == "demo")
     {
         return(View());
     }
     if (year != null && grade != null && groupname != null)
     {
         if (year.Count() == grade.Count() && year.Count() == groupname.Count())
         {
             string counselor               = AuthTokens[1].ToLower();
             CounselorAccountClient cac     = new CounselorAccountClient();
             AccessCodeClient       acc     = new AccessCodeClient();
             CounselorAccount       account = cac.GetByPartitionAndRowKey("counselor", counselor);
             string school = account.School;
             for (var i = 0; i < year.Count(); i++)
             {
                 acc.AddNewItem(new AccessCode {
                     RowKey = ShortGuidGenerator.NewGuid(), Code = PinCodeGenerator.NewPin(), Year = year.ElementAt(i), Grade = grade.ElementAt(i), Counselor = counselor, GroupName = groupname.ElementAt(i), School = school
                 });
             }
             return(RedirectToAction("Index"));
         }
     }
     TempData["error"] = true;
     return(RedirectToAction("Index"));
 }
        // private functions ===============================================================================================================================================
        private string getUniquePinCode(string school)
        {
            string pincode = PinCodeGenerator.NewPin();

            AccessCodeClient acc  = new AccessCodeClient();
            AccessCode       code = acc.GetBySchoolAndPinCode(school, pincode);

            //AssessmentGroupClient agc = new AssessmentGroupClient();
            //AssessmentGroup groupEntry = agc.GetByPartitionAndRowKey(school, pincode);
            while (code != null)
            {
                pincode = PinCodeGenerator.NewPin();
                code    = acc.GetBySchoolAndPinCode(school, pincode);
            }
            return(pincode);
        }