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 DeleteCategoryConfirmed(string category) { string userid = User.Identity.GetUserId(); PostTypesOps.DeletePostTypeByCategory(category, out StringBuilder error); return(RedirectToAction("Index")); }
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 })); }
public ActionResult Create([Bind(Include = "Category,SubCategory,Slug")] PostType postType) { if (ModelState.IsValid) { PostTypesOps.CreatePostTypes(postType.Category, postType.SubCategory, postType.Slug); return(RedirectToAction("Index")); } return(View(postType)); }
public ActionResult DeleteConfirmed(int id) { PostTypesOps.DeletePostTypeById(id, out StringBuilder errors); if (errors.Length > 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errors.ToString())); } return(RedirectToAction("Index")); }
public ActionResult GetSubCategoriesByCategory(string category) { var subCategories = PostTypesOps.GetSubCategoriesByCategory(category); var subCategorySelectItems = subCategories .Select(l => new SelectListItem { Value = l.Id.ToString(), Text = l.SubCategory }) .ToList(); // var subCategorySelectList = new SelectList(subCategorySelectItems, // "Value", "Text"); return(Json(subCategorySelectItems)); }
public ActionResult Edit(int id, [Bind(Include = "Category,SubCategory,Slug,Active")] PostType postType) { if (ModelState.IsValid) { postType.Id = id; PostTypesOps.UpdatePostType(postType, out StringBuilder errors); if (errors.Length > 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errors.ToString())); } return(RedirectToAction("Index")); } return(View(postType)); }
// GET: PostTypes/Edit/5 public ActionResult Edit(int?id) { if (!id.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostType postType = PostTypesOps.GetPostTypeById(id.Value); if (postType == null) { return(HttpNotFound()); } return(View(postType)); }
public ActionResult DeleteCategory(string category) { if (category == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostType postType = PostTypesOps.GetSubCategoriesByCategory(category)[0]; if (postType == null) { return(HttpNotFound()); } DeleteAreaOrCategoryViewModel v = new DeleteAreaOrCategoryViewModel(); v.Upper = postType.Category; 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) })); }
public ActionResult ListSubCategories(string category) { return(View(PostTypesOps.GetSubCategoriesByCategory(category))); }
// GET: PostTypes public ActionResult Index() { return(View(PostTypesOps.GetDistinctCategories())); }
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) })); }