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); }
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); }
public static List <AgentDailyActivity> Create(List <Agent> agentprofiles, DateTime startdate, DateTime enddate, string agent) { AgentEventClient aec = new AgentEventClient(); List <AgentEvent> allrecords = new List <AgentEvent>(); DateTime cursordate = startdate; if (agent != null && agent != "") { while (cursordate <= enddate) { allrecords.AddRange(aec.GetAllByPartition(cursordate.ToString("yyyyMM")).Where(x => x.EventTime.ToString("yyyyMMdd") == cursordate.ToString("yyyyMMdd") && x.Agent == agent).OrderBy(x => x.Timestamp)); cursordate = cursordate.AddDays(1); } } else { while (cursordate <= enddate) { allrecords.AddRange(aec.GetAllByPartition(cursordate.ToString("yyyyMM")).Where(x => x.EventTime.ToString("yyyyMMdd") == cursordate.ToString("yyyyMMdd")).OrderBy(x => x.Timestamp)); cursordate = cursordate.AddDays(1); } } List <AgentDailyActivity> retlist = new List <AgentDailyActivity>(); List <AgentLocationDate> alds = GetAgentDateList(allrecords); DateTime currenttime = EasternTimeConverter.Convert(DateTime.UtcNow); foreach (AgentLocationDate ald in alds) { try { if (ald.Agent == "victorr") { Console.Write(""); } AgentEvent logonevent = GetLogonEvent(allrecords, ald); AgentEvent logoffevent = GetLogoffEvent(allrecords, ald); double hoursworked = 0; Agent a = agentprofiles.SingleOrDefault(x => x.LoginName == ald.Agent.Replace("cindy", "sydneyc")); bool currentlyloggedon = false; if (a.CurrentStatus == "loggedon" && logonevent != null && logonevent.EventTime.ToString("yyyyMMdd") == currenttime.ToString("yyyyMMdd")) { currentlyloggedon = true; } if (logonevent != null && logoffevent != null) { if (currentlyloggedon) { //relogged on hoursworked = (double)(currenttime.Ticks - logonevent.EventTime.Ticks) / TimeSpan.TicksPerHour; } else { hoursworked = (double)(logoffevent.EventTime.Ticks - logonevent.EventTime.Ticks) / TimeSpan.TicksPerHour; } } else if (logonevent != null && logoffevent == null && logonevent.EventTime.ToString("yyyyMMdd") == currenttime.ToString("yyyyMMdd")) { hoursworked = (double)(currenttime.Ticks - logonevent.EventTime.Ticks) / TimeSpan.TicksPerHour; } retlist.Add(new AgentDailyActivity { FormattedDate = ald.Date, Agent = ald.Agent, Location = ald.Location, LogonTime = logonevent != null ? logonevent.EventTime.ToString("HH:mm") : "", LogonHour = logonevent != null ? int.Parse(logonevent.EventTime.ToString("HH")) : -1, LogoffTime = logoffevent != null && !currentlyloggedon ? logoffevent.EventTime.ToString("HH:mm") : "", LogoffHour = logoffevent != null && !currentlyloggedon ? int.Parse(logoffevent.EventTime.ToString("HH")) : -1, Hours = hoursworked }); } catch (Exception ex) { Console.Write(ex.Message); } } return(retlist); }
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); }