コード例 #1
0
        public ActionResult Story()
        {
            var  db = new CareersDataContext();
            var  storiesViewModel = new StoriesViewModel();
            long inputId          = Int64.Parse(RouteData.Values["Id"].ToString());
            var  story            = db.Stories.Where(x => x.Id == inputId).ToArray();

            if (RouteData.Values["slug"] == null)
            {
                return(Redirect(@"~\" + "careers/" + story[0].CareerName + "/" + RouteData.Values["Id"].ToString() + "/" + getSlug(Int64.Parse(RouteData.Values["Id"].ToString()))));
            }

            //sanitize url for careername (again), id, AND slug.
            string inputUrlParam;
            string cleanUrlParam;

            inputUrlParam = RouteData.Values["careerName"].ToString();
            cleanUrlParam = URLFriendly(inputUrlParam);

            if (!inputUrlParam.Equals(cleanUrlParam))
            {//use StringBuilder here for optimization
                return(Redirect(@"~\" + "careers/" + cleanUrlParam + "/" + RouteData.Values["Id"].ToString() + "/"
                                + RouteData.Values["slug"].ToString()));
            }

            if (!RouteData.Values["slug"].ToString().Equals(getSlug(Int64.Parse(RouteData.Values["Id"].ToString()))))
            {
                return(Redirect(@"~\" + "careers/" + RouteData.Values["careerName"].ToString() + "/" + RouteData.Values["Id"].ToString() + "/" + getSlug(Int64.Parse(RouteData.Values["Id"].ToString()))));
            }

            if (story.Length < 1)
            {//wrong id
                return(Redirect(@"~\" + "careers/" + RouteData.Values["careerName"].ToString()));
            }

            storiesViewModel.CareerName       = story[0].CareerName;
            storiesViewModel.StarCount        = story[0].StarCount;
            storiesViewModel.PostCount        = story[0].PostCount;
            storiesViewModel.FunnyCount       = story[0].FunnyCount;
            storiesViewModel.InformativeCount = story[0].InformativeCount;
            storiesViewModel.Username         = story[0].Username;
            storiesViewModel.Story            = story[0].Story;
            storiesViewModel.Title            = story[0].Title;
            storiesViewModel.Education        = story[0].Education;
            storiesViewModel.Company          = story[0].Company;
            storiesViewModel.Salary           = story[0].Salary;
            storiesViewModel.Location         = story[0].Location;
            storiesViewModel.PostDate         = story[0].PostDate;

            ///////////////////////////////

            /*Posts and Replies: use the inputId variable to find corresponding posts and replies.  Add them to ViewBag variables and display them
             * in the View.
             * */
            var PostsList = db.Posts.Where(u => u.IsActive == 1 && u.StoryId == inputId).OrderBy(u => u.PostDate).ToList();

            ViewBag.PostsList = PostsList;
            ///////////////////////////////
            return(View(storiesViewModel));
        }
コード例 #2
0
        public ActionResult Index()
        {
            var db = new CareersDataContext();
            var careerStoriesList = db.Stories.Where(u => u.IsActive == 1).OrderByDescending(u => u.PostCount).ToList();

            ViewBag.careerStoriesListHome = careerStoriesList;

            return(View());
        }
コード例 #3
0
        public static string getSlug(long StoryId)
        {
            string slug = "";

            var db      = new CareersDataContext();
            var stories = db.Stories.Where(x => x.Id == StoryId).ToArray();

            slug = stories[0].Title;
            slug = URLFriendly(slug);

            return(slug);
        }
コード例 #4
0
        public ActionResult StoryPost(PostsViewModel viewModelPosts)
        {
            //Don't do any redirects, the slug is null when form is posted.


            //This is how you get the current user id.
            string userId         = "";
            var    claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity != null)
            {
                // the principal identity is a claims identity.
                // now we need to find the NameIdentifier claim
                var userIdClaim = claimsIdentity.Claims
                                  .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                if (userIdClaim != null)
                {
                    userId = userIdClaim.Value;
                }
            }

            Posts posts = new Posts();

            posts.StoryId    = Int64.Parse(RouteData.Values["Id"].ToString()); //what if user changes id parameter in url then presses post??
            posts.UserId     = userId;
            posts.Username   = User.Identity.Name;
            posts.ReplyCount = 0;
            posts.LikeCount  = 0;
            posts.PostDate   = DateTime.Now.ToString("MM/dd/yyyy h:mm tt");
            posts.Post       = viewModelPosts.Post;
            posts.IsActive   = 1;

            if (ModelState.IsValid)
            {
                //Save to Database
                var db = new CareersDataContext();
                db.Posts.Add(posts);
                db.SaveChanges();

                //increment post count for current story
                var story = db.Stories.Find(Int64.Parse(RouteData.Values["Id"].ToString()));
                story.PostCount      += 1;
                db.Entry(story).State = EntityState.Modified;
                db.SaveChanges();


                //use StringBuilder here for optimization
                return(Redirect(@"~\" + "careers/" + RouteData.Values["careerName"].ToString() + "/" + RouteData.Values["Id"].ToString() + "/" + getSlug(posts.StoryId)));
            }

            return(Story()); //return the getStory action so that the new reply or post will be shown.
        }
コード例 #5
0
        //
        // GET: /Sitemap/
        public ActionResult Index()
        {
            var db          = new CareersDataContext();
            var careerslist = db.Careers.Where(u => u.IsActive == 1).OrderBy(u => u.CareerName).ToList();
            var storieslist = db.Stories.Where(u => u.IsActive == 1).OrderBy(u => u.CareerName).ToList();

            XNamespace   ns          = "http://www.sitemaps.org/schemas/sitemap/0.9";
            const string careersurl  = "http://careeries.com/careers/{0}";
            var          careeritems = careerslist;
            var          storyitems  = storieslist;
            var          sitemap     = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(ns + "urlset",
                             new XElement(ns + "url",
                                          new XElement(ns + "loc", "http://careeries.com"),
                                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                          new XElement(ns + "changefreq", "always"),
                                          new XElement(ns + "priority", "0.5")),
                             new XElement(ns + "url",
                                          new XElement(ns + "loc", "http://careeries.com/careers"),
                                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                          new XElement(ns + "changefreq", "always"),
                                          new XElement(ns + "priority", "0.5")),
                             new XElement(ns + "url",
                                          new XElement(ns + "loc", "http://careeries.com/account/register"),
                                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                          new XElement(ns + "changefreq", "always"),
                                          new XElement(ns + "priority", "0.5")),
                             new XElement(ns + "url",
                                          new XElement(ns + "loc", "http://careeries.com/account/login"),
                                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                          new XElement(ns + "changefreq", "always"),
                                          new XElement(ns + "priority", "0.5")),
                             from i in careeritems
                             select
                             new XElement(ns + "url",
                                          new XElement(ns + "loc", string.Format(careersurl, i.CareerName.Replace(" ", "-").ToLower())),
                                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                          new XElement(ns + "changefreq", "always"),
                                          new XElement(ns + "priority", "0.5")),
                             from story in storyitems
                             select
                             new XElement(ns + "url",
                                          new XElement(ns + "loc", string.Format(careersurl, story.CareerName.Replace(" ", "-").ToLower() + "/" + story.Id + "/" + story.Title.Replace(" ", "-").ToLower())),
                                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                                          new XElement(ns + "changefreq", "always"),
                                          new XElement(ns + "priority", "0.5"))
                             ) //end urlset
                );             //end XDocument

            return(Content("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + sitemap.ToString(), "text/xml"));
        }
コード例 #6
0
        public ActionResult Create()
        {
            //sanitize url
            string inputUrlParam;
            string cleanUrlParam;

            if (RouteData.Values["careerName"] == null)
            {
                return(Redirect("/careers/administrative-assistant"));
            }
            else
            {
                inputUrlParam = RouteData.Values["careerName"].ToString();
                cleanUrlParam = URLFriendly(inputUrlParam);

                if (!inputUrlParam.Equals(cleanUrlParam))
                {
                    return(Redirect(cleanUrlParam));
                }
            }

            bool careerNameUrlFound = false;

            string careerNameUrl = "";

            if (RouteData.Values["careerName"] != null)
            {
                careerNameUrl = RouteData.Values["careerName"].ToString();
                careerNameUrl = careerNameUrl.Replace("-", " ");
            }

            var db   = new CareersDataContext();
            var list = db.Careers.Where(u => u.IsActive == 1).ToList();

            for (int i = 0; i < list.Count(); i++)
            {
                if (list.ElementAt(i).CareerName.ToLower().Equals(careerNameUrl))
                {
                    careerNameUrlFound = true;
                }
            }

            if (!careerNameUrlFound)
            {
                return(Redirect("/careers/administrative-assistant")); //anything after careers/ that is not valid will be redirected to aa.
            }
            ////////////////////////end redirect check/////////////////////////////////////////////

            return(View());
        }
コード例 #7
0
        public static long getCareerId(string careerName)
        {
            long careerId = 1;

            var db      = new CareersDataContext();
            var careers = db.Careers.Where(x => string.Equals(x.CareerName, careerName)).ToArray();

            if (careerName == "" || careerName == null)
            {
                careerId = 1;
            }
            else
            {
                careerId = careers[0].Id;
            }

            return(careerId);
        }
コード例 #8
0
        public ActionResult Index()
        {
            //sanitize url
            string inputUrlParam;
            string cleanUrlParam;

            if (RouteData.Values["careerName"] == null)
            {
                return(Redirect("/careers/administrative-assistant"));
            }
            else
            {
                inputUrlParam = RouteData.Values["careerName"].ToString();
                cleanUrlParam = URLFriendly(inputUrlParam);

                if (!inputUrlParam.Equals(cleanUrlParam))
                {
                    return(Redirect(cleanUrlParam));
                }
            }

            var db = new CareersDataContext();
            //var careersArray = db.Careers.ToArray(); //The ToArray executes the SQL call.

            /*var careersArray = db.Careers.Where(u => u.IsActive == 1).Select(u => u.CareerName);
             * var careersIdArray = db.Careers.Where(u => u.IsActive == 1).Select(u => u.Id);
             * SelectList careers = new SelectList(careersArray); //change the array to a select list*/

            var  careersViewModel   = new CareersViewModel();
            bool careerNameUrlFound = false;

            string careerNameUrl = "";

            if (RouteData.Values["careerName"] != null)  //This is from RouteConfig, so make sure it is up to date!
            {
                careerNameUrl = RouteData.Values["careerName"].ToString();
                careerNameUrl = careerNameUrl.Replace("-", " ");
            }

            //var list = db.Careers.ToList();
            long careerId = 1;
            var  list     = db.Careers.Where(u => u.IsActive == 1).OrderBy(u => u.CareerName).ToList();
            List <SelectListItem> careersList = new List <SelectListItem>();

            for (int i = 0; i < list.Count(); i++)
            {
                careersList.Add(new SelectListItem
                {
                    Text  = list.ElementAt(i).CareerName,
                    Value = list.ElementAt(i).CareerName // change to this if you want the value to be the Id: list.ElementAt(i).Id.ToString()
                });

                if (list.ElementAt(i).CareerName.ToLower().Equals(careerNameUrl))
                {
                    careerNameUrlFound = true;
                    careersList.ElementAt(i).Selected = true;

                    //set ViewModel parameters
                    careersViewModel.CareerName  = list.ElementAt(i).CareerName;
                    careersViewModel.Description = list.ElementAt(i).Description;
                    careersViewModel.ImageUrl    = list.ElementAt(i).ImageUrl;

                    //set careerId to use in the list of stories below.
                    careerId = list.ElementAt(i).Id;
                }
            }

            ViewBag.careersList = careersList;

            if (!careerNameUrlFound)
            {
                return(Redirect("/careers/administrative-assistant")); //anything after careers/ that is not valid will be redirected to aa.
            }

            //get stories from selected career, sort, and put in viewbag.
            var careerStoriesList = db.Stories.Where(u => u.IsActive == 1 && u.CareerId == careerId).OrderByDescending(u => u.PostCount).ToList();

            ViewBag.careerStoriesList = careerStoriesList;

            return(View(careersViewModel));
        }
コード例 #9
0
        public ActionResult Create(StoriesCreateViewModel viewModelStories) //Look into ViewModels, more work but may be worth it.
        {
            //sanitize url
            string inputUrlParam;
            string cleanUrlParam;

            if (RouteData.Values["careerName"] == null)
            {
                return(Redirect("/careers/administrative-assistant"));
            }
            else
            {
                inputUrlParam = RouteData.Values["careerName"].ToString();
                cleanUrlParam = URLFriendly(inputUrlParam);

                if (!inputUrlParam.Equals(cleanUrlParam))
                {
                    return(Redirect(cleanUrlParam));
                }
            }

            bool careerNameUrlFound = false;

            string careerNameUrl = "";

            if (RouteData.Values["careerName"] != null)
            {
                careerNameUrl = RouteData.Values["careerName"].ToString();
                careerNameUrl = careerNameUrl.Replace("-", " ");
            }

            var db   = new CareersDataContext();
            var list = db.Careers.Where(u => u.IsActive == 1).ToList();

            for (int i = 0; i < list.Count(); i++)
            {
                if (list.ElementAt(i).CareerName.ToLower().Equals(careerNameUrl))
                {
                    careerNameUrlFound = true;
                }
            }

            if (!careerNameUrlFound)
            {
                return(Redirect("/careers/administrative-assistant")); //anything after careers/ that is not valid will be redirected to aa.
            }
            ////////////////////////end redirect check/////////////////////////////////////////////

            //This is how you get the current user id.
            string userId         = "";
            var    claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity != null)
            {
                // the principal identity is a claims identity.
                // now we need to find the NameIdentifier claim
                var userIdClaim = claimsIdentity.Claims
                                  .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                if (userIdClaim != null)
                {
                    userId = userIdClaim.Value;
                }
            }

            Stories stories = new Stories();

            stories.Title     = viewModelStories.Title;
            stories.Education = viewModelStories.Education;
            stories.Company   = viewModelStories.Company;
            stories.Salary    = viewModelStories.Salary;
            stories.Location  = viewModelStories.Location;
            stories.Story     = viewModelStories.Story;

            stories.CareerId   = getCareerId(RouteData.Values["careerName"].ToString().Replace("-", " "));
            stories.CareerName = RouteData.Values["careerName"].ToString().Replace("-", " ");
            stories.UserId     = userId; //MUST CHANGE to current user id!
            stories.Username   = User.Identity.Name;

            stories.PostDate         = DateTime.Now.ToString("M/dd/yy"); //account for time difference
            stories.StarCount        = 0;
            stories.PostCount        = 0;
            stories.FunnyCount       = 0;
            stories.InformativeCount = 0;
            stories.IsActive         = 1;

            if (stories.Title == null)
            {
                stories.Title = "";
            }
            if (stories.Education == null)
            {
                stories.Education = "";
            }
            if (stories.Company == null)
            {
                stories.Company = "";
            }

            if (ModelState.IsValid)
            {
                //Save to Database
                db = new CareersDataContext();
                db.Stories.Add(stories);
                db.SaveChanges();

                var id = stories.Id; //grabs the recently added story's id.

                //use StringBuilder here for optimization
                return(Redirect(@"~\" + "careers/" + RouteData.Values["careerName"].ToString() + "/" + id + "/" + stories.Title));
            }

            return(Create()); //returns to the Get Create action
        }