public ActionResult producerCreate(FormCollection form, HttpPostedFileBase fileUpload)
        {
            tbl_producer tic  = new tbl_producer();
            var          name = form["name"];
            bool         err  = false;

            if (String.IsNullOrEmpty(name))
            {
                err = true;
                ViewData["Error"] += "Vui lòng nhập tên danh mục!\n";
            }
            if (form["parent"].ToString().Equals("0"))
            {
                err = true;
                ViewData["Error"] += "Vui lòng chọn danh mục!\n";
            }
            else
            {
                tic.Idloaisp = Int32.Parse(form["parent"]);
            }

            tic.Tenhangsx = name;
            tic.alias     = DataHelper.GeneralHelper.getInstance().getAliasFromProducerName(data, name);
            if (err == false)
            {
                data.tbl_producers.InsertOnSubmit(tic);
                data.SubmitChanges();
                return(RedirectToAction("producerView"));
            }
            else
            {
                return(View(URLHelper.URL_ADMIN_PRODUCER_M, new Tuple <tbl_producer, List <tbl_product_type> >(tic, getAllItemCategories())));
            }
        }
        public ActionResult Producer(string id, int?page, string sorting)
        {
            int pageSize = 20;
            int pageNum  = (page ?? 1);

            var laysp = from g in db.tbl_Products
                        from h in db.tbl_product_types
                        from n in db.tbl_producers
                        where n.alias == id && g.IDLoaiSP == h.ID && g.Status == true && h.Status == true && n.status == true && n.Idloaisp == h.ID && n.Id == g.Idhangsx
                        select g;
            tbl_producer hang = db.tbl_producers.Where(n => n.alias.Equals(id)).SingleOrDefault();

            Session["TenLoai"] = hang.Tenhangsx;

            ViewBag.TenHangSX = hang.Tenhangsx;
            ViewBag.aliashang = hang.alias;
            ViewBag.TenLoai   = ((
                                     from l in db.tbl_product_types
                                     where l.ID == hang.Idloaisp
                                     select l).SingleOrDefault()).TenLoaiSP;
            ViewBag.aliasloai = ((
                                     from l in db.tbl_product_types
                                     where l.ID == hang.Idloaisp
                                     select l).SingleOrDefault()).alias;


            ViewBag.TenSapXep       = "Sắp xếp: A đến Z";
            ViewBag.NameSortParm    = "Name_desc";
            ViewBag.NameSortParmasc = "Name_asc";
            ViewBag.DateSortParm    = "Date_desc";
            ViewBag.PriceSortParm   = "Price_desc";
            ViewBag.PriceSortPasc   = "Price";
            if (sorting == "Name_desc")
            {
                ViewBag.TenSapXep = "Mặc định";
                return(View(laysp.OrderByDescending(n => n.TenSP).ToPagedList(pageNum, pageSize)));
            }
            if (sorting == "Name_asc")
            {
                ViewBag.TenSapXep = "Sắp xếp: A đến Z";
                return(View(laysp.OrderBy(n => n.TenSP).ToPagedList(pageNum, pageSize)));
            }
            if (sorting == "Date_desc")
            {
                ViewBag.TenSapXep = "Sản phẩm mới";
                return(View(laysp.OrderByDescending(n => n.NgayCapNhat).ToPagedList(pageNum, pageSize)));
            }
            if (sorting == "Price_desc")
            {
                ViewBag.TenSapXep = "Sắp xếp Giá: Cao Đến Thấp";
                return(View(laysp.OrderByDescending(n => n.GiaHienTai).ToPagedList(pageNum, pageSize)));
            }

            if (sorting == "Price")
            {
                ViewBag.TenSapXep = "Sắp xếp Giá: Thấp đến Cao";
                return(View(laysp.OrderBy(n => n.GiaHienTai).ToPagedList(pageNum, pageSize)));
            }
            return(View(laysp.ToPagedList(pageNum, pageSize)));
        }
        public ActionResult ProducerSetStatusEnable(int id)
        {
            tbl_producer tic = getOneProducer(id);

            tic.status = !tic.status;
            UpdateModel(tic);
            data.SubmitChanges();
            return(RedirectToAction("producerView"));
        }
        public ActionResult producerCreate()
        {
            var producer = new tbl_producer();

            return(View(URLHelper.URL_ADMIN_PRODUCER_M, new Tuple <tbl_producer, List <tbl_product_type> >(producer, getAllItemCategories())));
        }