Esempio n. 1
0
        public HttpResponse checkagentlogoncode(string location, string agent, string code)
        {
            try
            {
                Response.ContentType = "application/json";

                if (location == null || location == "")
                {
                    throw new Exception("Invalid location");
                }

                AgentClient ac = new AgentClient();
                Agent       a  = ac.GetAll().Execute().Where(x => x.LoginName == agent).SingleOrDefault();

                if (a == null)
                {
                    throw new Exception("Invalid agent ID or code");
                }

                if (a.LoginCode == code)
                {
                    a.CurrentLocation = location;
                    a.CurrentStatus   = "loggedon";
                    ac.Update(a);

                    AgentEventClient aec = new AgentEventClient();
                    aec.AddNewItem(new AgentEvent(agent, "logon", location));

#if DEBUG
#else
                    Telephony t = new Telephony();
                    //Send to Rick
                    //t.SendSMS("+19174340659", agent + " logged on at " + location);

                    //Send to Mike
                    t.SendSMS("+19179578770", agent + " logged on at " + location);
#endif

                    Response.Write("{\"result\": \"ok\", \"logonname\": \"" + a.LoginName + "\", \"logoncolor\": \"" + a.LoginColor + "\"}");
                    Response.End();
                }
                else
                {
                    throw new Exception("Invalid agent ID or code");
                }
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write(DefaultErrorResponse(ex.Message));
                Response.End();
            }

            return(null);
        }
Esempio n. 2
0
        public HttpResponse logoff(string location, string agent, string code)
        {
            try
            {
                Response.ContentType = "application/json";

                AgentClient ac = new AgentClient();
                Agent       a  = ac.GetAll().Execute().Where(x => x.LoginName == agent).SingleOrDefault();

                if (a == null)
                {
                    throw new Exception("Invalid agent ID or code");
                }

                if (a.LoginCode == code)
                {
                    DateTime nowTime = EasternTimeConverter.Convert(DateTime.UtcNow);


                    AgentEventClient aec       = new AgentEventClient();
                    AgentEvent       lastEvent = aec.GetAll().Execute().Where(x => x.Agent == agent).OrderByDescending(x => x.EventTime).FirstOrDefault();

                    string hoursworked = "No prior logon.";
                    string production  = "No results.";
                    if (lastEvent.EventType == "logon")
                    {
                        long     elapsedTicks = nowTime.Ticks - lastEvent.EventTime.Ticks;
                        TimeSpan ts           = new TimeSpan(elapsedTicks);
                        hoursworked = ts.Hours.ToString() + "h : " + ts.Minutes + "m logged.";

                        //Count how many leads
                        List <SkillCowRequestSubmission> allrecords = new List <SkillCowRequestSubmission>();

                        DateTime cursordate = lastEvent.EventTime;

                        SkillCowRequestSubmissionClient rsc = new SkillCowRequestSubmissionClient();
                        while (cursordate <= nowTime)
                        {
                            CloudTableQuery <SkillCowRequestSubmission> query = rsc.GetAll(cursordate.ToString("yyyyMMdd"));
                            allrecords.AddRange(query.Execute().Where(x => x.UtmCampaign == location && x.UtmContent == agent).OrderBy(x => x.Timestamp));
                            cursordate = cursordate.AddDays(1);
                        }

                        //tally up
                        int totalschoolleads = 0;
                        int totalindeedjobs  = 0;
                        int totalcourses     = 0;
                        foreach (SkillCowRequestSubmission x in allrecords)
                        {
                            switch (x.SourceForm)
                            {
                            case "schoolform":
                                totalschoolleads++;
                                break;

                            case "indeedjob":
                                totalindeedjobs++;
                                break;

                            case "udemycourse":
                                totalcourses++;
                                break;
                            }
                        }
                        if (totalschoolleads + totalindeedjobs + totalcourses > 0)
                        {
                            production  = "\n";
                            production += totalschoolleads + " school leads\n";
                            production += totalindeedjobs + " indeed jobs\n";
                            production += totalcourses + " udemy courses";
                        }
                    }

                    //Log event
                    aec.AddNewItem(new AgentEvent(agent, "logoff", location));

                    a.CurrentLocation = "";
                    a.CurrentStatus   = "loggedoff";
                    ac.Update(a);

#if DEBUG
#else
                    Telephony t = new Telephony();

                    string message = agent + " logged OFF at " + location + "\n" + hoursworked + "\n" + production;
                    //Send to Rick
                    //t.SendSMS("+19174340659", message);

                    t.SendSMS("+19179578770", message);
#endif

                    Response.Write("{\"result\": \"ok\", \"logonname\": \"" + a.LoginName + "\"}");
                    Response.End();
                }
                else
                {
                    throw new Exception("Invalid agent ID or code");
                }
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write(DefaultErrorResponse(ex.Message));
                Response.End();
            }

            return(null);
        }