Example #1
0
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                Manufactor manufactor = _context.Manufactor.Find(id); //先找到原来的值

                if (manufactor != null)
                {
                    _context.Manufactor.Remove(manufactor);  //标识这个数据要被删除 在数据库中还未删除
                    _context.SaveChanges();
                }
                // TODO: Add delete logic here

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        [HttpPost]//也就是说点保存的时候调用的,(下面的)
        public ActionResult ManufactorEdit(int?id, IFormCollection form)
        {
            if (ModelState.IsValid)
            {
                if (id == null)
                {
                    Manufactor manufactor = new Manufactor();
                    manufactor.CompanyName = form["CompanyName"];
                    manufactor.Address     = form["Address"];
                    manufactor.Province    = form["Province"];
                    manufactor.City        = form["City"];
                    manufactor.ContactTel  = form["ContactTel"];
                    //manufactor.RegistDate = Convert.ToDateTime(form["RegistDate"]);
                    manufactor.RegistDate = DateTime.Parse(form["RegistDate"]);
                    manufactor.Status     = form["Status"];
                    _context.Manufactor.Add(manufactor);
                    _context.SaveChanges();
                }
                else
                {
                    Manufactor manufactor = _context.Manufactor.Find(id);
                    manufactor.CompanyName = form["CompanyName"];
                    manufactor.Address     = form["Address"];
                    manufactor.Province    = form["Province"];
                    manufactor.City        = form["City"];
                    manufactor.ContactTel  = form["ContactTel"];
                    //manufactor.RegistDate = Convert.ToDateTime(form["RegistDate"]);
                    manufactor.RegistDate = DateTime.Parse(form["RegistDate"]);
                    manufactor.Status     = form["Status"];

                    _context.SaveChanges();
                }
                return(RedirectToAction("ManufactorList"));
            }
            else
            {
                ModelState.AddModelError("", "数据输入错误,请检查");
                return(View());
            }
        }
Example #3
0
        // GET: Product
        //Product/ProductDetail/id
        public ActionResult ProductDetail(int?id)
        {
            Product product = _productService.GetById(id.HasValue ? id.Value : 0);

            if (product != null && !product.isDelete)//check xem product co tren db ko va product da bi xoa ?
            {
                //khoi tao para cho filter Models
                IEnumerable <Category>   categories  = _categoryService.GetAll();
                IEnumerable <Manufactor> manufactors = _manufactorService.GetAll();
                IEnumerable <Status>     status      = _statusService.GetAll();
                IEnumerable <ProductTag> productTags = _productTagService.GetAll().Where(m => m.ProductID == product.Id);
                IEnumerable <Image>      images      = _imageService.GetAll().Where(m => m.ProductID == product.Id);

                ProductIndex p = new ProductIndex();//xu ly va fill du lieu vao Models
                p.product = product;
                List <Tag> tags = new List <Tag>();
                foreach (var item in productTags)
                {
                    tags.Add(_tagService.GetAll().FirstOrDefault(m => m.Id == item.TagID));
                }
                p.tags = tags;
                Category category = categories.FirstOrDefault(m => m.id == product.CategoryID);
                p.category = category;
                Manufactor manufactor = manufactors.FirstOrDefault(m => m.Id == product.ManufactorID);
                p.manufactor = manufactor;
                Status s = status.FirstOrDefault(m => m.Id == product.StatusID);
                p.status        = s;
                p.images        = images;
                p.comments      = _commentService.GetAll().Where(m => m.ProductID == product.Id && m.Type == 1 && m.isDelete == false).OrderByDescending(m => m.dateCreate).AsEnumerable();
                p.wishLists     = User.Identity.IsAuthenticated ? _wishListService.GetAll().Where(m => m.UserID == User.Identity.GetUserId()) : null;
                product.C_View += 1;//tang luot view len 1
                _productService.editProduct(product);
                return(View(p));
            }
            else
            {
                return(HttpNotFound());//trang view loi~
            }
        }
Example #4
0
        public JsonResult SearchAPI(string keyword, int?page, int?pageSize, int?chkBrand, double?price)
        {
            int pageNumber = (page ?? 1);

            if (keyword == null)
            {
                keyword = "";
            }
            else
            {
                keyword = keyword.ToLower();
            }
            List <Data.Product>      list        = new List <Data.Product>();
            IEnumerable <Image>      images      = _imageService.GetAll().ToList();
            IEnumerable <Manufactor> manufactors = _manufactorService.GetAll().ToList();
            IEnumerable <Category>   categorys   = _categoryService.GetAll();
            IEnumerable <Tag>        tags        = _tagService.GetAll();
            SearchAPIViewModel       model       = new SearchAPIViewModel();

            if (keyword == null)
            {
            }
            else if (keyword.Equals("featured"))//more product theo key
            {
                list = _productService.Get().Where(p => p.isDelete == false).OrderByDescending(d => d.C_View).ToList();
            }
            else if (keyword.Equals("new-arrivals"))
            {
                list = _productService.Get().Where(p => p.isDelete == false).OrderByDescending(d => d.DateCreated).ToList();
            }
            else if (keyword.Equals("top-sales"))
            {
                list = _productService.Get().Where(p => p.isDelete == false).OrderByDescending(d => d.SaleRate).ToList();
            }
            else if (manufactors.Where(m => m.Name.ToLower().Equals(keyword)).Any())//search theo manufactors
            {
                Manufactor manufactor = manufactors.Where(m => m.Name.ToLower().Equals(keyword)).FirstOrDefault();
                list = _productService.Get().Where(p => p.isDelete == false).Where(m => m.ManufactorID == manufactor.Id).ToList();
            }
            else if (categorys.Where(m => m.title.ToLower().Equals(keyword)).Any())//search theo type
            {
                Category type = categorys.Where(m => m.title.ToLower().Equals(keyword)).FirstOrDefault();
                list = _productService.Get().Where(p => p.isDelete == false).Where(m => m.CategoryID == type.id).ToList();
            }
            else if (tags.Where(m => m.Name.ToLower().Equals(keyword)).Any())
            {
                Tag tag = tags.Where(m => m.Name.ToLower().Equals(keyword)).FirstOrDefault();
                IEnumerable <ProductTag> productTags = _productTagService.GetAll().Where(m => m.TagID == tag.Id);
                foreach (var item in productTags)
                {
                    if (_productService.GetById(item.ProductID).isDelete == false)
                    {
                        list.Add(_productService.GetById(item.ProductID));
                    }
                }
            }
            else //search theo name san pham
            {
                var allProduct = _productService.Get().Where(p => p.isDelete == false);
                foreach (var item in allProduct)
                {
                    if (item.Name.ToLower().Contains(keyword))
                    {
                        list.Add(item);
                    }
                }
            }

            if (chkBrand.HasValue)//filter cho brand
            {
                list          = list.Where(m => m.ManufactorID == chkBrand.Value).ToList();
                ViewBag.Brand = chkBrand.Value;
            }
            if (price.HasValue)//filter cho price
            {
                double Price = price.HasValue ? price.Value : 50000;
                list          = list.Where(m => m.Price > Price).ToList();
                ViewBag.Price = price.Value;
            }

            model.list = list.Select(s => new ProductViewModel {
                CategoryID   = s.CategoryID,
                C_View       = s.C_View,
                DateCreated  = s.DateCreated,
                Description  = s.Description,
                Id           = s.Id,
                isDelete     = s.isDelete,
                ManufactorID = s.ManufactorID,
                ModifiedDate = s.ModifiedDate,
                Name         = s.Name,
                OrderCounter = s.OrderCounter,
                Price        = s.Price,
                Rate         = s.Rate,
                SaleRate     = s.SaleRate,
                Size         = s.Size,
                StatusID     = s.StatusID,
                images       = images.Where(i => i.ProductID == s.Id).ToList()
            }).ToPagedList(pageNumber, pageSize.HasValue ? pageSize.Value : 10);
            model.count = list.Count;

            JsonResult result = new JsonResult();

            result.Data = model;
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(result);
        }
Example #5
0
        public ActionResult Search(string keyword, int?page, int?chkBrand, double?price)
        {
            int pageSize   = 10;
            int pageNumber = (page ?? 1);

            if (keyword == null)
            {
                keyword = "";
            }
            else
            {
                keyword = keyword.ToLower();
            }
            List <Data.Product>      list        = new List <Data.Product>();
            IEnumerable <Image>      images      = _imageService.GetAll().ToList();
            IEnumerable <Manufactor> manufactors = _manufactorService.GetAll().ToList();
            IEnumerable <Category>   categorys   = _categoryService.GetAll();
            IEnumerable <Tag>        tags        = _tagService.GetAll();
            IEnumerable <Category>   categories  = _categoryService.GetAll();
            IEnumerable <Anime>      animes      = _animeService.GetAll();
            SearchViewModel          model       = new SearchViewModel();

            if (keyword == null)
            {
            }
            else if (keyword.Equals("featured")) //more product theo key
            {
                list = _productService.Get().Where(p => p.isDelete == false).OrderByDescending(d => d.C_View).ToList();
            }
            else if (keyword.Equals("new-arrivals"))
            {
                list = _productService.Get().Where(p => p.isDelete == false).OrderByDescending(d => d.DateCreated).ToList();
            }
            else if (keyword.Equals("top-sales"))
            {
                list = _productService.Get().Where(p => p.isDelete == false).OrderByDescending(d => d.SaleRate).ToList();
            }
            else if (manufactors.Where(m => m.Name.ToLower().Equals(keyword)).Any())//search theo manufactors
            {
                Manufactor manufactor = manufactors.Where(m => m.Name.ToLower().Equals(keyword)).FirstOrDefault();
                list = _productService.Get().Where(p => p.isDelete == false).Where(m => m.ManufactorID == manufactor.Id).ToList();
            }
            else if (categorys.Where(m => m.title.ToLower().Equals(keyword)).Any())//search theo type
            {
                Category type = categorys.Where(m => m.title.ToLower().Equals(keyword)).FirstOrDefault();
                list = _productService.Get().Where(p => p.isDelete == false).Where(m => m.CategoryID == type.id).ToList();
            }
            else if (tags.Where(m => m.Name.ToLower().Equals(keyword)).Any())
            {
                Tag tag = tags.Where(m => m.Name.ToLower().Equals(keyword)).FirstOrDefault();
                IEnumerable <ProductTag> productTags = _productTagService.GetAll().Where(m => m.TagID == tag.Id);
                foreach (var item in productTags)
                {
                    if (_productService.GetById(item.ProductID).isDelete == false)
                    {
                        list.Add(_productService.GetById(item.ProductID));
                    }
                }
            }
            else //search theo name san pham
            {
                var allProduct = _productService.Get().Where(p => p.isDelete == false);
                foreach (var item in allProduct)
                {
                    if (item.Name.ToLower().Contains(keyword))
                    {
                        list.Add(item);
                    }
                }
            }
            model.productAll = list; //danh cho filter para luu tru tat ca cac sp da search ra
            if (chkBrand.HasValue)   //filter cho brand
            {
                list          = list.Where(m => m.ManufactorID == chkBrand.Value).ToList();
                ViewBag.Brand = chkBrand.Value;
            }
            if (price.HasValue)//filter cho price
            {
                double Price = price.HasValue ? price.Value : 50000;
                list          = list.Where(m => m.Price > Price).ToList();
                ViewBag.Price = price.Value;
            }

            model.list        = list.ToPagedList(pageNumber, pageSize);
            model.categories  = categories;
            model.animes      = animes;
            model.images      = images;
            model.manufactors = manufactors;
            model.wishLists   = User.Identity.IsAuthenticated ? _wishListService.GetAll().Where(m => m.UserID == User.Identity.GetUserId()) : null;
            ViewBag.Size      = list.Count;
            ViewBag.keyword   = keyword;
            ViewBag.page      = page.HasValue ? page.Value : 1;

            return(View(model));
        }
Example #6
0
 public void Update(Manufactor entity)
 {
     _manufactorRepo.Update(entity);
 }
Example #7
0
 public Manufactor Add(Manufactor entity)
 {
     return(_manufactorRepo.Add(entity));
 }
 public void editManufactor(Manufactor obj)
 {
     ManufactorRepository.Update(obj);
     SaveChange();
 }