public async Task<IActionResult> productList(int categoryId = 0 , string productName = null) { var user = _userService.getIdentityUserByUserNameOrPhoneNumber(userName: User.Identity.Name); var vendor = await _roleService.IsUserInSpecificRole(user.Id, "Vendor"); var admin = await _roleService.IsUserInSpecificRole(user.Id, "Admin"); var vendorId = (vendor == true && !admin) ? user.Id : null; var products = _productService.getProductByCategoryIdList(categoryId, productName, vendorId:vendorId); var productsModel = _productModelFactory.getProductModelList(products); var productListModel = new ProductsListModel(); productListModel.ProductsModel = productsModel; return View("~/Admin/Views/Product/Product.cshtml",productListModel); }
public virtual ActionResult GetProductsList(ProductsListType listType, int?page, int?pageSize, int?catId, DateTime?fromDate, ViewStyles?style, NumberOfCol?numberOfCol, bool?showPager) { var currentUser = UserManager.FindById(User.Identity.GetUserId()); IPagedList <TblProducts> products = null; switch (listType) { case ProductsListType.Newest: products = _productService.GetNewItems(page ?? 1, pageSize ?? 24, catId, fromDate); break; case ProductsListType.MostPopular: products = _productService.GetPopularItems(page ?? 1, pageSize ?? 24, catId, fromDate); break; case ProductsListType.HotList: products = _productService.GetHotList(page ?? 1, pageSize ?? 24, catId, fromDate); break; case ProductsListType.Featured: products = _productService.GetFeaturedItems(page ?? 1, pageSize ?? 24, catId, fromDate); break; case ProductsListType.BestSelling: products = _productService.GetBestSelling(page ?? 1, pageSize ?? 24, catId, fromDate); break; case ProductsListType.MostDownloaded: products = _productService.GetMostDownloadedItems(page ?? 1, pageSize ?? 24, catId, fromDate); break; } var model = new ProductsListModel() { PostsList = _productModelFactory.PrepareProductCardViewModel(products, currentUser, Url), ViewStyle = style ?? ViewStyles.Normal, PageIndex = page ?? 1, PageSize = pageSize, PostsListType = listType, FromDate = fromDate, FilterByCategoryId = catId, ShowPager = showPager ?? true, NumberOfCol = numberOfCol ?? NumberOfCol.Four }; return(View("Partials/_ProductsList", model)); }
public void InsertProductList(ProductsListModel plm) { try { using (VenturadaDataContext vdc = new VenturadaDataContext()) { ProductsList receivedPM = new ProductsList(); receivedPM.MainDescription = plm.MainDescription; receivedPM.DetailsDescription = plm.DetailsDescription; vdc.ProductsLists.InsertOnSubmit(receivedPM); vdc.SubmitChanges(); } } catch (Exception ex) { throw ex; } }
public void UpdateProductList(ProductsListModel aum) { try { ProductsList au = new ProductsList(); using (VenturadaDataContext vdc = new VenturadaDataContext()) { au = vdc.ProductsLists.Single(a => a.ProductId == aum.ProductsId); au.ProductId = aum.ProductsId; au.MainDescription = aum.MainDescription; au.DetailsDescription = aum.DetailsDescription; vdc.SubmitChanges(); } } catch (Exception ex) { throw ex; } }
public ActionResult EditProduct(ProductsListModel plm) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ProductsDataService dataService = new ProductsDataService(); try { string id = (string)Request.Form["edit_ProductsId"]; if (ModelState.IsValid) { plm.ProductsId = int.Parse(id); dataService.UpdateProductList(plm); return(RedirectToAction("Edit", "Products")); } else { plm = new ProductsListModel(); plm.ProductsId = int.Parse(id); return(View(plm)); } } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public void Can_Send_Pagination_View_Model() { //arrange Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products) .Returns(new Product[] { new Product { ProductID = 1, Name = "P1" }, new Product { ProductID = 2, Name = "P2" }, new Product { ProductID = 3, Name = "P3" }, new Product { ProductID = 4, Name = "P4" }, new Product { ProductID = 5, Name = "P5" } }); ProductController controller = new ProductController(mock.Object); controller.PageSize = 3; //act ProductsListModel result = (ProductsListModel)controller.List(null, 2).Model; //assert PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(pageInfo.CurrentPage, 2); Assert.AreEqual(pageInfo.ItemsPerPage, 3); Assert.AreEqual(pageInfo.TotalItems, 5); Assert.AreEqual(pageInfo.TotalPage, 2); }
public ViewResult List(string category, int page = 1) { ProductsListModel model = new ProductsListModel { Products = repository.Products .Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null? repository.Products.Count() : repository.Products.Where(e => e.Category == category).Count() }, CurrentCategory = category }; return(View(model)); }
public ActionResult Add(ProductsListModel plm) { CommonDataService cds = new CommonDataService(); CommonModel cm = new CommonModel(); cm = cds.GenerateCommonModel(); Session["FaceBook"] = cm.FaceBook; Session["Twitter"] = cm.Twitter; Session["Youtube"] = cm.Youtube; Session["Instagram"] = cm.Instagram; Session["PhoneNumber"] = cm.PhoneNumber; Session["Email"] = cm.Email; Session["ShoppingHours"] = cm.ShoppingHours; ProductsDataService dataService = new ProductsDataService(); try { if (ModelState.IsValid) { dataService.InsertProductList(plm); return(RedirectToAction("Edit", "Products")); } else { return(View(plm)); } } catch (Exception ex) { throw ex; } finally { dataService = null; } }
public void Can_Paginate() { //arrange Mock <IProductRepository> mock = new Mock <IProductRepository>(); mock.Setup(m => m.Products) .Returns(new Product[] { new Product { ProductID = 1, Name = "P1" }, new Product { ProductID = 2, Name = "P2" }, new Product { ProductID = 3, Name = "P3" }, new Product { ProductID = 4, Name = "P4" }, new Product { ProductID = 5, Name = "P5" } }); ProductController controller = new ProductController(mock.Object); controller.PageSize = 3; //act ProductsListModel result = (ProductsListModel)controller.List(null, 2).Model; //assert Product[] prodArray = result.Products.ToArray(); Assert.IsTrue(prodArray.Length == 2); Assert.AreEqual(prodArray[0].Name, "P4"); Assert.AreEqual(prodArray[1].Name, "P5"); }
public ActionResult FindProducts(OrderDetailsModel model, int id) { List <Product> products; using (NorthwindConnection db = new NorthwindConnection()) { products = db.Products.Where(x => x.CategoryID == model.Product.CategoryID && x.UnitPrice >= model.MinPrice).ToList(); if (model.MaxPrice > 0) { products = products.Where(x => x.UnitPrice <= model.MaxPrice).ToList(); } if (model.Product.ProductName != null && model.Product.ProductName != "") { products = products.Where(x => x.ProductName.Contains(model.Product.ProductName)).ToList(); } } ProductsListModel plModel = new ProductsListModel { Products = products, OrderId = id }; return(PartialView("_ProductList", plModel)); }
public IndexModel(CategoryModel catalogTree, ProductsListModel products) { Products = products; CatalogTree = catalogTree; }
/// <summary> /// Implementation of Method. /// </summary> /// <param name="updateList">list.</param> /// <returns>value.</returns> public bool UpdateProductList(ProductsListModel updateList) { return(this.dal.UpdateProduct(updateList)); }
///// <summary> ///// Implementation of Method. ///// </summary> ///// <returns>value.</returns> // public List<ProductsListModel> GetProductsList() // { // return this.dal.GetProducts(); // } /// <summary> /// Implementation of Method. /// </summary> /// <param name="view">view.</param> /// <returns>value.</returns> public int InsertProducts(ProductsListModel view) { return(this.dal.InsertProducts(view)); }
/// <summary> /// Implemetntationof Method. /// </summary> /// <param name="deleteList">list.</param> /// <returns>value.</returns> public bool DeleteProducts(ProductsListModel deleteList) { return(this.dal.DeleteProduct(deleteList)); }
public IndexModel(CategoryModel catalogTree, ProductsListModel products) { Products = products; CatalogTree = catalogTree; }