コード例 #1
0
        public async Task <IActionResult> ProductMgn(string typeId)
        {
            ProductManagementViewModel productMgnVM = new ProductManagementViewModel();
            var productTypes = await _dbContext.Category.Where(x => x.CateID == typeId).ToListAsync();

            productMgnVM.Types = _mapper.Map <List <ProductTypeViewModel> >(productTypes);

            return(View(productMgnVM));
        }
コード例 #2
0
        public ActionResult Index()
        {
            if (ModelState.IsValid)
            {
                using (var context = new ShoppingCartContext())
                {
                    var productCategories = new ProductManagementViewModel();

                    var categories = context.Categories.ToList();

                    //var defaultCat = categories.First();

                    //var prods = from p in context.Products
                    //            where p.Categories.Any(c => c.Code == defaultCat.Code)
                    //            select p;

                    var prods = context.Products;
                    //productCategories.Products.AddRange(prods);
                    //                  where cartItems.Code == ShoppingCartId
                    foreach (var prod in prods)
                    {
                        productCategories.Products.Add(new ProductViewModel()
                        {
                            Code        = prod.Code,
                            Description = prod.Description,
                            Image       = prod.Image,
                            //ImageAlt0 = prod.ImageAlt0,
                            //ImageAlt1 = prod.ImageAlt1,
                            Id             = prod.Id,
                            Active         = prod.Active,
                            QuantityOnHand = prod.QuantityOnHand
                        });
                    }

                    foreach (var product in productCategories.Products)
                    {
                        var catList =
                            context.Products.Where(p => p.Id == product.Id)
                            .SelectMany(prod => prod.Categories).ToList();
                        if (catList.Any())
                        {
                            product.CategoriesString =
                                catList.Select(c => c.Description).ToList().Aggregate((i, j) => i + "," + j);
                        }
                        else
                        {
                            product.CategoriesString = "";
                        }
                    }

                    return(View(productCategories));
                }
            }
            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> ProductTypeMgn(string newItem)
        {
            ProductManagementViewModel productMgnVM = new ProductManagementViewModel();
            var productTypes = await _dbContext.Category.ToListAsync();

            var products = await _dbContext.Product.ToListAsync();

            productMgnVM.Types = _mapper.Map <List <ProductTypeViewModel> >(productTypes);
            if (newItem != null)
            {
                productMgnVM.CreateSuccess = newItem;
            }

            return(View(productMgnVM));
        }
コード例 #4
0
        public async Task <IActionResult> ProductManagement(int id)
        {
            try
            {
                var model = new ProductManagementViewModel()
                {
                    RootUrl          = BaseRootUrl,
                    SelectedGarageId = id,
                    Products         = await _optionService.GetProductList(id)
                };


                return(View(model));
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                return(BadRequest());
            }
        }
コード例 #5
0
        public async Task <IActionResult> ProductManagementList(int id)
        {
            try
            {
                if (id == 0)
                {
                    throw new ApplicationException("ProductManagementList - Id should ne be set to 0");
                }

                var model = new ProductManagementViewModel()
                {
                    Products = await _optionService.GetProductList(id)
                };
                return(PartialView("_products", model));
            }
            catch (Exception ex)
            {
                ex.ToExceptionless().Submit();
                return(BadRequest());
            }
        }
コード例 #6
0
        public ActionResult FilterByCategory(string code)
        {
            if (code == "All")
            {
                return(RedirectToAction("Index"));
            }

            var catDescription = "";
            var prods          = new List <Product>();

            using (var context = new ShoppingCartContext())
            {
                prods = (from p in context.Products
                         where p.Categories.Any(c => c.Code == code)
                         select p).ToList();
                catDescription = context.Categories.Single(c => c.Code == code).Description;
            }
            using (var context = new ShoppingCartContext())
            {
                var productCategories = new ProductManagementViewModel();
                foreach (var prod in prods)
                {
                    productCategories.Products.Add(new ProductViewModel()
                    {
                        Code             = prod.Code,
                        Description      = prod.Description,
                        Image            = prod.Image,
                        Id               = prod.Id,
                        Active           = prod.Active,
                        QuantityOnHand   = prod.QuantityOnHand,
                        CategoriesString = catDescription,
                    });
                }

                productCategories.SelectedCategory = code;

                return(View("Index", productCategories));
            }
        }
コード例 #7
0
        public ActionResult SearchProduct(ProductManagementViewModel productCategories)
        {
            using (var context = new ShoppingCartContext())
            {
                if (productCategories.SearchProductId.IsNullOrWhiteSpace())
                {
                    return(RedirectToAction("Index"));
                }
                var prods =
                    context.Products.Where(
                        p =>
                        productCategories.SearchProductId.Contains(p.Code) ||
                        productCategories.SearchProductId.Contains(p.Description));


                var categories = context.Categories.ToList();
                var defaultCat = categories.First();

                foreach (var prod in prods.Take(12))
                {
                    productCategories.Products.Add(new ProductViewModel()
                    {
                        Code        = prod.Code,
                        Description = prod.Description,
                        Image       = prod.Image,
                        Id          = prod.Id
                    });
                }
                //no thing return
                if (prods.ToList().Count == 0)
                {
                    ViewBag.Status = "No product matched the search criteria";
                }
                return(View("Index", productCategories));
            }
        }
コード例 #8
0
 public ProductManagementUserControl()
 {
     InitializeComponent();
     DataContext = new ProductManagementViewModel();
 }
コード例 #9
0
        public async Task <IActionResult> ProductManagement(ProductManagementViewModel productMngViewModel)
        {
            productMngViewModel.product = await _dbContext.Product.ToListAsync();

            return(View(productMngViewModel));
        }