예제 #1
0
        public IActionResult GetProducts(int page = 1)
        {
            var query = _context.Products.AsQueryable();
            //Thread.Sleep(2000);
            int pageSize = 4;
            int pageNo   = page - 1;

            var products = query
                           .OrderBy(p => p.Name)
                           .Skip(pageNo * pageSize)
                           .Take(pageSize)
                           .Select(p => new ProductViewModel
            {
                Id       = p.Id,
                Name     = p.Name,
                Category = p.Category.Name
            })
                           .ToList();

            int allCount           = query.Count();
            ProductPageModel model = new ProductPageModel
            {
                Data        = products,
                CurrentPage = page,
                TotalPage   = (int)Math.Ceiling((double)allCount / pageSize)
            };

            return(Ok(model));
        }
예제 #2
0
        public IActionResult Upsert(int?id)
        {
            ProductPageModel productPageModel = new ProductPageModel()
            {
                Product      = new Product(),
                CategoryList = _unitOfWork.Category.GetAll().Select(x => new SelectListItem {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                }),
                CoverTypeList = _unitOfWork.CoverType.GetAll().Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                })
            };

            if (id == null)
            {
                //this is to create product
                return(View(productPageModel));
            }
            //this is to edit
            productPageModel.Product = _unitOfWork.Product.Get(id.GetValueOrDefault());

            if (productPageModel.Product == null)
            {
                return(NotFound());
            }
            return(View(productPageModel));
        }
예제 #3
0
        public async Task <IActionResult> Search(ProductPageModel pageModel)
        {
            ViewData["Categories"] = new SelectList(await _categoryRepository.GetAllAsync(), "Id", "Name");

            pageModel.Products = await _productRepository.GeneralFilterAsync(pageModel.SearchCriteria);

            return(View("Products", pageModel));
        }
        public IActionResult Index(ProductSearchModel searchModel)
        {
            var response = _productOperations.GetProductListByFilters(searchModel);

            ProductPageModel products = new ProductPageModel {
                Products = _mapper.Map <List <ProductViewModel> >(response.Data)
            };

            return(View(products));
        }
예제 #5
0
        public async Task <IActionResult> Products()
        {
            ViewData["Categories"] = new SelectList(await _categoryRepository.GetAllAsync(), "Id", "Name");

            var products = await _productRepository.GetAllAsync();

            var model = new ProductPageModel
            {
                SearchCriteria = new ProductCriteriaModel(),
                Products       = products
            };

            return(View(model));
        }
예제 #6
0
        public async Task <ProductPageModel> GetScrubsOnCallPageAsync(string brand, string productCode)
        {
            ProductPageModel model = null;

            if (!string.IsNullOrEmpty(brand) && !string.IsNullOrEmpty(productCode))
            {
                if (brand.Equals("LN", StringComparison.OrdinalIgnoreCase))
                {
                    brand = "LAN";
                }
                else if (brand.Equals("UR", StringComparison.OrdinalIgnoreCase))
                {
                    brand = "UBN";
                }
                else if (brand.Equals("SN", StringComparison.OrdinalIgnoreCase))
                {
                    brand = "SMT";
                }

                var requestUrl = String.Format("https://eagle-pos.com/scrubsOnCall/include/php/detail.php?item={0}&vendor={1}", productCode, brand);

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(requestUrl));

                HttpResponseMessage response = await HttpClientHelper.SendAsync(request)
                                               .ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync()
                                  .ConfigureAwait(false);

                    var startPosition = (content.IndexOf("<title>") + "<title>".Length);
                    var endPosition   = (content.IndexOf("</title>") - startPosition);
                    var titleContent  = content.Substring(startPosition, endPosition);

                    if (titleContent.IndexOf(productCode) > 0)
                    {
                        model = new ProductPageModel
                        {
                            VendorId    = 3,
                            ProductCode = productCode,
                            ProductUrl  = requestUrl,
                            ColorCode   = null
                        };
                    }
                }
            }

            return(model);
        }
        public async Task <IHttpActionResult> GetProducts(int pageIndex, int itemsCountPerPage, string filterName = null)
        {
            try
            {
                var productModels = (await _productManagementService.GetProducts(pageIndex, itemsCountPerPage, filterName))
                                    .Select(p => p.ToProductModel()).ToList();
                var productCount = await _productManagementService.GetCount(filterName);

                var productsPage = new ProductPageModel(productCount, productModels);
                return(Ok(productsPage));
            }
            catch (Exception ex)
            {
                // Log exception
                return(InternalServerError());
            }
        }
예제 #8
0
        // GET: Home
        public ActionResult Index(PageModel pageModel)
        {
            var productsBelowReorder = (from prod in _context.Products
                                        join prodInv in _context.ProductInventories
                                        on prod.ProductID equals prodInv.ProductID
                                        where prodInv.Quantity < prod.ReorderPoint
                                        select new ProductViewModel()
            {
                ProductID = prod.ProductID,
                ProductName = prod.Name,
                ProductNumber = prod.ProductNumber,
                ListPrice = prod.ListPrice,
                LocationID = prodInv.LocationID,
                Quantity = prodInv.Quantity,
                ReorderPoint = prod.ReorderPoint
            }).ToList();

            var productsAboveReorder = (from prod in _context.Products
                                        join prodInv in _context.ProductInventories
                                        on prod.ProductID equals prodInv.ProductID
                                        where prodInv.Quantity >= prod.ReorderPoint
                                        select new ProductViewModel()
            {
                ProductID = prod.ProductID,
                ProductName = prod.Name,
                ProductNumber = prod.ProductNumber,
                ListPrice = prod.ListPrice,
                LocationID = prodInv.LocationID,
                Quantity = prodInv.Quantity,
                ReorderPoint = prod.ReorderPoint
            }).ToList();

            var model = new ProductPageModel(pageModel)
            {
                ProductsBelowReorder = productsBelowReorder.ToPagedList(pageModel.BelowReorderPage, pageModel.Size),
                ProductsAboveReorder = productsAboveReorder.ToPagedList(pageModel.AboveReorderPage, pageModel.Size)
            };

            return(View(model));
        }
예제 #9
0
 public ProductPage(int productId)
 {
     BindingContext = new ProductPageModel(productId, Navigation);
     InitializeComponent();
 }
예제 #10
0
        public ActionResult ProductDetailPage(ContentModel model, long?p)
        {
            if (!p.HasValue)
            {
                return(Redirect($"/{CurrentUser.LanguageCode}/page-not-found/"));
            }

            var ppModel = new ProductPageModel(model.Content);

            var fetched = UvendiaContext.Products.Single(p);

            if (fetched == null)
            {
                return(Redirect($"/{CurrentUser.LanguageCode}/page-not-found/"));
            }

            ppModel.SelectedVariant = fetched;

            if (fetched.IsVariant())
            {
                ppModel.Product      = fetched.Parent.Get();
                ppModel.SelectedSize = fetched["Size"] as string;
            }
            else
            {
                ppModel.Product = fetched;
            }

            ppModel.Images = ppModel.Product.Properties.Where(x => x.Property.DataType == DataType.CloudinaryImage && x.Value != null).Select(x => x.GetValue <string>());

            var categories = ppModel.Product.Categories.Select(c => c.Id).ToArray();

            ppModel.InterestingProducts = UvendiaContext.Products.GetTopInterestingProducts(8, categories);

            if (ppModel.Product.HasVariant)
            {
                bool hasSize = ppModel.Product.Variants.Any(x => x["Size"] != null);
                if (hasSize)
                {
                    ppModel.Sizes = new List <SelectListItem>();
                    foreach (var variant in ppModel.Product.Variants)
                    {
                        var item = new SelectListItem()
                        {
                            Text = variant["Size"] as string, Value = variant["Size"] as string
                        };
                        ppModel.Sizes.Add(item);

                        if (string.Equals(ppModel.SelectedSize, variant["Size"] as string))
                        {
                            ppModel.SelectedVariant = variant;
                        }
                    }
                    if (ppModel.SelectedSize == null)
                    {
                        ppModel.SelectedVariant = ppModel.Product.Variants[0];
                    }
                }
            }

            return(CurrentTemplate(ppModel));
        }
예제 #11
0
        public IActionResult Upsert(ProductPageModel productPageModel)
        {
            if (ModelState.IsValid)
            {
                string webRootPath = _hostEnvironment.WebRootPath;

                var files = HttpContext.Request.Form.Files;

                if (files.Count > 0)
                {
                    string fileName  = Guid.NewGuid().ToString();
                    var    upload    = Path.Combine(webRootPath, @"images\products");
                    var    extension = Path.GetExtension(files[0].FileName);

                    if (productPageModel.Product.ImageUrl != null)
                    {
                        // this is an edit and we need to remove old image

                        var imagePath = Path.Combine(webRootPath, productPageModel.Product.ImageUrl.TrimStart('\\'));
                        if (System.IO.File.Exists(imagePath))
                        {
                            System.IO.File.Delete(imagePath);
                        }
                    }
                    using (var filesStreams = new FileStream(Path.Combine(upload, fileName + extension), FileMode.Create))
                    {
                        files[0].CopyTo(filesStreams);
                    }

                    productPageModel.Product.ImageUrl = @"\images\products\" + fileName + extension;
                }
                else
                {
                    // Update when image is not Changed
                    if (productPageModel.Product.Id != 0)
                    {
                        Product objFromDb = _unitOfWork.Product.Get(productPageModel.Product.Id);
                        productPageModel.Product.ImageUrl = objFromDb.ImageUrl;
                    }
                }

                if (productPageModel.Product.Id == 0)
                {
                    _unitOfWork.Product.Add(productPageModel.Product);
                }
                else
                {
                    _unitOfWork.Product.Update(productPageModel.Product);
                }

                _unitOfWork.Complete();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                productPageModel.CategoryList = _unitOfWork.Category.GetAll().Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                });
                productPageModel.CoverTypeList = _unitOfWork.CoverType.GetAll().Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                });
            }
            if (productPageModel.Product.Id != 0)
            {
                productPageModel.Product = _unitOfWork.Product.Get(productPageModel.Product.Id);
            }
            return(View(productPageModel));
        }
 public ProductPageViewModel(ProductPageModel currentPage) : base(currentPage)
 {
     _currentPage = currentPage;
 }