Exemple #1
0
        public ActionResult Detail(long id)
        {
            ProductDAO db    = new ProductDAO();
            var        model = db.Detail(id);

            var product = Session[ProductSession];

            if (product != null)
            {
                var list = (List <ProductModel>)product;
                if (list.Exists(x => x.ID == id) == false)
                {
                    list.Add(model);
                }
                Session[ProductSession] = list;
            }
            else
            {
                var list = new List <ProductModel>();
                list.Add(model);
                Session[ProductSession] = list;
            }


            List <string> ListImages = new ImageDAO().GetAllImage(id);
            var           ListDetail = new ProductDetailDao().GetAllProductDetail(id);

            ViewBag.ListDetail = ListDetail;
            ViewBag.ListImages = ListImages;
            return(View(model));
        }
        public JsonResult SaveImages(long id, string images)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var listImages = serializer.Deserialize <List <string> >(images);

            XElement xElement = new XElement("Images");

            foreach (var item in listImages)
            {
                var subStringItem = item.Substring(22);
                xElement.Add(new XElement("Image", subStringItem));
            }
            ProductDetailDao dao = new ProductDetailDao();

            try
            {
                dao.UpdateImages(id, xElement.ToString());
                return(Json(new
                {
                    status = true
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    status = false
                }));
            }
        }
        // GET: Admin/ProductDetail
        public ActionResult Index(int id, int page = 1, int pageSize = 10)
        {
            var dao = new ProductDetailDao();

            var model = dao.ListAllPaging(id, page, pageSize);

            return(View(model));
        }
        public JsonResult LoadImages(long id)
        {
            ProductDetailDao dao = new ProductDetailDao();
            var product          = dao.ViewDetail(id);
            var images           = product.MoreImages;

            XElement      xImages          = XElement.Parse(images);
            List <string> listImagesReturn = new List <string>();

            foreach (XElement element in xImages.Elements())
            {
                listImagesReturn.Add(element.Value);
            }
            return(Json(new
            {
                data = listImagesReturn
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(ProductDetail detail)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                var dao = new ProductDetailDao();

                bool result = dao.Update(detail);

                if (result)
                {
                    SetAlert("Chỉnh sửa thành công", "success");
                    return(RedirectToAction("Index/" + detail.ProductID, "ProductDetail"));
                }
                else
                {
                    ModelState.AddModelError("", "Chỉnh sửa không thành công");
                }
            }
            return(View("Index"));
        }
        public ActionResult Create(ProductDetail product)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var listImages = serializer.Deserialize <List <string> >(product.MoreImages);

                XElement xElement = new XElement("Images");

                foreach (var item in listImages)
                {
                    var subStringItem = item.Substring(22);
                    xElement.Add(new XElement("Image", subStringItem));
                }
                product.MoreImages = xElement.ToString();
                var dao = new ProductDetailDao();

                product.ID = 0;
                //Color color = (Color)ColorConverter.ConvertFromString("123123");


                long id = dao.Insert(product);


                if (id > 0)
                {
                    SetAlert("Thêm sản phẩm thành công", "success");
                    return(RedirectToAction("Index/" + product.ProductID, "ProductDetail"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm sản phẩm không thành công");
                }
            }
            return(View("Index"));
        }
        public ActionResult Edit(long id)
        {
            var detail = new ProductDetailDao().ViewDetail(id);

            return(View(detail));
        }
Exemple #8
0
        // GET: api/Products/5
        public string GetModelNumber(int id)
        {
            IProductDetailDao repo = new ProductDetailDao();

            return(repo.GetProduct(id)?.ProductNumber);
        }
Exemple #9
0
        public IEnumerable <Product> Get(string sort = "ProductId", int page = 1, int pageSize = maxPageSize)
        {
            try
            {
                IProductDetailDao repository = new ProductDetailDao();

                var products = repository.GetAllProducts(sort);


                // ensure the page size isn't larger than the maximum.
                if (pageSize > maxPageSize)
                {
                    pageSize = maxPageSize;
                }

                // calculate data for metadata
                var totalCount = products.Count();
                var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);

                var urlHelper = new UrlHelper(Request);
                var prevLink  = page > 1 ? urlHelper.Link("ProductListing",
                                                          new
                {
                    page     = page - 1,
                    pageSize = pageSize,
                    sort     = sort
                }) : "";
                var nextLink = page < totalPages?urlHelper.Link("ProductListing",
                                                                new
                {
                    page     = page + 1,
                    pageSize = pageSize,
                    sort     = sort
                }) : "";


                var paginationHeader = new
                {
                    currentPage      = page,
                    pageSize         = pageSize,
                    totalCount       = totalCount,
                    totalPages       = totalPages,
                    previousPageLink = prevLink,
                    nextPageLink     = nextLink
                };

                HttpContext.Current.Response.Headers.Add("X-Pagination",
                                                         Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));


                // return result
                return(products
                       .Skip(pageSize * (page - 1))
                       .Take(pageSize)
                       .ToList());
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #10
0
        // GET: api/Products
        // GET: api/Products?sort=productName
        // GET: api/Products?sort=-productName,productId
        public IEnumerable <Product> Get(string sort = "ProductId")
        {
            IProductDetailDao repo = new ProductDetailDao();

            return(repo.GetAllProducts(sort));
        }
Exemple #11
0
        //  [Route("api/products/{productId}/ProductName")]
        // GET: api/Products/5
        // GET: api/Products?productId=5&&sort=productname

        public IHttpActionResult GetProductName(int productId, string sort = "ProductId")
        {
            IProductDetailDao repo = new ProductDetailDao();

            return(Ok(repo.GetAllProducts(sort)?.Where(item => item.ProductID == productId)));
        }