private bool AcceptingLeads(LeadCap schoolcap, LeadCap programcap, LeadCounter schoolcounter, LeadCounter programcounter) { //Check program level if (programcap.Total > 0 && programcounter.Total >= programcap.Total) { return(false); } if (programcap.Annually > 0 && programcounter.Annually >= programcap.Annually) { return(false); } if (programcap.Monthly > 0 && programcounter.Monthly >= programcap.Monthly) { return(false); } //Check school level if (schoolcap.Total > 0 && schoolcounter.Total >= schoolcap.Total) { return(false); } if (schoolcap.Annually > 0 && schoolcounter.Annually >= schoolcap.Annually) { return(false); } if (schoolcap.Monthly > 0 && schoolcounter.Monthly >= schoolcap.Monthly) { return(false); } return(true); }
public ActionResult Edit(string id, DirectEmployerClient item) { try { DirectEmployerClientClient dscc = new DirectEmployerClientClient(); if (item.Description == null) { item.Description = ""; } dscc.Update(item); //Save LeadCap LeadCapClient leadcapclient = new LeadCapClient(); LeadCap leadcap = leadcapclient.GetByRowKey(item.RowKey); bool createnewcap = false; if (leadcap == null) { leadcap = new LeadCap(); leadcap.RowKey = item.RowKey; createnewcap = true; } leadcap.Total = item.TotalCap; leadcap.Annually = item.AnnualCap; leadcap.Monthly = item.MonthlyCap; leadcap.Weekly = item.WeeklyCap; leadcap.Daily = item.DailyCap; if (createnewcap) { leadcapclient.AddNewItem(leadcap); } else { leadcapclient.Update(leadcap); } //Create LeadCounter if doesn't exist LeadCounterClient leadcounterclient = new LeadCounterClient(); LeadCounter leadcounter = leadcounterclient.GetByRowKey(item.RowKey); if (leadcounter == null) { leadcounter = new LeadCounter(); leadcounter.RowKey = item.RowKey; leadcounter.Total = 0; leadcounter.Annually = 0; leadcounter.Monthly = 0; leadcounter.Weekly = 0; leadcounter.Daily = 0; leadcounterclient.AddNewItem(leadcounter); } return(RedirectToAction("Edit", new { id = item.RowKey })); } catch { return(View()); } }
public List <object> FindPositions(HttpRequestBase Request, string zipcode, string attributes, string things, string gender, string programid) { bool demomode = Request["demo"] != null && Request["demo"] == "1"; LeadCounterClient leadcounterclient = new LeadCounterClient(); List <LeadCounter> leadcounters = null; LeadCapClient leadcapclient = new LeadCapClient(); List <LeadCap> leadcaps = null; List <object> results = new List <object>(); bool validprogramcategoryid = false; if (programid != "" && !programid.StartsWith("c")) { validprogramcategoryid = true; } //ZipCodeClient zipclient = new ZipCodeClient(); //ZipCode zipobject = zipclient.GetByRowKey(zipcode); string zipjson = BlobJsonResourceManager.Instance.GetJsonResource("skillcow", "zipcodes", zipcode); JObject jzip = null; if (zipjson != "") { jzip = JObject.Parse(zipjson); } GeoIndexNationalClient nclient = new GeoIndexNationalClient(); GeoIndexAddStateClient addstateclient = new GeoIndexAddStateClient(); GeoIndexAddZipClient addzipclient = new GeoIndexAddZipClient(); GeoIndexSubtractStateClient subtractstateclient = new GeoIndexSubtractStateClient(); GeoIndexSubtractZipClient subtractzipclient = new GeoIndexSubtractZipClient(); List <IGeoIndex> allresults = new List <IGeoIndex>(); List <IGeoIndex> subtractions = new List <IGeoIndex>(); //By program id if (validprogramcategoryid) { allresults.AddRange(nclient.GetAllByPartition(programid)); if (jzip != null) { //allresults.AddRange(addstateclient.GetAllByPartition(zipobject.StateCode + "-" + programid)); allresults.AddRange(addstateclient.GetAllByPartition(jzip["statecode"].ToString() + "-" + programid)); allresults.AddRange(addzipclient.GetAllByPartition(zipcode + "-" + programid)); } if (jzip != null) { //subtractions.AddRange(subtractstateclient.GetAllByPartition(zipobject.StateCode + "-" + programid)); subtractions.AddRange(subtractstateclient.GetAllByPartition(jzip["statecode"].ToString() + "-" + programid)); subtractions.AddRange(subtractzipclient.GetAllByPartition(zipcode + "-" + programid)); } } else { allresults.AddRange(nclient.GetAllByPartition("attr")); if (jzip != null) { //allresults.AddRange(addstateclient.GetAllByPartition(zipobject.StateCode)); allresults.AddRange(addstateclient.GetAllByPartition(jzip["statecode"].ToString())); allresults.AddRange(addzipclient.GetAllByPartition(zipcode)); } if (jzip != null) { //subtractions.AddRange(subtractstateclient.GetAllByPartition(zipobject.StateCode)); subtractions.AddRange(subtractstateclient.GetAllByPartition(jzip["statecode"].ToString())); subtractions.AddRange(subtractzipclient.GetAllByPartition(zipcode)); } } IEnumerable <IGeoIndex> difference = allresults.Except(subtractions, new CompareGeoIndexResults()); DirectEmployerClientClient clientclient = new DirectEmployerClientClient(); DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient(); DirectEmployerClientCampusProgramClient programclient = new DirectEmployerClientCampusProgramClient(); JObject oattributes = null; JObject othings = null; long attributemask = 0; long importantthingsmask = 0; if (attributes != null && attributes != "") { oattributes = JObject.Parse(attributes); AttributeMaskCalculator amc = new AttributeMaskCalculator(); attributemask = amc.GetMask(oattributes); } if (things != null && things != "") { othings = JObject.Parse(things); ImportantThingsMaskCalculator itmc = new ImportantThingsMaskCalculator(); importantthingsmask = itmc.GetMask(othings); } foreach (IGeoIndex geoindex in allresults) { if (geoindex.AttributeMask != null && (geoindex.AttributeMask & attributemask) == attributemask) { DirectEmployerClientCampusProgram job = programclient.GetByRowKey(geoindex.RowKey); if (job.Status == "Live" || (demomode == true && job.Status == "Demo")) { bool filtered = false; //Apply other filters if (gender != "" && job.Gender != null && job.Gender != "") { if (job.Gender != gender) { filtered = true; } } if (!filtered) { DirectEmployerClientCampus campus = campusclient.GetByRowKey(geoindex.CampusRowKey); DirectEmployerClient employer = clientclient.GetByRowKey(geoindex.ClientRowKey); bool acceptingleads = false; if (employer.Status == "Live" || (demomode == true && employer.Status == "Demo")) { if (campus.Status == "Live" || (demomode == true && campus.Status == "Demo")) { //List<DirectEmployerClientCampusProgram> campusprograms = new List<DirectEmployerClientCampusProgram>(programclient.GetAllByClientId(employer.RowKey).Where(x => x.CampusRowKey == campus.RowKey)); if (leadcounters == null) { leadcounters = new List <LeadCounter>(leadcounterclient.GetAll()); leadcaps = new List <LeadCap>(leadcapclient.GetAll()); } LeadCap schoolcap = leadcaps.Find(x => x.RowKey == employer.RowKey); LeadCap programcap = leadcaps.Find(x => x.RowKey == job.RowKey); LeadCounter schoolcounter = leadcounters.Find(x => x.RowKey == employer.RowKey); LeadCounter programcounter = leadcounters.Find(x => x.RowKey == job.RowKey); acceptingleads = AcceptingLeads(schoolcap, programcap, schoolcounter, programcounter); if (acceptingleads) { results.Add(new { clienttype = employer.ClientType, clientid = employer.ClientId, clientsetid = employer.ClientId, logoclientid = employer.ClientId, program = programid, formid = employer.FormId, distance = 0, campustype = campus.CampusType, campuskey = campus.CampusId, programkey = geoindex.RowKey, clientrowkey = employer.RowKey, jobkey = job.RowKey, jobtitle = job.JobTitle, company = employer.Name.ToJSONSafeString(), companylogo = "https://chaindate.blob.core.windows.net/resources/employerlogos/" + employer.ClientType + employer.RowKey, city = campus.City, state = campus.State, date = job.PostedDateTime.ToString("ddd, dd MMM yyyy HH:mm:ss") + " GMT", snippet = job.Description, attributescore = oattributes != null ? job.GetAttributeScore(oattributes) : 0, importantthingsscore = othings != null ? job.GetImportantThingsScore(othings) : 0 }); } } } } } } } return(results); }
public ActionResult Edit(string id, DirectEmployerClientCampusProgram updateditem) { DirectEmployerClientCampusProgramClient programclient = new DirectEmployerClientCampusProgramClient(); DirectEmployerClientCampusProgram currentitem = programclient.GetByRowKey(updateditem.RowKey); if (updateditem.GeoAddNational == null) { updateditem.GeoAddNational = ""; } if (updateditem.GeoAddStates == null) { updateditem.GeoAddStates = ""; } if (updateditem.GeoAddZips == null) { updateditem.GeoAddZips = ""; } if (updateditem.GeoSubtractStates == null) { updateditem.GeoSubtractStates = ""; } if (updateditem.GeoSubtractZips == null) { updateditem.GeoSubtractZips = ""; } try { AttributeMaskCalculator amc = new AttributeMaskCalculator(); updateditem.AttributeMask = amc.GetMask(updateditem); ImportantThingsMaskCalculator itmc = new ImportantThingsMaskCalculator(); updateditem.ImportantThingsMask = itmc.GetMask(updateditem); if (PublishGeoIndex2(currentitem, updateditem)) { BlobStringManager.Instance.SaveString(NullString(updateditem.Html), updateditem.RowKey, "skillcowjobs", "HTML"); object htmljson = new { html = updateditem.Html.ToJSONSafeString().Replace("'", "\'") }; BlobJsonResourceManager.Instance.SaveJsonResource("customhtml", "skillcowjobs", "JSON", updateditem.RowKey, htmljson.ToJSON()); updateditem.GeoAddStates = ""; updateditem.GeoAddZips = ""; updateditem.GeoSubtractStates = ""; updateditem.GeoSubtractZips = ""; updateditem.Html = ""; programclient.Update(updateditem); //Save LeadCap LeadCapClient leadcapclient = new LeadCapClient(); LeadCap leadcap = leadcapclient.GetByRowKey(updateditem.RowKey); bool createnewcap = false; if (leadcap == null) { leadcap = new LeadCap(); leadcap.RowKey = updateditem.RowKey; createnewcap = true; } leadcap.Total = updateditem.TotalCap; leadcap.Annually = updateditem.AnnualCap; leadcap.Monthly = updateditem.MonthlyCap; leadcap.Weekly = updateditem.WeeklyCap; leadcap.Daily = updateditem.DailyCap; if (createnewcap) { leadcapclient.AddNewItem(leadcap); } else { leadcapclient.Update(leadcap); } //Create LeadCounter if doesn't exist LeadCounterClient leadcounterclient = new LeadCounterClient(); LeadCounter leadcounter = leadcounterclient.GetByRowKey(updateditem.RowKey); if (leadcounter == null) { leadcounter = new LeadCounter(); leadcounter.RowKey = updateditem.RowKey; leadcounter.Total = 0; leadcounter.Annually = 0; leadcounter.Monthly = 0; leadcounter.Weekly = 0; leadcounter.Daily = 0; leadcounterclient.AddNewItem(leadcounter); } } else { throw new Exception("Failed to publish GEO index"); } return(RedirectToAction("Edit", "DirectEmployerClientCampusPrograms", new { id = updateditem.RowKey })); } catch { DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient(); DirectEmployerClientCampus campus = campusclient.GetByRowKey(updateditem.CampusRowKey); ViewBag.Campus = campus; DirectEmployerClientClient dscc = new DirectEmployerClientClient(); ViewBag.Client = dscc.GetByRowKey(updateditem.ClientRowKey); ViewBag.GeoAddStates = BlobStringManager.Instance.GetString("skillcowemployerprogramgeoindex", "AddStates", id); ViewBag.GeoAddZips = BlobStringManager.Instance.GetString("skillcowemployerprogramgeoindex", "AddZips", id); ViewBag.GeoSubtractStates = BlobStringManager.Instance.GetString("skillcowemployerprogramgeoindex", "SubtractStates", id); ViewBag.GeoSubtractZips = BlobStringManager.Instance.GetString("skillcowemployerprogramgeoindex", "SubtractZips", id); ViewBag.Html = BlobStringManager.Instance.GetString("skillcowjobs", "HTML", id); ModelState.AddModelError("error", "Failed to save"); return(View(updateditem)); } }
public List <object> FindSchools(HttpRequestBase Request, string zipcode, string programcategoryid, string edulevel, ref List <string> directclientnames) { bool demomode = Request["demo"] != null && Request["demo"] == "1"; LeadCounterClient leadcounterclient = new LeadCounterClient(); List <LeadCounter> leadcounters = null; LeadCapClient leadcapclient = new LeadCapClient(); List <LeadCap> leadcaps = null; List <object> results = new List <object>(); if (programcategoryid.StartsWith("c")) { return(results); } ZipCodeClient zipclient = new ZipCodeClient(); ZipCode zipobject = zipclient.GetByRowKey(zipcode); GeoIndexNationalClient nclient = new GeoIndexNationalClient(); GeoIndexAddStateClient addstateclient = new GeoIndexAddStateClient(); GeoIndexAddZipClient addzipclient = new GeoIndexAddZipClient(); GeoIndexSubtractStateClient subtractstateclient = new GeoIndexSubtractStateClient(); GeoIndexSubtractZipClient subtractzipclient = new GeoIndexSubtractZipClient(); List <IGeoIndex> allresults = new List <IGeoIndex>(); allresults.AddRange(nclient.GetAllByPartition(programcategoryid)); if (zipobject != null) { allresults.AddRange(addstateclient.GetAllByPartition(zipobject.StateCode + "-" + programcategoryid)); allresults.AddRange(addzipclient.GetAllByPartition(zipcode + "-" + programcategoryid)); } List <IGeoIndex> subtractions = new List <IGeoIndex>(); if (zipobject != null) { subtractions.AddRange(subtractstateclient.GetAllByPartition(zipobject.StateCode + "-" + programcategoryid)); subtractions.AddRange(subtractzipclient.GetAllByPartition(zipcode + "-" + programcategoryid)); } IEnumerable <IGeoIndex> difference = allresults.Except(subtractions, new CompareGeoIndexResults()); IEnumerable <IGrouping <string, IGeoIndex> > bycampus = difference.GroupBy(x => x.CampusRowKey); DirectSchoolClientClient clientclient = new DirectSchoolClientClient(); DirectSchoolClientCampusClient campusclient = new DirectSchoolClientCampusClient(); DirectSchoolClientCampusProgramClient programclient = new DirectSchoolClientCampusProgramClient(); foreach (IGrouping <string, IGeoIndex> campusgroup in bycampus) { DirectSchoolClientCampus campus = campusclient.GetByRowKey(campusgroup.Key); DirectSchoolClient school = clientclient.GetByRowKey(campus.ClientRowKey); bool acceptingleads = false; if (school.Status == "Live" || (demomode == true && school.Status == "Demo")) { if (campus.Status == "Live" || (demomode == true && campus.Status == "Demo")) { List <DirectSchoolClientCampusProgram> campusprograms = new List <DirectSchoolClientCampusProgram>(programclient.GetAllBySchoolId(school.RowKey).Where(x => x.CampusRowKey == campus.RowKey)); string programkey = ""; bool gotprogramkey = false; List <object> programitems = new List <object>(); foreach (IGeoIndex programresult in campusgroup) { DirectSchoolClientCampusProgram program = campusprograms.SingleOrDefault(x => x.RowKey == programresult.RowKey); if (program.Status == "Live" || (demomode == true && program.Status == "Demo")) { if (leadcounters == null) { leadcounters = new List <LeadCounter>(leadcounterclient.GetAll()); leadcaps = new List <LeadCap>(leadcapclient.GetAll()); } LeadCap schoolcap = leadcaps.Find(x => x.RowKey == school.RowKey); LeadCap programcap = leadcaps.Find(x => x.RowKey == program.RowKey); LeadCounter schoolcounter = leadcounters.Find(x => x.RowKey == school.RowKey); LeadCounter programcounter = leadcounters.Find(x => x.RowKey == program.RowKey); //see if counters need to be reset schoolcounter.ResetCountersIfNeeded(leadcounterclient); programcounter.ResetCountersIfNeeded(leadcounterclient); acceptingleads = AcceptingLeads(schoolcap, programcap, schoolcounter, programcounter); if (acceptingleads) { programitems.Add(new { id = program.ProgramId + "." + program.RowKey, type = program.ProgramType, typename = program.ResolveProgramTypeName(), isprimary = 1, name = program.Name.ToJSONSafeString() }); if (!gotprogramkey) { if (",hs,ged,crt,sc,as,inhs,none,".Contains("," + edulevel.ToLower() + ",")) { string testprogramkey = program.ProgramType; //Exclude MS if (!(",ms,ma,maed,mba,me,mfa,ms,mst,".Contains("," + testprogramkey.ToLower() + ","))) { programkey = HttpUtility.UrlDecode(program.ProgramId); gotprogramkey = true; } } else { programkey = HttpUtility.UrlDecode(program.ProgramId); gotprogramkey = true; } } } } } if (acceptingleads) { if (!directclientnames.Contains(school.Name)) { directclientnames.Add(school.Name); } results.Add(new { clienttype = "direct", formname = school.Name.ToJSONSafeString(), clientfrontendname = school.Name.ToJSONSafeString(), formdescription = school.Description.ToJSONSafeString(), city = campus.City, state = campus.State, image = "https://chaindate.blob.core.windows.net/resources/schoollogos/" + school.RowKey, clientid = school.ClientId, clientsetid = school.ClientId, logoclientid = school.ClientId, program = programcategoryid, formid = school.FormId, distance = 0, campustype = campus.CampusType, campuskey = campus.CampusId, programs = programitems.ToArray(), programkey = programkey, clientrowkey = school.RowKey }); } } } } return(results); }
public ActionResult Edit(string id, DirectSchoolClientCampusProgram updateditem) { DirectSchoolClientCampusProgramClient programclient = new DirectSchoolClientCampusProgramClient(); DirectSchoolClientCampusProgram currentitem = programclient.GetByRowKey(updateditem.RowKey); if (updateditem.GeoAddNational == null) { updateditem.GeoAddNational = ""; } if (updateditem.GeoAddNational == null) { updateditem.GeoAddNational = ""; } if (updateditem.GeoAddStates == null) { updateditem.GeoAddStates = ""; } if (updateditem.GeoAddZips == null) { updateditem.GeoAddZips = ""; } if (updateditem.GeoSubtractStates == null) { updateditem.GeoSubtractStates = ""; } if (updateditem.GeoSubtractZips == null) { updateditem.GeoSubtractZips = ""; } try { if (PublishGeoIndex(currentitem, updateditem)) { updateditem.GeoAddStates = ""; updateditem.GeoAddZips = ""; updateditem.GeoSubtractStates = ""; updateditem.GeoSubtractZips = ""; programclient.Update(updateditem); //Save LeadCap LeadCapClient leadcapclient = new LeadCapClient(); LeadCap leadcap = leadcapclient.GetByRowKey(updateditem.RowKey); bool createnewcap = false; if (leadcap == null) { leadcap = new LeadCap(); leadcap.RowKey = updateditem.RowKey; createnewcap = true; } leadcap.Total = updateditem.TotalCap; leadcap.Annually = updateditem.AnnualCap; leadcap.Monthly = updateditem.MonthlyCap; leadcap.Weekly = updateditem.WeeklyCap; leadcap.Daily = updateditem.DailyCap; if (createnewcap) { leadcapclient.AddNewItem(leadcap); } else { leadcapclient.Update(leadcap); } //Create LeadCounter if doesn't exist LeadCounterClient leadcounterclient = new LeadCounterClient(); LeadCounter leadcounter = leadcounterclient.GetByRowKey(updateditem.RowKey); if (leadcounter == null) { leadcounter = new LeadCounter(); leadcounter.RowKey = updateditem.RowKey; leadcounter.Total = 0; leadcounter.Annually = 0; leadcounter.Monthly = 0; leadcounter.Weekly = 0; leadcounter.Daily = 0; leadcounterclient.AddNewItem(leadcounter); } } else { throw new Exception("Failed to publish GEO index"); } return(RedirectToAction("Edit", "DirectSchoolClientCampuses", new { id = updateditem.CampusRowKey })); } catch { DirectSchoolClientCampusClient campusclient = new DirectSchoolClientCampusClient(); DirectSchoolClientCampus campus = campusclient.GetByRowKey(updateditem.CampusRowKey); ViewBag.Campus = campus; DirectSchoolClientClient dscc = new DirectSchoolClientClient(); ViewBag.Client = dscc.GetByRowKey(updateditem.ClientRowKey); ViewBag.GeoAddStates = BlobStringManager.Instance.GetString("skillcowschoolprogramgeoindex", "AddStates", id); ViewBag.GeoAddZips = BlobStringManager.Instance.GetString("skillcowschoolprogramgeoindex", "AddZips", id); ViewBag.GeoSubtractStates = BlobStringManager.Instance.GetString("skillcowschoolprogramgeoindex", "SubtractStates", id); ViewBag.GeoSubtractZips = BlobStringManager.Instance.GetString("skillcowschoolprogramgeoindex", "SubtractZips", id); return(View(updateditem)); } }