public ActionResult Create(
            [Bind(Include = "Title,Body,SelectedArea,SelectedLocale,SelectedCategory,SelectedSubcategory")]
            PostViewModel post)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var postType = PostTypesOps.GetPostTypeById(int.Parse(post.SelectedSubcategory));
                    var location = LocationOps.GetLocationById(int.Parse(post.SelectedLocale));

                    UserPost.CreatePost(User.Identity.GetUserId(), post.Title, post.Body,
                                        post.SelectedCategory, postType.SubCategory, post.SelectedArea,
                                        location.Locale);

                    return(RedirectToAction("Index"));
                }

                return(View(post));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public ActionResult Index(string area     = "New York", string locale = "",
                                  string category = "", string subcategory    = "")
        {
            if (!string.IsNullOrEmpty(category) || !string.IsNullOrEmpty(subcategory))
            {
                return(RedirectToAction("Index", "PostFilter",
                                        new { area, locale, category, subcategory }));
            }

            var areas = LocationOps.GetDistinctAreas()
                        .Select(a => a.Area)
                        .ToList();

            var locales          = new List <string>();
            var activeCategories = PostTypesOps.GetActivePostTypesList();

            if (!string.IsNullOrEmpty(area))
            {
                locales = LocationOps.GetLocalesByArea(area)
                          .Select(l => l.Locale)
                          .ToList();
            }

            locales.Sort();

            return(View(new HomePageViewModel(activeCategories)
            {
                Area = area,
                Areas = areas,
                Locales = locales,
                Locale = locale
            }));
        }
Beispiel #3
0
        public ActionResult DeleteAreaConfirmed(string area)
        {
            string userid = User.Identity.GetUserId();

            LocationOps.DeleteLocationByArea(area, out StringBuilder error);
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Area,Locale,Slug")] Location location)
        {
            if (ModelState.IsValid)
            {
                LocationOps.CreateLocation(location.Area, location.Locale, location.Slug);
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
Beispiel #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            LocationOps.DeleteLocationById(id, out StringBuilder errors);

            if (errors.Length > 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errors.ToString()));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #6
0
        public ActionResult GetLocalesByArea(string area)
        {
            var locales           = LocationOps.GetLocalesByArea(area);
            var localeSelectItems = locales
                                    .Select(l => new SelectListItem {
                Value = l.Id.ToString(),
                Text  = l.Locale
            })
                                    .ToList();

//            var localesSelectList = new SelectList(localeSelectItems,
//                "Value", "Text");

            return(Json(localeSelectItems));
        }
Beispiel #7
0
        // GET: Locations/Edit/5
        public ActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Location location = LocationOps.GetLocationById(id.Value);

            if (location == null)
            {
                return(HttpNotFound());
            }

            return(View(location));
        }
Beispiel #8
0
        public ActionResult Edit(int id, [Bind(Include = "Area,Locale,Slug,Active")] Location location)
        {
            if (ModelState.IsValid)
            {
                location.Id = id;
                LocationOps.UpdateLocation(location, out StringBuilder errors);

                if (errors.Length > 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errors.ToString()));
                }

                return(RedirectToAction("ListLocale", routeValues: new { area = location.Area }));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid Location Data"));
        }
Beispiel #9
0
        public ActionResult DeleteArea(string area)
        {
            if (area == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Location location = LocationOps.GetLocalesByArea(area).FirstOrDefault();

            if (location == null)
            {
                return(HttpNotFound());
            }
            DeleteAreaOrCategoryViewModel v = new DeleteAreaOrCategoryViewModel();

            v.Upper = location.Area;
            return(View(v));
        }
        public ActionResult Create(string area     = "", string locale      = "",
                                   string category = "", string subcategory = "")
        {
            var locations = LocationOps.GetActiveLocationsList();
            var postTypes = PostTypesOps.GetActivePostTypesList();

            var categories = new List <string>
            {
                "Please Select a Category"
            };

            categories.AddRange(postTypes
                                .GroupBy(p => p.Category)
                                .Select(l => l.Key)
                                .ToList());

            var areas = new List <string>
            {
                "Please Select an Area"
            };

            areas.AddRange(locations
                           .GroupBy(l => l.Area)
                           .Select(l => l.Key)
                           .ToList());

            var subcategories = new List <string> {
                "Please Select a Category"
            };
            var locales = new List <string> {
                "Please Select a Locale"
            };

            if (string.IsNullOrEmpty(category) && !string.IsNullOrEmpty(subcategory))
            {
                category = PostTypesOps.GetCategoryBySubcategoryName(subcategory);
            }

            if (string.IsNullOrEmpty(area) && !string.IsNullOrEmpty(locale))
            {
                area = LocationOps.GetAreaByLocale(locale);
            }

            if (!string.IsNullOrEmpty(category))
            {
                subcategories.AddRange(PostTypesOps.GetSubCategoriesByCategory(category)
                                       .Select(s => s.SubCategory)
                                       .OrderBy(l => l)
                                       .ToList());
            }

            if (!string.IsNullOrEmpty(area))
            {
                locales.AddRange(LocationOps.GetLocalesByArea(area)
                                 .Select(l => l.Locale)
                                 .OrderBy(l => l)
                                 .ToList());
            }

            return(View(new PostViewModel
            {
                Areas = new SelectList(areas, string.IsNullOrEmpty(area) ? "Please Select an Area" : area),
                Locales = new SelectList(locales, string.IsNullOrEmpty(locale) ? "Please Select a Locale" : locale),
                Categories = new SelectList(categories, string.IsNullOrEmpty(category) ? "Please Select a Category" : category),
                SubCategories = new SelectList(subcategories, string.IsNullOrEmpty(subcategory) ? "Please Select a Subcategory" : subcategory)
            }));
        }
Beispiel #11
0
 //Get: Locations/{area}
 public ActionResult ListLocale(string area)
 {
     return(View(LocationOps.GetLocalesByArea(area).ToList()));
 }
Beispiel #12
0
 // GET: Locations
 public ActionResult Index()
 {
     return(View(LocationOps.GetDistinctAreas()));
 }
Beispiel #13
0
        public ActionResult Index(string area   = "", string category    = "",
                                  string locale = "", string subcategory = "",
                                  string query  = "", string pageAction  = "")
        {
            if (!int.TryParse(pageAction, out var pageNo))
            {
                pageNo = 1;
            }

            var selectedArea        = string.IsNullOrEmpty(area) ? "Please Select an Area" : area;
            var selectedLocale      = string.IsNullOrEmpty(locale) ? "Please Select a Locale" : locale;
            var selectedCategory    = string.IsNullOrEmpty(category) ? "Please Select a Category" : category;
            var selectedSubcategory = string.IsNullOrEmpty(subcategory) ? "Please Select a Subcategory" : subcategory;

            var actualArea        = area.Equals("Please Select an Area") ? "" : area;
            var actualLocale      = locale.Equals("Please Select a Locale") ? "" : locale;
            var actualCategory    = category.Equals("Please Select a Category") ? "" : category;
            var actualSubcategory = subcategory.Equals("Please Select a Subcategory") ? "" : subcategory;
            var posts             = PostFilter.FilterPost(actualArea, actualLocale,
                                                          actualCategory, actualSubcategory, query);

            var filteredPosts = posts
                                .Select(p => new PostViewModel
            {
                Id          = p.Id,
                Title       = p.Title,
                Body        = p.Body,
                Area        = p.Location.Area,
                Locale      = p.Location.Locale,
                Category    = p.PostType.Category,
                Subcategory = p.PostType.SubCategory,
                CreateDate  = p.CreateDate.ToString("MMM dd")
            }).ToList();

            var pageSize = 10;

            ViewBag.PageSize  = pageSize;
            ViewBag.PageCount = Convert.ToInt32(Math.Ceiling(filteredPosts.Count * 1.0 / pageSize));

            if (pageNo < 1)
            {
                pageNo = 1;
            }

            if (pageNo > ViewBag.PageCount)
            {
                pageNo = ViewBag.PageCount;
            }

            ViewBag.CurrentPage = pageNo;

            var pagedPosts    = filteredPosts.Skip((pageNo - 1) * pageSize).Take(pageSize);
            var subcategories = new List <string> {
                selectedSubcategory
            };
            var locales = new List <string> {
                selectedLocale
            };

            if (string.IsNullOrEmpty(actualCategory) && !string.IsNullOrEmpty(actualSubcategory))
            {
                actualCategory   = PostTypesOps.GetCategoryBySubcategoryName(actualSubcategory);
                selectedCategory = actualCategory;
            }

            if (string.IsNullOrEmpty(actualArea) && !string.IsNullOrEmpty(actualLocale))
            {
                actualArea   = LocationOps.GetAreaByLocale(actualLocale);
                selectedArea = actualArea;
            }

            if (!string.IsNullOrEmpty(actualCategory))
            {
                subcategories.AddRange(PostTypesOps.GetSubCategoriesByCategory(actualCategory)
                                       .Select(s => s.SubCategory)
                                       .OrderBy(l => l)
                                       .ToList());
            }

            if (!string.IsNullOrEmpty(actualArea))
            {
                locales.AddRange(LocationOps.GetLocalesByArea(actualArea)
                                 .Select(l => l.Locale)
                                 .OrderBy(l => l)
                                 .ToList());
            }

            return(View(new PostFilterViewModel
            {
                Query = query,
                Posts = pagedPosts.ToList(),
                Categories = new SelectList(Categories, selectedCategory),
                Areas = new SelectList(Areas, selectedArea),
                SubCategories = new SelectList(subcategories, selectedSubcategory),
                Locales = new SelectList(locales, selectedLocale)
            }));
        }