public ActionResult EditListing(JobPosting posting)
        {
            JobPostingClient jpc = new JobPostingClient();

            posting.PostedDateTime = DateTime.UtcNow;


            AttributeMaskCalculator amc = new AttributeMaskCalculator();

            posting.AttributeMask = amc.GetMask(posting);

            ImportantThingsMaskCalculator itmc = new ImportantThingsMaskCalculator();

            posting.ImportantThingsMask = itmc.GetMask(posting);


            jpc.Update(posting);

            return(RedirectToAction("jobpostings", new { am = 262143 }));
        }
        public ActionResult CreateFromTemplate(string tenid, string templateid)
        {
            JobPostingClient jpc = new JobPostingClient();

            XmlDocument xmldoc = getXmlDoc("http://www.employmentnetwork.net/xml/?campus_type=j&site_id=1002&campaign_id=13574568&zip=&job_title_name=jobs");

            JobPosting posting = new JobPosting();

            posting.PostedDateTime = DateTime.UtcNow;

            XmlNodeList items = xmldoc.GetElementsByTagName("listing");

            foreach (XmlNode node in items)
            {
                if (node.E("reference_number") == tenid)
                {
                    XmlNode programvaluesnode = node.SelectSingleNode("program_values");
                    XmlNode programnode       = null;
                    if (programvaluesnode != null)
                    {
                        XmlNodeList programnodes = programvaluesnode.SelectNodes("item");
                        if (programnodes.Count > 0)
                        {
                            programnode = programnodes[0];
                        }
                    }

                    posting.ClientId    = node.E("client_id");
                    posting.CompanyName = node.E("client_name");
                    posting.Logo        = node.E("logo_image");
                    posting.JobTitle    = programnode.E("value");
                    posting.Description = programnode.E("description2");

                    if (node.E("city") != "" && node.E("state") != "")
                    {
                        posting.FormattedLocation = node.E("city") + ", " + node.E("state");
                    }
                    else if (node.E("city") != "" && node.E("state") == "")
                    {
                        posting.FormattedLocation = node.E("city");
                    }
                    else if (node.E("city") == "" && node.E("state") != "")
                    {
                        posting.FormattedLocation = node.E("state");
                    }
                    else
                    {
                        posting.FormattedLocation = "";
                    }

                    posting.Source               = "TEN";
                    posting.FormId               = node.E("form_id");
                    posting.PositionLocationId   = node.E("campus_key");
                    posting.PositionLocationName = node.E("campus_value");

                    posting.ReferenceId = node.E("reference_number");
                    posting.URL         = programnode.E("link");

                    string geotargeting = node.E("zips");
                    //if (geotargeting.Length > 65536)
                    //{
                    //    posting.GeoTarget = geotargeting.Substring(0, 65536);
                    //    posting.GeoTarget2 = geotargeting.Substring(65536, geotargeting.Length - 65536);
                    //}
                    //else
                    //{
                    posting.GeoTarget = geotargeting;
                    //}

                    posting.GeoTargetType = "zip";

                    posting.Keywords = node.E("keywords");

                    break;
                }
            }

            posting.PostedDateTime = DateTime.UtcNow;


            JobPosting template = jpc.GetByRowKey(templateid);

            posting.DimensionAttitude     = template.DimensionAttitude;
            posting.DimensionAction       = template.DimensionAction;
            posting.DimensionCompensation = template.DimensionCompensation;

            posting.DimensionConcentration = template.DimensionConcentration;
            posting.DimensionEndurance     = template.DimensionEndurance;
            posting.DimensionInformation   = template.DimensionInformation;

            posting.DimensionPatterns   = template.DimensionPatterns;
            posting.DimensionPresence   = template.DimensionPresence;
            posting.DimensionProcessing = template.DimensionProcessing;

            posting.ImportantThingsAdmiration  = template.ImportantThingsAdmiration;
            posting.ImportantThingsAdventure   = template.ImportantThingsAdventure;
            posting.ImportantThingsAnimals     = template.ImportantThingsAnimals;
            posting.ImportantThingsBeauty      = template.ImportantThingsBeauty;
            posting.ImportantThingsCompetition = template.ImportantThingsCompetition;

            posting.ImportantThingsCreativity = template.ImportantThingsCreativity;
            posting.ImportantThingsDuty       = template.ImportantThingsDuty;
            posting.ImportantThingsEasy       = template.ImportantThingsEasy;
            posting.ImportantThingsGrowth     = template.ImportantThingsGrowth;
            posting.ImportantThingsHelping    = template.ImportantThingsHelping;

            posting.ImportantThingsPeople     = template.ImportantThingsPeople;
            posting.ImportantThingsPolitics   = template.ImportantThingsPolitics;
            posting.ImportantThingsSafety     = template.ImportantThingsSafety;
            posting.ImportantThingsScience    = template.ImportantThingsScience;
            posting.ImportantThingsTechnology = template.ImportantThingsTechnology;


            posting.AttributeMask       = template.AttributeMask;
            posting.ImportantThingsMask = template.ImportantThingsMask;


            jpc.AddNewItem(posting);

            return(RedirectToAction("editlisting", new { id = posting.RowKey }));
        }
        public ActionResult MatchJobs(string zip, string attributes, string things)
        {
            try
            {
                ZipCodeClient zcc     = new ZipCodeClient();
                ZipCode       zipcode = zcc.GetByRowKey(zip);

                if (zipcode == null)
                {
                    throw new Exception("Invalid ZIP");
                }

                JObject oattributes = JObject.Parse(attributes);
                JObject othings     = JObject.Parse(things);

                AttributeMaskCalculator amc = new AttributeMaskCalculator();
                long attributemask          = amc.GetMask(oattributes);

                ImportantThingsMaskCalculator itmc = new ImportantThingsMaskCalculator();
                long importantthingsmask           = itmc.GetMask(othings);

                JobPostingClient jpc = new JobPostingClient();

                List <object> jobs = new List <object>();

                foreach (JobPosting posting in jpc.GetAllBySource("TEN").Execute().Where(x => x.IsLive != null && x.IsLive == true))
                {
                    if (posting.AttributeMask != null && (posting.AttributeMask & attributemask) == attributemask)
                    {
                        bool targetsusa   = false;
                        bool targetsstate = false;
                        bool targetszip   = false;

                        if (posting.GeoTarget != null)
                        {
                            targetsusa   = posting.GeoTarget.Contains("USA");
                            targetsstate = posting.GeoTarget.Contains(zipcode.StateCode);
                            targetszip   = posting.GeoTarget.Contains(zipcode.RowKey);
                        }
                        else
                        {
                            Console.Write("geo target not set");
                        }

                        if (targetsusa || targetsstate || targetszip)
                        {
                            try
                            {
                                jobs.Add(new
                                {
                                    id                = posting.RowKey,
                                    jobtitle          = posting.JobTitle != null ? posting.JobTitle.ToJSONSafeString() : "",
                                    description       = posting.Description != null ? posting.Description.ToJSONSafeString() : "",
                                    clientid          = posting.ClientId,
                                    clientname        = posting.CompanyName != null ? posting.CompanyName.ToJSONSafeString() : "",
                                    formattedlocation = posting.FormattedLocation != null ? posting.FormattedLocation.ToJSONSafeString() : "",
                                    logoimage         = posting.Logo,

                                    formid      = posting.FormId,
                                    campuskey   = posting.PositionLocationId,
                                    campusvalue = posting.PositionLocationName != null ? posting.PositionLocationName.ToJSONSafeString() : "",

                                    //zips = node.E("zips"),
                                    //keywords = node.E("keywords"),
                                    date            = posting.PostedDateTime != null ? posting.PostedDateTime.ToString("dd/MM/yyyy HH:mm") : "",
                                    referencenumber = posting.ReferenceId,

                                    dimattitude      = posting.DimensionAttitude,
                                    dimaction        = posting.DimensionAction,
                                    dimcompensation  = posting.DimensionCompensation,
                                    dimconcentration = posting.DimensionConcentration,
                                    dimendurance     = posting.DimensionEndurance,
                                    diminformation   = posting.DimensionInformation,
                                    dimpatterns      = posting.DimensionPatterns,
                                    dimprocessing    = posting.DimensionProcessing,
                                    dimpresence      = posting.DimensionPresence,

                                    thingadmiration  = posting.ImportantThingsAdmiration,
                                    thingadventure   = posting.ImportantThingsAdventure,
                                    thinganimals     = posting.ImportantThingsAnimals,
                                    thingbeauty      = posting.ImportantThingsBeauty,
                                    thingcompetition = posting.ImportantThingsCompetition,

                                    thingcreativity = posting.ImportantThingsCreativity,
                                    thingduty       = posting.ImportantThingsDuty,
                                    thingeasy       = posting.ImportantThingsEasy,
                                    thinggrowth     = posting.ImportantThingsGrowth,
                                    thinghelping    = posting.ImportantThingsHelping,

                                    thingpeople     = posting.ImportantThingsPeople,
                                    thingpolitics   = posting.ImportantThingsPolitics,
                                    thingsafety     = posting.ImportantThingsSafety,
                                    thingscience    = posting.ImportantThingsScience,
                                    thingtechnology = posting.ImportantThingsTechnology,

                                    attributescore       = posting.GetAttributeScore(oattributes),
                                    importantthingsscore = posting.GetImportantThingsScore(othings)
                                });
                            }
                            catch (Exception ex)
                            {
                                Console.Write(ex.Message);
                            }
                        }
                    }
                }


                Response.ContentType = "application/json";
                string retvalue = (new { result = "ok", jobs = jobs.ToArray() }).ToJSON();
                Response.Write(retvalue);
                Response.End();
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write(DefaultErrorResponse(ex.Message));
                Response.End();
            }

            return(null);
        }