public async Task <IActionResult> Index(AllProductsViewModel model) { Rating rating = model.NewRating; // Register rating with current date rating.RateDate = DateTime.UtcNow; rating.UserEmail = User.Identity.Name; rating.UserId = User.UserId(); // Request new token and store rating var token = await webAPIToken.New(); var apiResponse = await webAPI.PostAsync <Rating>(rating, ApiURL.RATINGS_POST, token); // Was new rating saved successfully? if (apiResponse.Status.IsSuccessStatusCode) { TempData["NewRatingSaved"] = true; } else { TempData["NewRatingFailed"] = true; } return(RedirectToAction("ProductDetail", "Product", new { id = rating.ProductId })); }
public async Task <IActionResult> ConvertToPdfAllZeroProducts(DateTime startDate, DateTime endDate) { string idString = string.Empty; this.memoryCache.TryGetValue("ClientSelected", out idString); object clientName; this.memoryCache.TryGetValue("ClientName", out clientName); var products = new AllProductsViewModel(); Guid id = new Guid(idString); products.Products = this.productService.GetAllZeroProducts <ProductViewModel>(id, startDate, endDate, null, null, 0, true); products.ClientName = clientName.ToString(); foreach (var p in products.Products) { var sum = p.Qty * p.SinglePrice; products.TotalSum += sum; } var htmlData = await this.viewRenderService.RenderToStringAsync("~/Views/Products/IndexForZeroPdf.cshtml", products); var fileContents = this.htmlToPdfConverter.Convert("wwwroot/js/", htmlData); return(this.File(fileContents, "application/pdf;charset=utf-8")); }
protected void ShowAllProducts() { var workspace = new AllProductsViewModel(); this.Workspaces.Add(workspace); this.SetActiveWorkspace(workspace); }
//// //// Get: /Store/CategoryDetails/?categoryId=X //public ActionResult CategoryDetails(Int32 categoryId = 0) //{ // if (categoryId == 0) // return RedirectToAction("Index"); // var cat = _categoryService.GetCategoryWithChildCategories(categoryId); // if (cat == null) // return RedirectToAction("Index"); // ViewBag.CurrentCategoryID = cat.CategoryID; // if (cat.ChildCategories.Any()) // { // //var model = new BranchCategoryIndexViewModel(); // //model.CurrentCategory = Mapper.Map<CategoryViewModel>(cat); // //model.Categories = Mapper.Map<List<CategoryViewModel>>(cat.ChildCategories.Take(3)); // return View("BranchCategory");//, model); // } // else // { // var model = new LeafCategoryViewModel(); // model.CurrentCategory = Mapper.Map<CategoryViewModel>(cat); // //TODO take random products // model.Products = Mapper.Map<List<ProductViewModel>>(_prodService.GetAllByCategoryIdWithImages(cat.CategoryID).Take(3)); // return View("LeafCategory", model); // } //} //// //// GET: /Store/AllCategories/?categoryId=X //public ActionResult AllCategories(Int32 parentCategoryId = 0, Int32 pageNumber = 1) //{ // ViewBag.CurrentCategoryID = parentCategoryId; // IPagedList<CategoryViewModel> cats; // if (parentCategoryId == 0) // cats = Mapper.Map<List<CategoryViewModel>>(_categoryService.GetAll()).ToPagedList(pageNumber, 9); // else // cats = Mapper.Map<List<CategoryViewModel>>(_categoryService.GetAll().Where(c => c.ParentCategoryID == parentCategoryId)).ToPagedList(pageNumber, 9); // return View(cats); //} // // GET: /Store/AllProducts/?categoryId= public ActionResult AllProducts(AllProductsViewModel model) { IEnumerable <Product> products; if (model.CategoryId != 0) { products = _productService.GetByCategoryIdWithImages(model.CategoryId); } else { products = _productService.GetAllWithImages(); } if (!products.Any()) { return(RedirectToAction("Index")); } //Ordering if (model.OrderBy != ProductOrderingOptions.None) { if (!model.OrderByDescending) { if (model.OrderBy == ProductOrderingOptions.DateAdded) { products = products.OrderBy(p => p.Price); } if (model.OrderBy == ProductOrderingOptions.Price) { products = products.OrderBy(p => p.Price); } } else { if (model.OrderBy == ProductOrderingOptions.DateAdded) { products = products.OrderByDescending(p => p.Price); } if (model.OrderBy == ProductOrderingOptions.Price) { products = products.OrderByDescending(p => p.Price); } } } else { products = products.OrderBy(p => p.UnitsInStock); } model.ProductsList = ((IOrderedEnumerable <Product>)products).ToPagedList(model.PageNumber, 9); model.ProductOrderingOptions = Enum.GetValues(typeof(ProductOrderingOptions)).Cast <ProductOrderingOptions>().ToList(); setCurrentCategoryId(model.CategoryId); return(View(model)); }
//Method Name: Index //Purpose of the Method: This method is the first method that is loaded when a user visits Bangazon. This method will get all of the products in the database and show them on the homepage. //Arguments in Method: None. public async Task <IActionResult> Index() { AllProductsViewModel model = new AllProductsViewModel(context); model.Products = await context.Product.ToListAsync(); return(View(model)); }
public async Task <IActionResult> AllProducts(string sort = null) { var ProductsViewModel = new AllProductsViewModel(); var products = await _productRepository.GetProductList(sort); ProductsViewModel.Products = _mapper.Map <IEnumerable <ProductToList> >(products); return(View(ProductsViewModel)); }
public async Task <IActionResult> All() { var products = await this.productService.GetAllProducts(); AllProductsViewModel model = new AllProductsViewModel { Products = products.ToList() }; return(this.View(model)); }
public IActionResult Index() { if (this.User.Identity.IsAuthenticated) { AllProductsViewModel viewModel = this.productService.GetAllProducts(this.User.Identity.Name); return(View(viewModel)); } else { return(View()); } }
//GET: Products public IActionResult Index() { List <Product> products = _context.Product .OrderBy(p => p.Title) .ToList(); AllProductsViewModel viewModel = new AllProductsViewModel(); viewModel.AllProducts = products; return(View(viewModel)); }
// // GET: /Store/AllProducts/?categoryId=X public ActionResult AllProducts(AllProductsViewModel model) { ViewBag.CurrentCategoryID = model.CategoryID; IEnumerable <Product> products; if (model.CategoryID != 0) { products = _prodService.GetAllByCategoryIdWithImages(model.CategoryID); } else { products = _prodService.GetAllWithImages(); } //Ordering if (model.OrderBy != ProductOrderingOptions.None) { if (!model.OrderByDescending) { if (model.OrderBy == ProductOrderingOptions.DateAdded) { products = products.OrderBy(p => p.UnitPrice); } if (model.OrderBy == ProductOrderingOptions.Price) { products = products.OrderBy(p => p.UnitPrice); } } else { if (model.OrderBy == ProductOrderingOptions.DateAdded) { products = products.OrderByDescending(p => p.UnitPrice); } if (model.OrderBy == ProductOrderingOptions.Price) { products = products.OrderByDescending(p => p.UnitPrice); } } } else { products = products.OrderBy(p => p.UnitsInStock); } model.ProductsList = ((IOrderedEnumerable <Product>)products).ToPagedList(model.PageNumber, 9); return(View(model)); }
//GET: Products/?search="iPod" public IActionResult Search(string search) { List <Product> products = _context.Product //Gets all products from database .Where(p => p.Title.Contains(search)) //Filters the ones thats that contain what the search contains .OrderBy(p => p.Title) //Orders them in alphabetical order .ToList(); //Turns results into a list AllProductsViewModel viewModel = new AllProductsViewModel(); //Creates new view model viewModel.AllProducts = products; //Attaches the searched products to the view model return(View(viewModel)); //Sends the view model to the view }
public HttpResponse Index() { if (!this.IsUserLoggedIn()) { return(this.View()); } AllProductsViewModel allProductsViewModel = new AllProductsViewModel(); allProductsViewModel.Products = this.productsService.GettAllProducts(); return(this.View(allProductsViewModel, "Home")); }
public IActionResult All(string filter = "", int page = 1) { if (TempData != null) { if (TempData.Keys.Contains("AmmountError") && TempData["AmmountError"] != null) { ViewBag.ProductId = TempData["ProductId"]; ViewBag.AmmountError = TempData["AmmountError"]; } if (TempData.Keys.Contains("UserError") && TempData["UserError"] != null) { ViewBag.ProductId = TempData["ProductId"]; ViewBag.AmmountError = "You own this."; } } if (page <= 0) { page = 1; } AllProductsViewModel model = new AllProductsViewModel(); if (page % 3 == 0) { model.FirstPage = page - 2; } else { model.FirstPage = page / 3 > 0 ? page / 3 * 3 + 1: 1; } if (model.FirstPage <= 0) { model.FirstPage = 1; } model.Products = repository.GetAll().Skip((page - 1) * 9).Where(x => filter == "" || x.Category.ToString() == filter || filter == "All").Take(9).ToList(); model.Page = page; model.selectListItems = new List <SelectListItem>(); string[] array = { "None", "Price Down", "Price Up", "Rating Down", "Rating Up", "Name Down", "Name Up" }; int count = 0; foreach (var item in Enum.GetNames(typeof(Filters))) { model.selectListItems.Add(new SelectListItem(array[count], item)); ++count; } model.selectListCategory = new List <SelectListItem>(); foreach (var item in Enum.GetNames(typeof(Category))) { model.selectListCategory.Add(new SelectListItem(item, item)); } return(View(model)); }
public IActionResult GetAll() { var viewModel = new AllProductsViewModel { Products = this.productService.GetAll <ProductViewModel>(), }; if (viewModel == null) { return(this.NotFound()); } return(this.View(viewModel)); }
public IHttpResponse All() { var viewModel = new AllProductsViewModel(); viewModel.AllProducts = this.Db.Products.Select(x => new SimpleProductViewModel { Name = x.Name, Barcode = x.Barcode.ToString(), Price = x.Price.ToString("F2"), Picture = string.IsNullOrEmpty(x.Picture) ? "/product.png" : x.Picture }).ToList(); return(this.View(viewModel)); }
public AllProductsViewModel GetProducts() { var products = new AllProductsViewModel(); products.Products = db.Products .Select(x => new ProductViewModel { Name = x.Name, Price = x.Price, Barcode = x.Barcode, Image = x.PictureUrl }) .ToList(); return(products); }
//Method Name: ProductsInSubType //Purpose of the Method: This method gets all the products in a selected subtype and returns them. //Arguments in Method: Gets the subtypeId from the route. public async Task <IActionResult> ProductsInSubType([FromRoute] int id) { AllProductsViewModel model = new AllProductsViewModel(context); model.Products = await context.Product.Where(p => p.SubProductTypeId == id).ToListAsync(); model.SubProductType = await context.SubProductType.Where(p => p.SubProductTypeId == id).SingleOrDefaultAsync(); if (model.Products == null) { return(NotFound()); } return(View(model)); }
public IActionResult ByCategory(string categoryName) { if (!this.categoriesService.Exist(categoryName)) { return(this.BadRequest()); } this.ViewBag.CategoryName = categoryName; var allProductsViewModel = new AllProductsViewModel { Products = this.productsService.GetAll <ProductsViewModel>(categoryName), }; return(this.View(allProductsViewModel)); }
public IActionResult All(int id, int?pageNumber) { var nextPage = pageNumber ?? GlobalConstants.NextPageValue; var products = this.productService.GetProductsByCategory(id); var mappedProducts = this.mapper.Map <IEnumerable <ProductViewModel> >(products); var pagedProducts = mappedProducts.ToPagedList(nextPage, GlobalConstants.MaxProductsOnPage); var productsViewModel = new AllProductsViewModel { Products = pagedProducts }; return(this.View(productsViewModel)); }
public IActionResult All() { var products = this.productsService.GetAllProducts(); var model = new AllProductsViewModel(); var allProductDetailsViewModel = model.AllProductsDetails = new List <AllProductsDetailsViewModel>(); foreach (var product in products) { var image = this.imageService.ReturnProductImage(product.Image); var token = mapper.Map <AllProductsDetailsViewModel>(product); token.Image = image; allProductDetailsViewModel.Add(token); } return(View(model)); }
public IActionResult Index() { DataTable dt = this.dataLayer.GetAllProducts(); string ProductsTable = "<table><tr><td><B>Product ID</B></td><td><B>Product Name</B></td><td><B>Description</B></td></tr>"; foreach (DataRow dr in dt.Rows) { ProductsTable += "<tr><td>" + dr[0] + "</td><td>" + dr[1] + "</td><td>" + dr[2] + "</td></tr>"; } ProductsTable += "</table>"; var model = new AllProductsViewModel { ProductsTable = new HtmlString(ProductsTable) }; return(View(model)); }
public IActionResult FillingSuggestion(string productName) { var allFireplaces = this.fireplaceService.GetAllFireplace <IndexFireplaceViewModel>(); var allFinishedModels = this.finishedModelService.GetAll <IndexFinishedModelViewModel>(); var allProjects = this.projectService.GetAll <IndexProjectViewModel>(); var allAccessorie = this.accessoriesService.GetAllAccessorieAsync <IndexAccessorieViewModel>(); this.TempData["fireplaceForFill"] = productName; var allProducts = new AllProductsViewModel { Fireplaces = allFireplaces, FinishedModels = allFinishedModels, Projects = allProjects, Accessories = allAccessorie, }; return(this.View(allProducts)); }
public AllProductsViewModel GetAll() { var products = context .Products .Select(p => new SingleProductViewModel() { Id = p.Id, Name = p.Name, Description = p.Description, Price = p.Price }); var model = new AllProductsViewModel() { Products = products }; return(model); }
public IHttpResponse All() { var productsViewModel = Db.Products .Select(p => new ProductViewModel { Id = p.Id, Name = p.Name, Price = p.Price, Barcode = p.Barcode, Picture = p.Picture }) .ToList(); var allProducts = new AllProductsViewModel { ProductViewModels = productsViewModel }; return(View(allProducts)); }
public IActionResult UserProduct(AllProductsViewModel viewModel) { int page = viewModel.Page; string category = viewModel.Category.ToString(); if (page <= 0) { page = 1; } AllProductsViewModel model = new AllProductsViewModel(); if (page % 3 == 0) { model.FirstPage = page - 2; } else { model.FirstPage = page / 3 > 0 ? page / 3 * 3 + 1 : 1; } if (model.FirstPage <= 0) { model.FirstPage = 1; } string id = userRepository.GetByUsername(User.Identity.Name).Id; model.Products = repository.GetUserProducts(id).Skip((page - 1) * 9).Where(x => category == "" || x.Category.ToString() == category || category == "All").ToList(); model.selectListItems = new List <SelectListItem>(); string[] array = { "None", "Price Down", "Price Up", "Rating Down", "Rating Up", "Name Down", "Name Up" }; int count = 0; foreach (var item in Enum.GetNames(typeof(Filters))) { model.selectListItems.Add(new SelectListItem(array[count], item)); ++count; } model.selectListCategory = new List <SelectListItem>(); foreach (var item in Enum.GetNames(typeof(Category))) { model.selectListCategory.Add(new SelectListItem(item, item)); } return(View(model)); }
public IHttpResponse ProductsAll() { var products = this.Db.Products .Select(p => new ProductViewModel { Name = p.Name, Price = p.Price, Barcode = p.Barcode, Picture = p.Picture, Id = p.Id }) .ToList(); var model = new AllProductsViewModel { Products = products }; return(View(model)); }
public IActionResult All() { var product = this.productServices.GetAllProducts().Select(x => new ProductViewModel { Id = x.Id, Title = x.Title, Author = x.Author, Description = x.Description, ISBN = x.ISBN, Price = x.Price, ProductTypes = x.ProductTypes.ToString(), Publishing = x.Publishing, Quantity = x.Quantity, YearOfPublishing = x.YearOfPublishing }).ToList(); AllProductsViewModel products = new AllProductsViewModel(); products.Products.AddRange(product); return(View(products)); }
public HttpResponse Index() { if (this.IsUserLoggedIn()) { var products = new AllProductsViewModel { Products = productService.GetProducts().Select(x => new ProductInfoViewModel() { Id = x.Id, Name = x.Name, ImageUrl = x.ImageUrl, Price = x.Price }) }; return(this.View(products, "Home")); } return(this.View()); }
public AllProductsViewModel GetAllProducts(string userId) { var products = GetProducts().ToList(); var model = this.GetProducts() .Select(x => new ProductViewModel { Name = x.Name, Price = x.Price, }).ToList(); var allProductsModel = new AllProductsViewModel { Products = model, Total = products.Sum(x => x.Price), }; return(allProductsModel); }
public IActionResult IndexZeroProducts(DateTime startDate, DateTime endDate, int page = 1, string search = null) { string idString = string.Empty; this.memoryCache.TryGetValue("ClientSelected", out idString); object clientName; this.memoryCache.TryGetValue("ClientName", out clientName); var products = new AllProductsViewModel(); if (idString != null || (startDate != DateTime.MinValue && endDate != DateTime.MinValue)) { Guid id = new Guid(idString); products.Products = this.productService.GetAllZeroProducts <ProductViewModel>(id, startDate, endDate, search, ItemsPerPage, (page - 1) * ItemsPerPage, false); } else { products.Products = this.productService.GetAllZeroProducts <ProductViewModel>(search, ItemsPerPage, (page - 1) * ItemsPerPage); } if (clientName == null) { clientName = "Не е избран клиент"; } products.ClientName = clientName.ToString(); var count = this.productService.GetCount(); products.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage); if (products.PagesCount == 0) { products.PagesCount = 1; } products.CurrentPage = page; return(this.View(products)); }