Esempio n. 1
0
        public ActionResult Create(ProductAdvice productAdvice, FormCollection form)
        {
            if (productAdvice.ProductsId == null)
            {
                ModelState.AddModelError("ProductsId", "Please choose a product.");
            }
            ValidateAdvice(productAdvice);
            productAdvice.MentorId = CurrentMentor.Id;

            if (ModelState.IsValid)
            {
                try
                {
                    //_adviceApplicationService.AddProductAdvice(CurrentMentor, productAdvice);
                    _productAdviceApplicationService.SaveProductAdvice(productAdvice);
                    return(RedirectToAction("Index", "Advice"));
                }
                catch
                {
                    return(RedirectToAction("Create"));
                }
            }
            var products = _productApplicationService.GetAllProducts();

            ViewData["Products"]   = new SelectList(products, "Id", "ProductName", productAdvice.ProductsId);
            ViewData["Semaphores"] = _semaphoreApplicationService.GetAllSemaphores();
            SetAdviceTagViewData();
            return(View(productAdvice));
        }
Esempio n. 2
0
        public JsonResult GetProducts(int?page, int?rows, string sidx, string sord, string searchMask)
        {
            var products = _productApplicationService.GetAllProducts();

            if (!string.IsNullOrEmpty(searchMask))
            {
                long temp;
                if (long.TryParse(searchMask, out temp))
                {
                    products = (from product in products
                                where product.GlobalTradeItemNumber.StartsWith(searchMask)
                                select product).ToList();
                }
                else
                {
                    products = (from product in products
                                where product.ProductName.ToLower().Contains(searchMask.ToLower())
                                select product).ToList();
                }
            }
            var productInfo = from product in products
                              select new
            {
                product.Id,
                product.ProductName,
                product.GlobalTradeItemNumber,
                product.Brand.BrandName
            };

            page = page.HasValue ? page.Value - 1 : 0;

            var data = productInfo.AsQueryable().ToPagedList(page.Value, rows ?? 10);

            double totalCount = data.TotalCount;
            double pageSize   = data.PageSize;
            var    jsonData   = new
            {
                total   = Math.Round(totalCount / pageSize, MidpointRounding.AwayFromZero),
                page    = data.PageIndex + 1,
                records = data.TotalCount,
                rows    = data
            };

            return(Json(jsonData));
        }
Esempio n. 3
0
        private async Task <SelectList> LoadProducts()
        {
            var allProducts = await _productApplicationService.GetAllProducts();

            Dictionary <Guid, string> dictProducts = new Dictionary <Guid, string>();

            allProducts.ForEach(x => {
                dictProducts.Add(x.Id, x.Name);
            });

            SelectList products = new SelectList(
                dictProducts.Select(x => new { Value = x.Key, Text = x.Value }),
                "Value",
                "Text"
                );

            return(products);
        }
Esempio n. 4
0
 public ActionResult <List <ProductModel> > GetAllProducts()
 {
     return(CustomResponse(_productApplicationService.GetAllProducts()));
 }
 public IHttpActionResult GetAll()
 {
     return(Ok(_productApplicationService.GetAllProducts()));
 }
Esempio n. 6
0
        public async Task <ActionResult <List <ProductResponseViewModel> > > GetAll()
        {
            var products = await _productApplicationService.GetAllProducts();

            return(Response(products));
        }