public async Task <CategoryDetailsViewModel> GetAsync(string id, int pageIndex, int productsPerPage) { CoreValidator.ThrowIfNullOrWhitespace(id); var category = await this.categoryRepository.GetAsync(id); if (category == default(Category)) { return(null); } var products = await this.productRepository.GetByCategoryId(id); var productModels = products .Where(p => !p.IsDeleted) .Select(pr => this.customMapper.Map <Product, ProductConciseViewModel>(pr)) .AsQueryable() .ToPaginatedList(pageIndex, productsPerPage); foreach (var productModel in productModels) { productModel.CategoryName = category.Name; productModel.MainPictureUrl = (await this.pictureRepository.GetByProductId(productModel.Id)) .FirstOrDefault() ?.Url; } var model = this.customMapper.Map <Category, CategoryDetailsViewModel>(category); model.Products = productModels; return(model); }
public async Task <UserDeleteViewModel> GetForDeleteAsync(string userId) { CoreValidator.ThrowIfNullOrWhitespace(userId); var user = await this.userManager.FindByIdAsync(userId); if (user == null) { return(null); } return(this.customMapper.Map <User, UserDeleteViewModel>(user)); }
public async Task <ShoppingCartIndexViewModel> GetAsync(string browserId) { CoreValidator.ThrowIfNullOrWhitespace(browserId); var shoppingCart = await this.shoppingCartRepository.GetAsync(browserId); if (shoppingCart == null) { var newCart = this.shoppingCartFactory.CreateInstance(browserId); await this.shoppingCartRepository.AddAsync(newCart); shoppingCart = await this.shoppingCartRepository.GetAsync(browserId); } var model = this.customMapper.Map <ShoppingCart, ShoppingCartIndexViewModel>(shoppingCart); var modelItems = new List <OrderItemIndexViewModel>(); foreach (var item in shoppingCart.Items) { modelItems.Add(new OrderItemIndexViewModel { Count = item.Count, Product = new ProductShoppingCartViewModel { Id = item.Product.Id, Name = item.Product.Name, Price = item.Product.Price, Availability = item.Product.Availability, MainPictureUrl = (await this.pictureRepository.GetByProductId(item.Product.Id)) .FirstOrDefault() ?.Url, ShortDescription = item.Product.Description.Length > 50 ? item.Product.Description.Substring(0, 50) + "..." : item.Product.Description } }); } model.Items = modelItems.OrderBy(i => i.Product.Name).ToList(); return(model); }