Example #1
0
        public ActionResult Detail(string id)
        {
            try
            {
                ProductDetailViewModels model = new ProductDetailViewModels();
                if (!string.IsNullOrEmpty(id))
                {
                    var dataDetail = _fac.GetDetail(id);
                    if (dataDetail != null)
                    {
                        dataDetail.ListImages = _fac.GetListImageOfProduct(id);
                        if (dataDetail.ListImages != null)
                        {
                            dataDetail.ListImages.ForEach(x =>
                            {
                                x.ImageURL = Commons.HostImage + "Products/" + x.ImageURL;
                            });
                        }
                        dataDetail.ListImages = dataDetail.ListImages.OrderBy(x => x.ImageURL).Skip(0).Take(4).ToList();

                        var oldData = _fac.GetList().Where(x => !x.Id.Equals(id) && x.CategoryId.Equals(dataDetail.CategoryId)).OrderBy(x => x.CreatedDate).Skip(0).Take(5).ToList();
                        if (oldData != null && oldData.Any())
                        {
                            var dataImage = _fac.GetListImage();
                            oldData.ForEach(x =>
                            {
                                var _Image = dataImage.FirstOrDefault(y => y.ProductId.Equals(x.Id));
                                if (_Image != null)
                                {
                                    if (!string.IsNullOrEmpty(_Image.ImageURL))
                                    {
                                        x.ImageURL = Commons.HostImage + "Products/" + _Image.ImageURL;
                                    }
                                }
                            });
                        }

                        model.ListProduct = oldData;
                        model.Product     = dataDetail;
                        return(View(model));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                //NSLog.Logger.Error("GetDetail: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
        public ActionResult PropertiesDetail(string id)
        {
            ProductDetailViewModels model = new ProductDetailViewModels();

            if (!string.IsNullOrEmpty(id))
            {
                var data    = _factoryPro.GetListProduct();
                var oldData = data.Where(x => !x.ID.Equals(id)).OrderBy(x => x.CreatedDate).Skip(0).Take(3).ToList();
                oldData.ForEach(x =>
                {
                    if (!string.IsNullOrEmpty(x.ImageURL))
                    {
                        x.ImageURL = Commons.HostImage + x.ImageURL;
                    }
                });
                var dataDetail = data.Where(x => x.ID.Equals(id)).FirstOrDefault();
                if (dataDetail != null)
                {
                    if (!string.IsNullOrEmpty(dataDetail.ImageURL))
                    {
                        dataDetail.ImageURL = Commons.HostImage + dataDetail.ImageURL;
                    }
                    if (dataDetail.ListImg != null)
                    {
                        dataDetail.ListImg.ForEach(x =>
                        {
                            x.ImageURL = Commons.HostImage + x.ImageURL;
                        });
                    }
                    model.ListProduct = oldData;
                    model.Product     = dataDetail;

                    //// get list location
                    var _location = _factoryLoc.GetListLocation();
                    _location.ForEach(x =>
                    {
                        x.Total = data.Count(z => z.LocationID.Equals(x.ID));
                    });
                    model.ListLocation = _location;
                    return(View(model));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Example #3
0
        // GET: Product
        public ActionResult Index(string product_id)
        {
            NSLog.Logger.Info("Request_Product_Index", product_id);
            var models = new ProductDetailViewModels();

            try
            {
                if (string.IsNullOrEmpty(product_id))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                var _product = _fac.GetDetail(product_id);
                if (_product != null)
                {
                    var data = _fac.GetList().Where(o => o.ProductTypeCode == (int)CMS_Common.Commons.EProductType.Product && o.IsActive).ToList();
                    if (data != null)
                    {
                        /* get list product by category */
                        models.ListProduct = data.Where(o => o.CategoryId.Equals(_product.CategoryId) && !o.Id.Equals(product_id)).ToList();
                        /* get top 3 product new */
                        models.ProductNew = data.OrderByDescending(x => x.CreatedDate).Skip(0).Take(3).ToList();
                        /* get list product category */
                        var _cate = _facCate.GetListProductCate();
                        models.Product = _product;
                        if (models.Product != null)
                        {
                            models.Product.ImageURL = models.Product.ListImages != null && models.Product.ListImages.Count > 0 ? models.Product.ListImages.FirstOrDefault().ImageURL : "";
                        }
                        models.Categories = _cate;
                    }
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Index Product", ex);
            }
            return(View(models));
        }
        public ActionResult SearchKeyWord(ProductDetailViewModels model)
        {
            var modelView = new ProductViewModels();

            if (string.IsNullOrEmpty(model.KeyWord))
            {
                model.KeyWord = "";
            }
            var data = _factoryPro.GetListProduct()
                       .Where(x => CommonHelper.RemoveUnicode(x.Name.ToLower()).Contains(CommonHelper.RemoveUnicode(model.KeyWord.ToLower())))
                       .OrderByDescending(x => x.CreatedDate)
                       .ToList();

            data.ForEach(x =>
            {
                if (!string.IsNullOrEmpty(x.ImageURL))
                {
                    x.ImageURL = Commons.HostImage + x.ImageURL;
                }
            });
            modelView.ListProduct = data;
            return(View("Search", modelView));
        }
Example #5
0
        public ActionResult ProductDetail(string id)
        {
            try
            {
                ProductDetailViewModels model = new ProductDetailViewModels();
                if (!string.IsNullOrEmpty(id))
                {
                    var data = _fac.GetListProduct();

                    var dataDetail = data.Where(x => x.ID.Equals(id)).FirstOrDefault();
                    if (dataDetail != null)
                    {
                        if (!string.IsNullOrEmpty(dataDetail.ImageURL))
                        {
                            dataDetail.ImageURL = Commons.HostImage + dataDetail.ImageURL;
                        }
                        //else
                        //    dataDetail.ImageURL = Commons.Image400_250;
                        if (dataDetail.ListImg != null)
                        {
                            dataDetail.ListImg.ForEach(x =>
                            {
                                x.ImageURL = Commons.HostImage + x.ImageURL;
                            });
                            dataDetail.ListImg.Add(new ImageProduct
                            {
                                ImageURL = dataDetail.ImageURL
                            });
                        }
                        else
                        {
                            dataDetail.ListImg = new List <ImageProduct>()
                            {
                                new ImageProduct
                                {
                                    ImageURL = dataDetail.ImageURL
                                }
                            };
                        }
                        dataDetail.ListImg = dataDetail.ListImg.OrderBy(x => x.ImageURL).Skip(0).Take(4).ToList();

                        var oldData = data.Where(x => !x.ID.Equals(id) && x.CategoryID.Equals(dataDetail.CategoryID)).OrderBy(x => x.CreatedDate).Skip(0).Take(5).ToList();
                        oldData.ForEach(x =>
                        {
                            if (!string.IsNullOrEmpty(x.ImageURL))
                            {
                                x.ImageURL = Commons.HostImage + x.ImageURL;
                            }
                            //else
                            //    x.ImageURL = Commons.Image400_250;
                        });
                        model.ListProduct = oldData;
                        model.Product     = dataDetail;
                        return(View(model));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("GetDetail: ", ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }