public ActionResult Edit(string id)
        {
            DirectEmployerClientCampusProgramClient programclient = new DirectEmployerClientCampusProgramClient();
            DirectEmployerClientCampusProgram       program       = programclient.GetByRowKey(id);

            program.PostedDateTime = DateTime.UtcNow;

            DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient();
            DirectEmployerClientCampus       campus       = campusclient.GetByRowKey(program.CampusRowKey);

            ViewBag.Campus = campus;

            DirectEmployerClientClient dscc = new DirectEmployerClientClient();

            ViewBag.Client = dscc.GetByRowKey(program.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);

            return(View(program));
        }
        public ActionResult Create(DirectEmployerClientCampus item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DirectEmployerClientCampusClient dscc = new DirectEmployerClientCampusClient();

                    try
                    {
                        dscc.AddNewItem(item);
                        return(RedirectToAction("Edit", "DirectEmployerClients", new { id = item.ClientRowKey }));
                    }
                    catch
                    {
                        ModelState.AddModelError("error", "Error creating new campus");
                    }
                }

                return(View(item));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(string id)
        {
            DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient();
            DirectEmployerClientCampus       campus       = campusclient.GetByRowKey(id);

            DirectEmployerClientClient dscc = new DirectEmployerClientClient();

            ViewBag.Client = dscc.GetByRowKey(campus.ClientRowKey);

            return(View(campus));
        }
        public ActionResult Duplicate(string id)
        {
            DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient();
            DirectEmployerClientCampus       campus       = campusclient.GetByRowKey(id);

            DirectEmployerClientCampusProgramClient  campusprogramclient = new DirectEmployerClientCampusProgramClient();
            List <DirectEmployerClientCampusProgram> campusprograms      = new List <DirectEmployerClientCampusProgram>(campusprogramclient.GetAllByClientId(campus.ClientRowKey).Where(x => x.CampusRowKey == id));

            //Create a copy of the campus
            DirectEmployerClientCampus campuscopy = new DirectEmployerClientCampus();

            campuscopy.Address      = campus.Address;
            campuscopy.CampusType   = campus.CampusType;
            campuscopy.City         = campus.Address;
            campuscopy.ClientId     = campus.ClientId;
            campuscopy.ClientRowKey = campus.ClientRowKey;
            campuscopy.Name         = "Copy of " + campus.Name;
            campuscopy.State        = campus.State;
            campuscopy.Zip          = campus.Zip;
            campusclient.AddNewItem(campuscopy);

            //Now create copies of Programs
            foreach (DirectEmployerClientCampusProgram program in campusprograms)
            {
                DirectEmployerClientCampusProgram pcopy = new DirectEmployerClientCampusProgram();

                pcopy.ClientId     = program.ClientId;
                pcopy.ClientRowKey = program.ClientRowKey;
                pcopy.CampusId     = campuscopy.CampusId;
                pcopy.CampusRowKey = campuscopy.RowKey;

                pcopy.Name              = program.Name;
                pcopy.ProgramId         = program.ProgramId;
                pcopy.ProgramType       = program.ProgramType;
                pcopy.Payout            = program.Payout;
                pcopy.ProgramCategories = program.ProgramCategories;

                pcopy.TotalCap   = program.TotalCap;
                pcopy.AnnualCap  = program.AnnualCap;
                pcopy.MonthlyCap = program.MonthlyCap;
                pcopy.WeeklyCap  = program.WeeklyCap;
                pcopy.DailyCap   = program.DailyCap;

                pcopy.Status = program.Status;

                campusprogramclient.AddNewItem(pcopy);
            }


            return(RedirectToAction("Edit", "DirectEmployerClients", new { id = campus.ClientRowKey }));
        }
        public ActionResult Edit(string id, DirectEmployerClientCampus item)
        {
            try
            {
                DirectEmployerClientCampusClient dscc = new DirectEmployerClientCampusClient();
                dscc.Update(item);

                return(RedirectToAction("Edit", "DirectEmployerClients", new { id = item.ClientRowKey }));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(DirectEmployerClientCampusProgram item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DirectEmployerClientCampusProgramClient programclient = new DirectEmployerClientCampusProgramClient();

                    item.PostedDateTime = DateTime.UtcNow;

                    AttributeMaskCalculator amc = new AttributeMaskCalculator();
                    item.AttributeMask = amc.GetMask(item);

                    ImportantThingsMaskCalculator itmc = new ImportantThingsMaskCalculator();
                    item.ImportantThingsMask = itmc.GetMask(item);

                    try
                    {
                        programclient.AddNewItem(item);
                        return(RedirectToAction("Edit", "DirectEmployerClientCampuses", new { id = item.CampusId }));
                    }
                    catch
                    {
                        ModelState.AddModelError("error", "Error creating new program");
                    }
                }

                DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient();
                DirectEmployerClientCampus       campus       = campusclient.GetByRowKey(item.CampusId);
                ViewBag.Campus = campus;

                DirectEmployerClientClient dscc = new DirectEmployerClientClient();
                ViewBag.Client = dscc.GetByRowKey(item.ClientRowKey);

                return(View(item));
            }
            catch
            {
                DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient();
                DirectEmployerClientCampus       campus       = campusclient.GetByRowKey(item.CampusId);
                ViewBag.Campus = campus;

                DirectEmployerClientClient dscc = new DirectEmployerClientClient();
                ViewBag.Client = dscc.GetByRowKey(item.ClientRowKey);

                return(View());
            }
        }
        public ActionResult Create(string campusid)
        {
            DirectEmployerClientCampusClient campusclient = new DirectEmployerClientCampusClient();
            DirectEmployerClientCampus       campus       = campusclient.GetByRowKey(campusid);

            ViewBag.Campus = campus;

            DirectEmployerClientClient dscc = new DirectEmployerClientClient();

            ViewBag.Client = dscc.GetByRowKey(campus.ClientRowKey);

            DirectEmployerClientCampusProgram newitem = new DirectEmployerClientCampusProgram();

            newitem.PostedDateTime = DateTime.UtcNow;
            return(View(newitem));
        }
        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));
            }
        }