示例#1
0
        public HttpResponse ManualTimeEntry(string formatteddate, string location, string agent, string eventtype, int hours, int minutes)
        {
            try
            {
                Response.ContentType = "application/json";

                AgentEventClient aec = new AgentEventClient();

                DateTime eventdate = DateTime.ParseExact(formatteddate, "yyyyMMdd", CultureInfo.InvariantCulture);
                DateTime eventtime = new DateTime(eventdate.Year, eventdate.Month, eventdate.Day, hours, minutes, 0);

                AgentEvent manualevent = new AgentEvent();

                manualevent.PartitionKey = eventtime.ToString("yyyyMM");
                manualevent.RowKey       = ShortGuidGenerator.NewGuid();
                manualevent.EventTime    = eventtime;
                manualevent.Agent        = agent;
                manualevent.EventType    = eventtype;
                manualevent.Location     = location;

                aec.AddNewItem(manualevent);

                Response.Write("{\"result\": \"ok\"}");
                Response.End();
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write(DefaultErrorResponse(ex.Message));
                Response.End();
            }

            return(null);
        }
示例#2
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);
        }
示例#3
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);
        }