public ActionResult Create(DirectSchoolClientCampusProgram item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DirectSchoolClientCampusProgramClient programclient = new DirectSchoolClientCampusProgramClient();

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

                DirectSchoolClientCampusClient campusclient = new DirectSchoolClientCampusClient();
                DirectSchoolClientCampus       campus       = campusclient.GetByRowKey(item.CampusId);
                ViewBag.Campus = campus;

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

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

            DirectSchoolClientClient dscc = new DirectSchoolClientClient();

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

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

            DirectSchoolClientCampusProgramClient  campusprogramclient = new DirectSchoolClientCampusProgramClient();
            List <DirectSchoolClientCampusProgram> campusprograms      = new List <DirectSchoolClientCampusProgram>(campusprogramclient.GetAllBySchoolId(campus.ClientRowKey).Where(x => x.CampusRowKey == id));

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

            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 (DirectSchoolClientCampusProgram program in campusprograms)
            {
                DirectSchoolClientCampusProgram pcopy = new DirectSchoolClientCampusProgram();

                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", "DirectSchoolClients", new { id = campus.ClientRowKey }));
        }
        public ActionResult Edit(string id)
        {
            DirectSchoolClientCampusProgramClient programclient = new DirectSchoolClientCampusProgramClient();
            DirectSchoolClientCampusProgram       program       = programclient.GetByRowKey(id);

            DirectSchoolClientCampusClient campusclient = new DirectSchoolClientCampusClient();
            DirectSchoolClientCampus       campus       = campusclient.GetByRowKey(program.CampusRowKey);

            ViewBag.Campus = campus;

            DirectSchoolClientClient dscc = new DirectSchoolClientClient();

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