public async Task <List <Product> > ProductsAsync(List <Category> SubCategories) { List <Product> producData = new List <Product>(); foreach (Category category in SubCategories) { GetProducts filterProducts = new GetProducts { page_number = 0, language_id = 1, categories_id = category.id, type = "a to z" }; ProductData data = await App.oServiceManager.getAllProducts(filterProducts); if (!data.success.Equals("1")) { await Application.Current.MainPage.DisplayAlert("Notificación", data.message, "Aceptar"); } else { data.product_data.ForEach(x => x.products_image = (Constants.urlApi + x.products_image)); producData.AddRange(data.product_data); } } return(producData); }
public IEnumerable <Product> Handle(GetProducts command) { var products = _repository.FindAll <Product>(p => command.ProductIds.Contains(p.Id)) .ToList(); return(products); }
public void GetProducts_ReturnsAllProducts_WhenIdsAreNotProvided() { //Arrange var products = new List <Product> { new Product { CatalogNumber = 1 }, new Product { CatalogNumber = 2 } }; var productsRepositoryMock = new Mock <IProductsRepository>(); productsRepositoryMock .Setup(x => x.GetAllAsync()) .Returns(Task.FromResult(products as IEnumerable <Product>)); var service = new ProductsServices(productsRepositoryMock.Object); var request = new GetProducts(); //Act var response = (GetProductsResponse)service.GetAsync(request).Result; //Assert Assert.AreEqual(2, response.Products.Count); Assert.AreEqual(1, response.Products[0].CatalogNumber); Assert.AreEqual(2, response.Products[1].CatalogNumber); }
public void OnGet() { Products = new GetProducts(_ctx, _discounts).Do(new GetProductsQuery { UserId = GetUserId() }); UserLists = new GetLists(_ctx).Do(GetUserId()); }
public IActionResult GetCount( [FromServices] GetProducts getProducts) { int count = getProducts.GetProductsCount().Result; return(Ok(count)); }
public IActionResult Index(string search, string filter, int sid, int page = 1) { GetProducts getProducts = new GetProducts(); ViewBag.Class = ""; var config = new MapperConfiguration(cfg => cfg.CreateMap <ReviewVM, ReviewDto>()); var mapper = new Mapper(config); var products = getProducts.products = _userService.GetProducts(0, search, filter, sid).Select(x => new AddProductVM() { UploadPath = System.IO.File.Exists(Path.Combine(webHostEnvironment.WebRootPath, "images/" + x.ImagePath)) ? "/images/" + x.ImagePath : "/images/noimage.png", ProductName = x.ProductName, ProductId = x.Id, Price = x.Price.ToString(), DiscountPrice = (x.Price - x.Price * x.Discount / 100).ToString(), Reviews = mapper.DefaultContext.Mapper.Map <ReviewVM>(_userService.GetProductReview(x.Id)) }).ToList(); getProducts.total = products.Count(); getProducts.page = page; ViewBag.page = page; ViewBag.filter = filter ?? "Popular"; ViewBag.search = search; getProducts.products = products.Skip((page - 1) * 12).Take(12).ToList(); ViewBag.menu = JsonConvert.SerializeObject(GetCategory()); return(View(getProducts)); }
public async Task <IEnumerable <ProductViewModel> > GetProducts() { GetProducts getProduct = new GetProducts(_context); var result = await getProduct.Do(); return(result); }
public async Task <PagingProductModel> GetProductsAsync(GetProducts query) { var skip = (query.Page - 1) * query.PageSize; string sql = $@"WITH pg AS (SELECT Products.Id, c = COUNT(*) OVER() FROM Products ORDER BY Products.Id OFFSET {query.PageSize} * {skip} ROWS FETCH NEXT {query.PageSize} ROWS ONLY) SELECT dbo.Products.Id,Brand,Color,CreateTime,[Description],Discount,Expiration,DiscountPrice,ForBaby,Gender,IsDeleted,[Name],Price,Quantity,ProductType,[Weight],Size,Images.[Url],Images.MainImage,Images.Id AS ImgId,Images.ProductId FROM Products LEFT JOIN Images ON dbo.Products.Id=Images.ProductId INNER JOIN pg ON pg.Id= dbo.Products.Id WHERE IsDeleted=0;"; await using var connection = new SqlConnection(_connectionString); await using var command = new SqlCommand(sql, connection); await connection.EnsureIsOpenAsync().ConfigureAwait(false); await using var reader = await command.ExecuteReaderAsync().ConfigureAwait(false); var products = new List <ProductReadModel>(20); products = await ProductListReaderAsync(reader, products).ConfigureAwait(false); var totalCount = await GetAllProductCountAsync(new GetAllProductCount()).ConfigureAwait(false); var pageCount = CountPages(query.PageSize, totalCount); return(new PagingProductModel(products, pageCount, query.Page)); }
public async Task <ProductData> getAllProducts(GetProducts getProducts) { var uri = new Uri(Constants.urlApi + "getAllProducts"); ProductData allProducts = new ProductData(); if (App.CurrentConetion()) { try { var dataPost = JsonConvert.SerializeObject(getProducts); var content = new StringContent(dataPost, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await client.PostAsync(uri, content); var request = await response.Content.ReadAsStringAsync(); allProducts = JsonConvert.DeserializeObject <ProductData>(request); } catch (Exception ex) { Debug.WriteLine(@"ERROR {0}", ex.Message); } } return(allProducts); }
public void Should_work() { // Arrange var command = new GetProducts(); var entity1 = new Product { Id = 1, Description = "test1", Name = "test1" }; var entity2 = new Product { Id = 2, Description = "test2", Name = "test2" }; var entity3 = new Product { Id = 3, Description = "test3", Name = "test3" }; var products = new List <Product>() { entity1, entity2, entity3 }.AsQueryable(); var fakeDbSet = new Mock <DbSet <Product> >(); fakeDbSet.Setup(dbs => dbs.AsQueryable()).Returns(products); var fakeDbContext = new Mock <BasicDbContext>(new DbContextOptionsBuilder().Options); fakeDbContext.Setup(dbc => dbc.Set <Product>()).Returns(fakeDbSet.Object); // Act var res = new ProductRepository(fakeDbContext.Object).All(); // Assert fakeDbSet.Verify(x => x.AsQueryable(), Times.Once()); Assert.Equal(products.Count(), res.Count()); }
public IActionResult GetCountBuCategoryId( Guid?categoryId, [FromServices] GetProducts getProducts) { int count = getProducts.GetProductsCount(categoryId).Result; return(Ok(count)); }
public AdminProductsBlazorService(GetProducts getProducts, GetProduct getProduct, CreateProduct createProduct, DeleteProduct deleteProduct, UpdateProduct updateProduct) { _getProducts = getProducts; _getProduct = getProduct; _createProduct = createProduct; _deleteProduct = deleteProduct; _updateProduct = updateProduct; }
public async Task <IActionResult> GetProducts(string category, [FromServices] GetProducts getProducts, [FromServices] GetProductsByCategory getProductsByCategory) { if (!string.IsNullOrWhiteSpace(category)) { return(Ok(await getProductsByCategory.Do(category, 0, 100))); } return(Ok(await getProducts.Do(0, 100))); }
public void Handle(GetProducts command) { var products = _domainRepository.FindAll <Product>(p => command.ProductIds.Contains(p.Id)) .Select(p => new Project { Id = p.Id, Name = p.Name, Count = p.Count }) .ToList(); _commandContext.Reply = products; }
public void OnGet() { var products = new GetProducts(_ctx).Do(); if (!string.IsNullOrEmpty(SearchString)) { products = products.Where(s => s.Name.ToLower().Contains(SearchString.ToLower())); } Products = products; }
public GetProductsService() { getproducts = new GetProducts(); getproducts.GetSingleValueFromJoinTable(); getproducts.GetDoubleValueFromJoinTable(); spropertyidposition = new List<int>(); dpropertyidposition = new List<int>(); singlevaluedata = new List<DataRow>(); doublevaluedata = new List<DataRow>(); }
public IActionResult Index([FromServices] GetProducts getProducts) { var vm = new SummariesIndexViewModel(); var products = getProducts.GetAllProducts(); vm.DiscountsFood = products.Where(x => x.Category == "Markety Spożywcze").OrderByDescending(item => item.Discount).Take(15).ToList(); vm.DiscountsDiy = products.Where(x => x.Category == "Markety Budowlane").OrderByDescending(item => item.Discount).Take(15).ToList(); return(View(vm)); }
public async Task <IEnumerable <ProductDto> > HandleAsync(GetProducts query) { var from = Builders <ProductDocument> .Filter.Gte("Price", query.PriceFrom ?? 0); var to = Builders <ProductDocument> .Filter.Lte("Price", query.PriceTo ?? decimal.MaxValue); var products = await database.GetCollection <ProductDocument>("products") .Find(from & to).ToListAsync(); return(products.Select(x => x.AsDto())); }
//returns all the Products public ProductsResponse Get(GetProducts request) { //get data from the database List <Product> products = ProductRepository.GetAll(); //transform to ProductsResponse and return. return(new ProductsResponse() { Products = ProductMapper.ToProductResponseList(products) }); }
public async Task <IEnumerable <ProductDto> > HandleAsync(GetProducts query) { var products = await _productsRepository.GetProducts(query); return(products.Select(p => new ProductDto() { Id = p.Id, Name = p.Name, Price = p.Price, Description = p.Description }).ToList()); }
// GET: Product public ActionResult Index(GetProducts ProductContext) { try { List <ProductModell> loadedProducts = ProductContext.GetProduct(); return(View(loadedProducts)); } catch (Exception e) { return(View()); } }
public void GetProducts_ReturnsResponseContainingAllObjects_WhenIdsAreNotProvided(int expectedNumberOfProducts, Func <Product, bool> match) { //Arrange var client = CreateClient(); var getProducts = new GetProducts(); //Act var getProductsResponse = client.Get(getProducts); //Assert Assert.AreEqual(expectedNumberOfProducts, getProductsResponse.Products.Count); Assert.That(getProductsResponse.Products.All(p => match(p))); }
public void OnGet( [FromServices] GetProducts getProducts, [FromServices] GetCategories getCategories, int pageNumber = 1, int pageSize = PageZize) { IndexViewModel = new IndexViewModel { Products = getProducts.Do(pageNumber, pageSize), Categories = getCategories.Do() }; var taskCount = getProducts.GetProductsCount(); int count = taskCount.Result; PageViewModel = new PageViewModel(count, pageNumber, PageZize); }
public async Task<object> GetAsync(GetProducts request) { IEnumerable<Product> products; if(request.Ids == null || request.Ids.Length == 0) { products = await _productsRepository.GetAllAsync(); } else { products = await _productsRepository.GetByIdsAsync(request.Ids); } return new GetProductsResponse { Products = products.ToList() }; }
public Task <PagingProductModel> HandleAsync(GetProducts query) { if (query.Page <= 0) { query.Page = 1; } if (query.PageSize <= 0) { query.PageSize = 10; } return(_readRepository.GetProductsAsync(query)); }
public List <ProductResponse> Get(GetProducts request) { return(new List <ProductResponse> { new ProductResponse { Id = 1, Name = "Product", Status = new Status { Id = 1, Name = "Active" } } }); }
protected override IEnumerable <GetProductItemResult> Handle(GetProducts request) { var machine = _vendingMachineProvider.GetVendingMachine(); var products = machine.GetProductsWithPrices() .Select(kvp => new GetProductItemResult( kvp.Key.ToString(), string.Format("{0:N2} Euro", (decimal)kvp.Value / 100) )); var amount = (decimal)machine.GetAmountToBePaid() / 100; return(products); }
public async Task <IEnumerable <Product> > GetProducts(GetProducts query) { var from = Builders <Product> .Filter.Gte("price", query.PriceFrom == null ? 0 : query.PriceFrom); var to = Builders <Product> .Filter.Lte("price", query.PriceTo == null ?decimal.MaxValue : query.PriceTo); return(await _products.Find(from& to).ToListAsync()); }
// GET: Product/Details/5 public ActionResult Details(Guid id, GetProducts ProductContext) { List <ProductModell> loadedProducts = ProductContext.GetProduct(); ProductModell loadedProducts2 = new ProductModell(); foreach (ProductModell Modell in loadedProducts) { if (Modell.productID == id) { loadedProducts2 = Modell; } } return(View(loadedProducts2)); }
public async Task <IActionResult> OnGet( [FromServices] GetProducts getProducts, [FromServices] CountProducts countProducts, int p, string c) { bool filter = !string.IsNullOrWhiteSpace(c); int count; if (filter) { count = await countProducts.Do(c); } else { count = await countProducts.Do(); } int pages = (int)Math.Ceiling((decimal)count / productsPerPage); if (p < 1) { return(RedirectToPage("Shop", new { p = 1, c })); } if (pages != 0 && p > pages) { return(RedirectToPage("Shop", new { p = pages, c })); } if (filter) { Products = await getProducts.Do( c, (p - 1) *productsPerPage, productsPerPage); } else { Products = await getProducts.Do( (p - 1) *productsPerPage, productsPerPage); } PageNumber = p; PageCount = pages; return(Page()); }