public async Task <IActionResult> Wishlist(int page = 1) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (page <= 0) { return(Redirect("/User/Wishlist")); } var adsCount = await userAdWishlistService.GetWishlistCountAsync(userId); var lastPage = adsCount / GlobalConstants.AdsOnPageCount + 1; if (adsCount % GlobalConstants.AdsOnPageCount == 0 && adsCount > 0) { lastPage -= 1; } if (page > lastPage) { return(Redirect("/User/Wishlist")); } var ads = await userAdWishlistService.GetUserWishlistAsync(userId, page, GlobalConstants.AdsOnPageCount); var viewModel = new WishlistViewModel { CurrentPage = page, TotalAdsCount = adsCount, LastPage = lastPage, }; foreach (var ad in ads) { var category = await categoryService.GetByIdAsync(ad.CategoryId); var subCategoryName = await subCategoryService.GetByIdAsync(ad.SubCategoryId); var town = await townService.GetByIdAsync(ad.TownId); viewModel.Advertisements.Add(new WishlistAdViewModel { Category = $"{category.Name} -> {subCategoryName.Name}", CreatedOn = ad.CreatedOn.ToString(GlobalConstants.DateTimeFormat), Id = ad.Id, Name = ad.Name, Price = ad.Price, UserId = ad.UserId, UserName = userManager.FindByIdAsync(ad.UserId).GetAwaiter().GetResult().UserName }); } return(View(viewModel)); }
public async Task <IActionResult> Edit(int id) { var editingSubCategory = await _subCategoryService.GetByIdAsync(id); if (editingSubCategory != null) { var subCategory = _mapper.Map <SubCategoryUpdateDto>(editingSubCategory); subCategory.CategoryList = new SelectList(await _categoryService.GetListAsync(), "Id", "Name", id); return(View(subCategory)); } return(BadRequest()); }
// GET: Admin/SubCategories/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SubCategory subCategory = await _subcategoryService.GetByIdAsync(Convert.ToInt32(id)); if (subCategory == null) { return(HttpNotFound()); } var subcategoryDetails = Mapper.Map <SubCategory, SubCategoryResource>(subCategory); return(View(subcategoryDetails)); }
//[AcceptVerbs("GET", "HEAD", Route = "{slug}")] public async Task <IActionResult> Blog(int?id) { var subCategoryControl = await _subCategoryService.GetByIdAsync(id.GetValueOrDefault()); if (subCategoryControl != null) { ViewData["BlogCategoryName"] = subCategoryControl.Name; return(View(_mapper.Map <List <BlogGeneralDto> >(await _blogService.GetListWithAllPropByFilterAsync(x => x.SubCategoryId == id)))); } return(View(_mapper.Map <List <BlogGeneralDto> >(await _blogService.GetListWithAllPropAsync()))); }
public async Task <IViewComponentResult> InvokeAsync() { var userId = userManager.GetUserId(HttpContext.User); var ads = await advertisementService.GetLatestAsync(8, userId); var result = new List <ViewModels.Advertisement.ListingViewModel>(); foreach (var ad in ads) { var category = await categoryService.GetByIdAsync(ad.CategoryId); string subCategoryName = null; if (await subCategoryService.ContainsByIdAsync(ad.SubCategoryId)) { var subCategory = await subCategoryService.GetByIdAsync(ad.SubCategoryId); subCategoryName = subCategory.Name; } var town = await townService.GetByIdAsync(ad.TownId); var adViewModel = new ViewModels.Advertisement.ListingViewModel { Address = ad.Address, CategoryName = category.Name, CreatedOn = ad.CreatedOn.ToString(GlobalConstants.DateTimeFormat), Id = ad.Id, Name = ad.Name, Price = ad.Price, SubCategoryName = subCategoryName, TownName = town.Name, Image = ad.Images.FirstOrDefault() }; result.Add(adViewModel); } return(View(result)); }
public async Task <IActionResult> GetByCategory(string categoryId, string orderBy = "dateDesc", int page = 1) { if (page <= 0) { return(Redirect("/Home/Index")); } var adsCount = await advertisementService.GetCountByCategoryIdAsync(categoryId); var lastPage = adsCount / GlobalConstants.AdsOnPageCount + 1; if (adsCount % GlobalConstants.AdsOnPageCount == 0 && adsCount > 0) { lastPage -= 1; } if (page > lastPage) { return(Redirect("/Home/Index")); } var ads = await advertisementService.GetByCategoryIdAsync(categoryId, page, GlobalConstants.AdsOnPageCount, orderBy); ads = OrderAds(ads, orderBy); var result = new ListingPageViewModel(); result = await GetCategoriesAndSubCategoriesAsync(result); foreach (var ad in ads) { var category = await categoryService.GetByIdAsync(ad.CategoryId); string subCategoryName = null; if (await subCategoryService.ContainsByIdAsync(ad.SubCategoryId)) { var subCategory = await subCategoryService.GetByIdAsync(ad.SubCategoryId); subCategoryName = subCategory.Name; } var town = await townService.GetByIdAsync(ad.TownId); var adViewModel = new ListingViewModel { Address = ad.Address, CategoryName = category.Name, CreatedOn = ad.CreatedOn.ToString(GlobalConstants.DateTimeFormat), Id = ad.Id, Name = ad.Name, Price = ad.Price, SubCategoryName = subCategoryName, TownName = town.Name, Image = ad.Images.FirstOrDefault(), IsPromoted = ad.IsPromoted, }; result.Advertisements.Add(adViewModel); } result.CurrentPage = page; result.LastPage = lastPage; result.TotalAdsCount = adsCount; result.GetByParam = "GetByCategory"; result.OrderParam = "orderBy=" + orderBy; result.PageParam = "categoryId=" + categoryId; return(View("Listing", result)); }