Exemplo n.º 1
0
        protected void AutomarkCalls_Clicked(object sender, DirectEventArgs e)
        {
            List <PhoneCall> userSessionPhoneCalls;
            Dictionary <string, PhoneBookContact> userSessionAddressbook;
            PhoneBookContact addressBookEntry;
            int numberOfRemainingUnmarked;

            //Get the unmarked calls from the user session phonecalls container
            CurrentSession.FetchSessionPhonecallsAndAddressbookData(out userSessionPhoneCalls, out userSessionAddressbook);

            numberOfRemainingUnmarked = userSessionPhoneCalls.Where(phoneCall => string.IsNullOrEmpty(phoneCall.UiCallType)).ToList().Count;

            //If the user has no addressbook contacts, skip the auto marking process
            if (userSessionAddressbook.Keys.Count > 0)
            {
                foreach (var phoneCall in userSessionPhoneCalls.Where(phoneCall => string.IsNullOrEmpty(phoneCall.UiCallType)))
                {
                    if (userSessionAddressbook.Keys.Contains(phoneCall.DestinationNumberUri))
                    {
                        addressBookEntry = (PhoneBookContact)userSessionAddressbook[phoneCall.DestinationNumberUri];

                        if (!string.IsNullOrEmpty(addressBookEntry.Type))
                        {
                            phoneCall.UiCallType      = addressBookEntry.Type;
                            phoneCall.UiUpdatedByUser = sipAccount;
                            phoneCall.UiMarkedOn      = DateTime.Now;

                            Global.DATABASE.PhoneCalls.Update(phoneCall, phoneCall.PhoneCallsTableName);

                            ModelProxy model = MyPhoneCallsGrid.GetStore().Find("SessionIdTime", phoneCall.SessionIdTime.ToString());
                            model.Set(phoneCall);
                            model.Commit();
                        }
                    }
                }
            }

            MyPhoneCallsGrid.GetSelectionModel().DeselectAll();
            MyPhoneCallsGrid.GetStore().LoadPage(1);

            CurrentSession.AssignSessionPhonecallsAndAddressbookData(userSessionPhoneCalls, userSessionAddressbook);
        }
Exemplo n.º 2
0
        protected void AssignAlwaysBusiness(object sender, DirectEventArgs e)
        {
            string                 json = string.Empty;
            RowSelectionModel      selectiomModel;
            JavaScriptSerializer   serializer = new JavaScriptSerializer();
            JsonSerializerSettings settings   = new JsonSerializerSettings();

            //These are used for querying the filtering the submitted phonecalls and their destinations
            PhoneBookContact        phoneBookEntry;
            List <PhoneCall>        submittedPhoneCalls;
            List <PhoneCall>        matchedDestinationCalls;
            List <PhoneBookContact> newOrUpdatedPhoneBookEntries = new List <PhoneBookContact>();

            //These would refer to either the the user's or the delegee's
            List <PhoneCall> userSessionPhoneCalls = new List <PhoneCall>();
            Dictionary <string, PhoneBookContact> userSessionAddressBook = new Dictionary <string, PhoneBookContact>();

            //Get user session and effective sip account
            //CurrentSession = ((UserSession)HttpContext.Current.Session.Contents["UserData"]);
            sipAccount = CurrentSession.GetEffectiveSipAccount();

            //Get user phoneCalls, addressbook, and phoneCallsPerPage;
            //Handle user delegee mode and normal user mode
            CurrentSession.FetchSessionPhonecallsAndAddressbookData(out userSessionPhoneCalls, out userSessionAddressBook);

            //Get the submitted grid data
            json = e.ExtraParams["Values"];
            settings.NullValueHandling = NullValueHandling.Ignore;
            selectiomModel             = this.MyPhoneCallsGrid.GetSelectionModel() as RowSelectionModel;
            submittedPhoneCalls        = serializer.Deserialize <List <PhoneCall> >(json);

            //Start allocating the submitted phone calls
            foreach (PhoneCall phoneCall in submittedPhoneCalls)
            {
                //Create a Phonebook Entry
                phoneBookEntry = new PhoneBookContact();

                //Check if this entry Already exists by either destination number and destination name (in case it's edited)
                bool found = userSessionAddressBook.ContainsKey(phoneCall.DestinationNumberUri) &&
                             (userSessionAddressBook.Values.Select(phoneBookContact => phoneBookContact.Name == phoneCall.PhoneBookName) == null ? false : true);

                if (!found)
                {
                    phoneBookEntry.Name = phoneCall.PhoneBookName ?? string.Empty;
                    phoneBookEntry.DestinationCountry = phoneCall.MarkerCallToCountry;
                    phoneBookEntry.DestinationNumber  = phoneCall.DestinationNumberUri;
                    phoneBookEntry.SipAccount         = sipAccount;
                    phoneBookEntry.Type = "Business";

                    //Add Phonebook entry to Session and to the list which will be written to database
                    if (userSessionAddressBook.ContainsKey(phoneCall.DestinationNumberUri))
                    {
                        userSessionAddressBook[phoneCall.DestinationNumberUri] = phoneBookEntry;
                    }
                    else
                    {
                        userSessionAddressBook.Add(phoneCall.DestinationNumberUri, phoneBookEntry);
                    }

                    newOrUpdatedPhoneBookEntries.Add(phoneBookEntry);
                }

                matchedDestinationCalls = userSessionPhoneCalls.Where(o => o.DestinationNumberUri == phoneCall.DestinationNumberUri && (string.IsNullOrEmpty(o.UiCallType) || o.UiCallType == "Personal")).ToList();

                foreach (PhoneCall matchedDestinationCall in matchedDestinationCalls)
                {
                    matchedDestinationCall.UiCallType      = "Business";
                    matchedDestinationCall.UiMarkedOn      = DateTime.Now;
                    matchedDestinationCall.UiUpdatedByUser = sipAccount;
                    matchedDestinationCall.PhoneBookName   = phoneCall.PhoneBookName ?? string.Empty;

                    Global.DATABASE.PhoneCalls.Update(matchedDestinationCall, matchedDestinationCall.PhoneCallsTableName);
                }
            }

            PhoneCallsAllocationToolsMenu.Hide();

            //Add To Users Addressbook Store
            Global.DATABASE.PhoneBooks.AddOrUpdatePhoneBookEntries(sipAccount, newOrUpdatedPhoneBookEntries);

            //Reassign the user session data
            //Handle the normal user mode and user delegee mode
            CurrentSession.AssignSessionPhonecallsAndAddressbookData(userSessionPhoneCalls: userSessionPhoneCalls, userSessionAddressBook: userSessionAddressBook);

            //Rebind data to the grid store
            RebindDataToStore(userSessionPhoneCalls);
        }