//error handle view public ActionResult SingleCategory(CategoryArticleViewModel model) { if (StaticResources.CurrentCategory == 0) { RedirectToAction("Index", "Home"); } if (ModelState.IsValid) { var sortedModel = service.GetSorted_CAM((CategoriesInformation.CategoriesEnum)StaticResources.CurrentCategory, model.SortBar); return(View("Articles", sortedModel)); } return(SingleCategory(StaticResources.CurrentCategory)); }
public CategoryArticleViewModel GetCategoryArticleModel(CategoriesInformation.CategoriesEnum category) { var converted = GetStringCategoryFromEnum(category); var model = new CategoryArticleViewModel(); var additionalInfo = CategoriesInformation.GetAdditionalInformation(converted); model.PreviewModels = PreviewArticleModels(converted); model.SortBar = new SortBindingModel(); model.SortBar.SortByValues = new string[] { "Most recent", "Price (ascending)", "Price (descending)" }; var passArr = new string[] { "Any" }; if (additionalInfo != null) { Array.Resize(ref passArr, additionalInfo.Length + 1); Array.Copy(additionalInfo, 0, passArr, 1, additionalInfo.Length); } model.SortBar.TypeDropDownValues = passArr; return(model); }
public IActionResult Create(int?categoryId = null) { BEArticleViewModel bEArticleViewModel = new BEArticleViewModel(new SiocArticle() { Specificulture = CurrentLanguage, CreatedBy = User.Identity.Name, CreatedDateTime = DateTime.UtcNow }) { Status = SWStatus.Published }; if (categoryId.HasValue) { CategoryArticleViewModel categoryArticleViewModel = bEArticleViewModel.Categories.Find(c => c.CategoryId == categoryId); if (categoryArticleViewModel != null) { categoryArticleViewModel.IsActived = true; } } ViewBag.categoryId = categoryId; return(View(bEArticleViewModel)); }
public CategoryArticleViewModel GetSorted_CAM(CategoriesInformation.CategoriesEnum category, SortBindingModel model) { var converted = GetStringCategoryFromEnum(category); var returnModel = new CategoryArticleViewModel(); IEnumerable <ArticleDataModel> queryModel = context.Articles .Where(a => a.Category == converted); System.Diagnostics.Debug.WriteLine(string.Format("Search => {0} / Order => {1} / PriceF => {2} / PriceT => {3} / Category => {4} / querymodelISNULL = {5} / Type = {6}", model.Search != null ? model.Search : "NULL", model.SortBy, model.PriceLimitationFrom, model.PriceLimitationTo, converted, queryModel != null ? "No" : "Yes", model.Type)); #region querryModel != null if (queryModel != null) { if (model.Type != null && model.Type != "Any") { IEnumerable <ArticleDataModel> temp; temp = queryModel .Where(a => a.Type == model.Type); if (temp != null) { queryModel = temp; } } if (model.Search != null && model.Search != string.Empty) { IEnumerable <ArticleDataModel> temp; temp = queryModel .Where(a => a.Name.Contains(model.Search)); if (temp != null && temp.Count() > 0) { queryModel = temp; } } switch (model.SortBy) { case "Most recent": { queryModel = queryModel .OrderByDescending(a => a.UploadDate); } break; case "Price (ascending)": { queryModel = queryModel .OrderBy(a => a.Price); } break; case "Price (descending)": { queryModel = queryModel .OrderByDescending(a => a.Price); } break; } if (model.PriceLimitationTo != 0) { queryModel = queryModel .Where(a => (a.Price >= model.PriceLimitationFrom && a.Price <= model.PriceLimitationTo)); } } #endregion var mapped = MapArticles(queryModel); returnModel.PreviewModels = mapped; returnModel.SortBar = new SortBindingModel() { SortByValues = new string[] { "Most recent", "Price (ascending)", "Price (descending)" } }; return(returnModel); }