public IActionResult OnGetUploads(int productIda) { var model = new List <UploadViewModel>(); var uploads = _uploadRepository.GetProductUploads(productIda); foreach (var item in uploads) { model.Add(new UploadViewModel() { Id = item.Id, FileName = item.FileName, Path = Url.Content(item.Path) }); } return(new JsonResult(model)); }
public IActionResult OnGet(int id, string toastr, bool error = false) { var model = _productRepository.GetProduct(id); if (model == null) { return(RedirectToPage("/Index")); } Id = model.Id; Name = model.Name; Stock = (int)model.Quantity; Description = model.Description; IsOnSale = (bool)model.IsOnSale; Price = (decimal)_productRepository.GetCurrentPrice(id).Price1; if (IsOnSale) { SalePrice = (decimal)_productRepository.GetSalePrice(id).Price1; } var categories = _categoryRepository.GetProductCategories(id); var i = 0; foreach (var item in categories) { if (i == 0) { Categories = item.Category.Name; } else { Categories += ", " + item.Category.Name; } } var uploads = _uploadRepository.GetProductUploads(id); foreach (var item in uploads) { Uploads.Add(new UploadViewModel() { FileName = item.FileName, Path = item.Path }); } var product = _productRepository.GetProducts().Where(p => p.Id != id).Take(4); foreach (var item in product) { Products.Add(new ProductListViewModel() { Id = item.Id, ImagePath = Url.Content(_uploadRepository.GetProductThumbnail(item.Id).Path), IsOnSale = (bool)item.IsOnSale, SalePrice = _productRepository.GetSalePrice(item.Id) != null ? (decimal)_productRepository.GetSalePrice(item.Id).Price1 : 0.00M, Price = (decimal)_productRepository.GetCurrentPrice(item.Id).Price1, Title = item.Name, Url = "/Producti/" + item.Id }); } if (!String.IsNullOrEmpty(toastr) && !error) { ViewData["Success"] = toastr; } if (!String.IsNullOrEmpty(toastr) && error) { ViewData["Error"] = toastr; } return(Page()); }