public string FixDemoSource(string startdate) { int cnt = 0; SkillCowRequestSubmissionClient rsc = new SkillCowRequestSubmissionClient(); DateTime cursordate = DateTime.ParseExact(startdate, "yyyyMMdd", CultureInfo.InvariantCulture); List <SkillCowRequestSubmission> submissions = new List <SkillCowRequestSubmission>(); while (cursordate < DateTime.UtcNow.AddDays(1)) { CloudTableQuery <SkillCowRequestSubmission> query = rsc.GetAll(cursordate.ToString("yyyyMMdd")); foreach (SkillCowRequestSubmission s in query.Execute().Where(x => x.UtmSource == "demo")) { submissions.Add(s); } cursordate = cursordate.AddDays(1); } foreach (SkillCowRequestSubmission x in submissions) { x.UtmSource = "Kiosks"; x.UtmCampaign = "JerseyGardens"; x.UtmTerm = "Station1"; rsc.Update(x); } return(cnt.ToString() + " leads fixed"); }
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); }