/// <summary>
        /// Sets the Note to DB
        /// </summary>
        public void Set(int LeadID, int CaseID)
        {
            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");
            AquariumEventManagement.EventResult result;

            if(SelectedNoteType == 0)
            {
                //Add Normal Note
                result = theEventSDKClient.AddNormalNote(sd,LeadID,CaseID,SelectedNoteType,NoteDescription,NoteDescription,NoteApplytoAll);
            }
            else
            {
                //Add Alert Note
                result = theEventSDKClient.AddStickyNote(sd,LeadID, CaseID,SelectedNoteType,NoteDescription,NoteDescription,NoteApplytoAll);
            }

            if (result.ResultInfo.ReturnCode == AquariumEventManagement.BasicCode.OK)
            {

            }
            else if (result.ResultInfo.ReturnCode == AquariumEventManagement.BasicCode.Failed)
            {
                throw new System.ApplicationException("Error ID:" + result.ResultInfo.Errors[0].ResultCodeID + ", Description:" + result.ResultInfo.Errors[0].Description);
            }
        }
        //Overload 1 - takes DiaryEvent
        public void GetLoadedNextEventsForLeadEvent(DiaryEvent aDiaryEvent)
        {
            //
            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            AquariumEventManagement.EventResult comeOn = theEventSDKClient.GetEventType(sd, 64897, 975501, 1038481);
        }
        public List<DiaryEvent> GetNextEventsForAllowedEventsThreads(DiaryEvent aDiaryEvent)
        {
            List<DiaryEvent> theNextEvents = new List<DiaryEvent>();

            //get all threads for this event
            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            AquariumEventManagement.EventResult nextEventResults = theEventSDKClient.GetNextEvents(sd, aDiaryEvent.LeadEventID, aDiaryEvent.EventThread);

            //convert to Diary Event method

            return theNextEvents;
        }
        /// <summary>
        /// Method to get EventHistory List from SDK using the CaseID
        /// </summary>
        /// <param name="ID">CaseID</param>
        public void GetEventHistory(int ID)
        {
            IR_Dashboard_SDK.AquariumEventManagement.EventManagementSoapClient eventSdk = new AquariumEventManagement.EventManagementSoapClient();

            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            AquariumEventManagement.EventResult result = eventSdk.GetEventHistory(sd, ID, false);
            if (result.ResultInfo.ReturnCode == AquariumEventManagement.BasicCode.OK)
            {
                LeadEventHistory = result.LeadEventHistory.ToList();
            }
            else if (result.ResultInfo.ReturnCode == AquariumEventManagement.BasicCode.Failed)
            {
                throw new System.ApplicationException("Error ID:" + result.ResultInfo.Errors[0].ResultCodeID + ", Description:" + result.ResultInfo.Errors[0].Description);
            }
        }
        /// <summary>
        /// Get All Note Types from DB and add to our Object
        /// </summary>
        /// <returns>List of DiaryNoteType</returns>
        public static List<DiaryNoteType> GetNoteTypes()
        {
            List<DiaryNoteType> theNotesToReturn = new List<DiaryNoteType>();
            //   string[] EventAndThread;

            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            //get all OOP Events
            AquariumEventManagement.EventResult result = theEventSDKClient.GetNoteTypes(sd);

            //map it and add it
            for (int i = 0; i < result.NoteTypes.Count(); i++)
            {
                theNotesToReturn.Add(new DiaryNoteType
                {
                    DiaryNoteTypeID = result.NoteTypes.ElementAt(i).NoteTypeID,
                    DiaryNoteTypeName = result.NoteTypes.ElementAt(i).NoteTypeName
                });
            }

            //return it
            return theNotesToReturn;
        }
        //create a top level SDK object can use for everything
        //
        // GET: /TestEvent/
        public ActionResult Main()
        {
            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            Customer testCustomer = new Customer();
            int CustomerID = testCustomer.GetCustomerID(975033);

            Case testCase = new Case();
            int TestCaseID = testCase.GetCaseID(CustomerID);
            DiaryEvent theTopLevelEvent_AvailableThreadsContainer = new DiaryEvent();
            theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads = new List<DiaryEvent>();

            AquariumEventManagement.EventResult AllowedCaseThreads = theEventSDKClient.GetAllowedCaseEventThreads(sd, TestCaseID);
            //get all the in process

            if(AllowedCaseThreads.AllowedCaseEventThreads.Count() >= 1)
            {

                //add a default event that does f**k all for the drop down list

                string[] EventAndThread;

                for (int i = 0; i < AllowedCaseThreads.AllowedCaseEventThreads.Count(); i++)
                {

                    //split the array
                    EventAndThread = AllowedCaseThreads.AllowedCaseEventThreads[i].Value.Split('|');
                    //get erm....the LeadEventID
                    AquariumEventManagement.EventResult theLeadEvent = theEventSDKClient.GetLeadEvent(sd, Convert.ToInt32(EventAndThread[0]));

                    theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.Add(new DiaryEvent
                    {
                           EventName = AllowedCaseThreads.AllowedCaseEventThreads[i].Text,
                           LeadEventID = Convert.ToInt32(EventAndThread[0]),
                           EventThread = Convert.ToInt32(EventAndThread[1]),
                           LeadEventIDThreadComposite = AllowedCaseThreads.AllowedCaseEventThreads[i].Value,
                           ParentSDKResult = AllowedCaseThreads,
                           EventTypeID = Convert.ToInt32(theLeadEvent.LeadEvent.EventTypeID),
                           WhenCreated = theLeadEvent.LeadEvent.WhenCreated,
                           WhoCreated = Convert.ToInt32(theLeadEvent.LeadEvent.WhoCreated),
                           LeadDocumentID = Convert.ToInt32(theLeadEvent.LeadEvent.LeadDocumentID)

                    });

                }

                //NOW WE WANT TO GET THE NEXT EVENTS, MAYBE?? OR ARE THESE THE NEXT EVENTS??
                for (int i = 0; i < theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.Count(); i++)
                {
                    List<DiaryEvent> NextEvents = GetNextEventsForAllowedEventsThreads(theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.ElementAt(i));

                    theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.ElementAt(0).theNextEventsAfterThisEvent = NextEvents;
                }

                //NOW GET THE LOADED EVENTS, INCLUDING MANDATORY AND HELPER FIELDS
                //GetLoadedNextEventsForLeadEvent(theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.ElementAt(0).theNextEventsAfterThisEvent.ElementAt(0));

                //get the oop events

                //get the note types

                List<DiaryEvent> oopEvents = DiaryEvent.GetOOPEvents(261);

                //List<DiaryEvent> noteTypes = DiaryEvent.GetNoteTypes();

            List<DiaryDetailField> aListOfFields = new List<DiaryDetailField>();
            //aListOfFields = DiaryEvent.GetMandatoryFieldsForLeadEvent(65685, 975033, 1038013);

            }

            return View();
        }
        /// <summary>
        /// to get the next 'In Process' events in the system
        /// </summary>
        /// <param name="CaseID">CaseID<CaseID/param>
        /// <returns>AquariumEventManagement.EventResult</returns>
        public AquariumEventManagement.EventResult GetAllowedThreads(int CaseID)
        {
            try
            {

                AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();

                AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

                //this brings us back all available Events
                AquariumEventManagement.EventResult result = theEventSDKClient.GetAllowedCaseEventThreads(sd, CaseID);

                //initalist the event list if it hasn't been already
                if (this.theAvailableEventsAndTheirThreads == null)
                {
                    this.theAvailableEventsAndTheirThreads = new List<DiaryEvent>();

                }

                //if results returns ok then assign, else throw
                if (result.ResultInfo.ReturnCode == AquariumEventManagement.BasicCode.OK)
                {
                    //if there are next events
                    if (result.AllowedCaseEventThreads.Count() >= 1)
                    {
                        for (var i = 0; i < result.AllowedCaseEventThreads.Count(); i++)
                        {
                            //add to 'next events'
                            this.theAvailableEventsAndTheirThreads.Add(new DiaryEvent
                            {
                                //parse all Aq event info into our info
                                //EventTypeID = result.AllowedCaseEventThreads.ElementAt(i)

                            });

                        }

                    }

                }

                return result;
            }

            //if there's
            catch (Exception ex)
            { throw ex; }
        }
        /// <summary>
        /// To get all OOP events in the system
        /// </summary>
        /// <param name="LeadTypeID">LeadTypeID</param>
        /// <returns>AquariumEventManagement.EventResult</returns>
        public static List<DiaryEvent> GetOOPEvents(int LeadTypeID)
        {
            List<DiaryEvent> theEventsToReturn = new List<DiaryEvent>();
            //   string[] EventAndThread;

            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            //get all OOP Events
            AquariumEventManagement.EventResult result = theEventSDKClient.GetOutOfProcessEvents(sd, LeadTypeID);

            theEventsToReturn.Add(new DiaryEvent
            {
                EventName = "Please select an OOP Event",
                EventThread = 0,
                ParentSDKResult = null,
                EventTypeID = 10000,
                NextEvent_ChoicesInThread = 0,
                NextEvent_ChoicesDescription = ""

            });

            //map it and add it
            for (int i = 0; i < result.NextEvents.Count(); i++)
            {

                //AquariumEventManagement.EventResult theLeadEvent = theEventSDKClient.GetLeadEvent(sd, Convert.ToInt32(EventAndThread[0]));

                theEventsToReturn.Add(new DiaryEvent
                {
                    EventName = result.NextEvents.ElementAt(i).NextEventTypeName,

                    EventThread = result.NextEvents.ElementAt(i).ThreadNumber,
                    NextEvent_ChoicesInThread = result.NextEvents.ElementAt(i).ChoicesInThread,
                    ParentSDKResult = result,
                    EventTypeID = Convert.ToInt32(result.NextEvents.ElementAt(i).NextEventTypeID),

                    NextEvent_ChoicesDescription = result.NextEvents.ElementAt(i).ChoiceDescription

                });

            }

            //return it
            return theEventsToReturn;
        }
        /*
        //to create an OOP
        public DiaryEvent()
        {

        }

        //to Create an 'EventType'
        public DiaryEvent()
        {

        }
         * */
        public static List<DiaryEvent> EventsToDisplayToTheUser(int CustomerID)
        {
            //list to return
            List<DiaryEvent> EventToReturnToTheUser = new List<DiaryEvent>();

            AquariumEventManagement.EventManagementSoapClient theEventSDKClient = new AquariumEventManagement.EventManagementSoapClient();
            AquariumEventManagement.SessionDetails sd = SDKHelper.GetSessionDetails<AquariumEventManagement.SessionDetails>("User");

            Case testCase = new Case();
            int TestCaseID = testCase.GetCaseID(CustomerID);
            DiaryEvent theTopLevelEvent_AvailableThreadsContainer = new DiaryEvent();
            theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads = new List<DiaryEvent>();

            AquariumEventManagement.EventResult AllowedCaseThreads = theEventSDKClient.GetAllowedCaseEventThreads(sd, TestCaseID);
            //get all the in process

            if (AllowedCaseThreads.AllowedCaseEventThreads.Count() >= 1)
            {

                string[] EventAndThread;

                for (int i = 0; i < AllowedCaseThreads.AllowedCaseEventThreads.Count(); i++)
                {

                    //split the array
                    EventAndThread = AllowedCaseThreads.AllowedCaseEventThreads[i].Value.Split('|');
                    //get erm....the LeadEventID
                    //AquariumEventManagement.EventResult theLeadEvent = theEventSDKClient.GetLeadEvent(sd, Convert.ToInt32(EventAndThread[0]));
                    AquariumEventManagement.EventResult theLeadEvent = theEventSDKClient.GetNextEvents(sd, Convert.ToInt32(EventAndThread[0]), Convert.ToInt32(EventAndThread[1]));

                    theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.Add(new DiaryEvent
                    {
                        EventName = AllowedCaseThreads.AllowedCaseEventThreads[i].Text,
                        LeadEventID = Convert.ToInt32(EventAndThread[0]),
                        EventThread = Convert.ToInt32(EventAndThread[1]),
                        LeadEventIDThreadComposite = AllowedCaseThreads.AllowedCaseEventThreads[i].Value,
                        ParentSDKResult = AllowedCaseThreads,
                        EventTypeID = Convert.ToInt32(theLeadEvent.NextEvents[0].NextEventTypeID)
                    });

                }

                // return these to the user a list of Diary events

                }

            EventToReturnToTheUser.Add(new DiaryEvent
            {

                EventTypeID = 10000,
                EventName = "Please select an Event"
                          });

            for (var i = 0; i < theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.Count(); i++)
               {

                    EventToReturnToTheUser.Add(theTopLevelEvent_AvailableThreadsContainer.theAvailableEventsAndTheirThreads.ElementAt(i));

              }

                return EventToReturnToTheUser;
        }