Esempio n. 1
0
        async Task <JToken> cdMapStdDrv(String myCurrentEventID)
        {
            List <EventSignup> drveventsignups  = new List <EventSignup>();
            List <EventSignup> stdeventsignups  = new List <EventSignup>();
            cdAllEventSignups  curreventsignups = new cdAllEventSignups();

            cdCallAPI            mycallAPI = new cdCallAPI();
            cdUpdateEventMembers updem     = new cdUpdateEventMembers();
            cdQueryAttr          qryAcct   = new cdQueryAttr();

            qryAcct.ColIndex  = "IndexName";
            qryAcct.IndexName = "EventIDIndex";
            qryAcct.ColName   = "EventID";
            qryAcct.ColValue  = myCurrentEventID;
            int esmaxarray = -1;
            int drvarray   = -1;
            int stdarray   = -1;

            var response = await mycallAPI.cdcallEventMembersGET(qryAcct);

            curreventsignups = JsonConvert.DeserializeObject <cdAllEventSignups>((string)response);

            System.Diagnostics.Debug.WriteLine(" Event Signup payload is " + response);

            try
            {
                foreach (var divsignup in curreventsignups.EventSignup)
                {
                    esmaxarray = esmaxarray + 1;
                    try
                    {
                        if (divsignup.MemberRole.Contains("D") == true)
                        {
                            System.Diagnostics.Debug.WriteLine("Adding Driver " + divsignup.MemberAccountID);
                            drvarray = drvarray + 1;
                            drveventsignups.Add(divsignup);
                            System.Diagnostics.Debug.WriteLine("Added Driver " + divsignup.MemberAccountID);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("Adding Student " + divsignup.MemberAccountID);
                            stdarray = stdarray + 1;
                            stdeventsignups.Add(divsignup);
                            System.Diagnostics.Debug.WriteLine("Added Student " + divsignup.MemberAccountID);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Out of loop " + ex);
                    }
                }

                System.Diagnostics.Debug.WriteLine(" Event signups devided. Max array is " + esmaxarray);
                int stdcounter = 0;

                foreach (var allsignup in drveventsignups)
                {
                    int rcount = Convert.ToInt32(allsignup.RiderCount);
                    try
                    {
                        for (stdcounter = 0; stdcounter <= stdarray && rcount > 0; stdcounter++)
                        {
                            rcount = rcount - 1;
                            //Do student driver allocation
                            DriverAllocation myDriverAlloc = new DriverAllocation();
                            myDriverAlloc.AllocationID = allsignup.MemberAccountID + stdeventsignups[stdcounter].MemberAccountID + myCurrentEventID;
                            myDriverAlloc.EventID      = myCurrentEventID;
                            myDriverAlloc.ClubID       = allsignup.ClubID;
                            myDriverAlloc.DriverID     = allsignup.MemberAccountID;
                            myDriverAlloc.StudentID    = stdeventsignups[stdcounter].MemberAccountID;
                            myDriverAlloc.EventName    = allsignup.EventName;
                            myDriverAlloc.ClubName     = allsignup.ClubName;
                            myDriverAlloc.StudentName  = stdeventsignups[stdcounter].MemberName;
                            myDriverAlloc.DriverName   = allsignup.MemberName;
                            myDriverAlloc.Attr1        = allsignup.Attr1;
                            myDriverAlloc.Attr2        = allsignup.Attr2;
                            myDriverAlloc.Attr3        = allsignup.Attr3;
                            myDriverAlloc.Attr4        = allsignup.Attr4;
                            myDriverAlloc.Attr5        = "None";
                            myDriverAlloc.Attr6        = "None";
                            myDriverAlloc.Attr7        = "None";
                            myDriverAlloc.Attr8        = "None";
                            myDriverAlloc.Attr9        = "None";
                            myDriverAlloc.Attr10       = "None";

                            var daresponse = await mycallAPI.cdcallDriverAllocPUT(myDriverAlloc);

                            if (daresponse.ToString().Contains("ValidationException"))
                            {
                                System.Diagnostics.Debug.WriteLine(" Put API Call failed " + daresponse);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(" Put API Call Successful ");
                            }

                            //Set Student to Allocated
                            updem.EventMemberID = stdeventsignups[stdcounter].EventMemberID;
                            updem.ColumnName    = "AllocationStatus";
                            updem.ColumnValue   = "ALLOCATED";
                            updem.ColumnName1   = "RiderCount";
                            updem.ColumnValue1  = "0";
                            updem.ColumnName2   = "Attr1";
                            updem.ColumnValue2  = "None";
                            updem.ColumnName3   = "Attr2";
                            updem.ColumnValue3  = "None";
                            updem.ColumnName4   = "Attr3";
                            updem.ColumnValue4  = "None";

                            daresponse = await mycallAPI.cdEventMembersPOST(updem);

                            if (daresponse.ToString().Contains("ValidationException"))
                            {
                                System.Diagnostics.Debug.WriteLine(" Post API Call failed " + daresponse);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(" Post API Call Successful  ");
                            }
                        }

                        if (rcount <= 0)
                        {
                            //Set driver to allocated
                            updem.EventMemberID = allsignup.EventMemberID;
                            updem.ColumnName    = "AllocationStatus";
                            updem.ColumnValue   = "ALLOCATED";
                            updem.ColumnName1   = "RiderCount";
                            updem.ColumnValue1  = "0";
                            updem.ColumnName2   = "Attr1";
                            updem.ColumnValue2  = "None";
                            updem.ColumnName3   = "Attr2";
                            updem.ColumnValue3  = "None";
                            updem.ColumnName4   = "Attr3";
                            updem.ColumnValue4  = "None";

                            var dauresponse = await mycallAPI.cdEventMembersPOST(updem);

                            if (dauresponse.ToString().Contains("ValidationException"))
                            {
                                System.Diagnostics.Debug.WriteLine(" Post API Call failed " + dauresponse);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(" Post API Call Successful ");
                            }
                        }
                        else
                        {
                            updem.EventMemberID = allsignup.EventMemberID;
                            updem.ColumnName    = "AllocationStatus";
                            updem.ColumnValue   = "UNALLOCATED";
                            updem.ColumnName1   = "RiderCount";
                            updem.ColumnValue1  = rcount.ToString();
                            updem.ColumnName2   = "Attr1";
                            updem.ColumnValue2  = "None";
                            updem.ColumnName3   = "Attr2";
                            updem.ColumnValue3  = "None";
                            updem.ColumnName4   = "Attr3";
                            updem.ColumnValue4  = "None";

                            var dauresponse = await mycallAPI.cdEventMembersPOST(updem);

                            if (dauresponse.ToString().Contains("ValidationException"))
                            {
                                System.Diagnostics.Debug.WriteLine(" Post API Call failed " + dauresponse);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(" Post API Call Successful ");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("Out of loop " + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("End of Loop " + ex);
            }

            return("success");
        }