예제 #1
0
        public IActionResult Index()
        {
            IEnumerable <Product>     products     = GetApiProducts.GetProducts();
            IEnumerable <UserComment> comment      = GetApiUserComments.GetUserComments();
            IEnumerable <Category>    categories   = GetApiCategories.GetCategories();
            IEnumerable <Distributor> distributors = GetApiDistributors.GetDistributors();

            List <ProductModelViewDetail> productRatings = products.Where(p => p.IsActivated == true).Select(p => new ProductModelViewDetail()
            {
                ProductId          = p.ProductId,
                ProductName        = p.ProductName,
                ProductDescription = p.ProductDescription,
                ProductImage       = p.ProductImage,
                ProductPrice       = p.ProductPrice,
                ProductDiscount    = p.ProductDiscount,
                CategoryName       = categories.SingleOrDefault(k => k.CategoryId == p.CategoryId).CategoryName,
                DistributorName    = distributors.SingleOrDefault(k => k.DistributorId == p.DistributorId).DistributorName,
                Rating             = getRatingProduct(p.ProductId),
                No_Ratings         = comment.Where(k => k.ProductId == p.ProductId && k.UserCommentApproved == true).Count(),
                InitAt             = p.InitAt,
                SlugName           = p.SlugName
            }).OrderByDescending(p => p.InitAt).ToList();

            return(View(productRatings));
        }
예제 #2
0
        public IActionResult EditProduct(int productId)
        {
            ViewBag.Distributors = GetApiDistributors.GetDistributors().ToList();
            ViewBag.Categories   = GetApiCategories.GetCategories().ToList();
            Product product = GetApiProducts.GetProducts().SingleOrDefault(p => p.ProductId == productId);

            return(View(product));
        }
예제 #3
0
        public IActionResult Index()
        {
            List <ProductModelView> products = GetApiProducts.GetProducts().Select(p => new ProductModelView()
            {
                ProductId          = p.ProductId,
                ProductName        = p.ProductName,
                ProductDescription = p.ProductDescription,
                ProductImage       = p.ProductImage,
                ProductPrice       = p.ProductPrice,
                ProductDiscount    = p.ProductDiscount,
                CatName            = GetApiCategories.GetCategories().SingleOrDefault(k => k.CategoryId == p.CategoryId).CategoryName,
                IsActivated        = p.IsActivated,
                InitAt             = p.InitAt,
                DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(k => k.DistributorId == p.DistributorId).DistributorName
            }).ToList();

            return(View(products));
        }
예제 #4
0
        public IActionResult RatingDetail(string slugName)
        {
            IEnumerable <Product> products = GetApiProducts.GetProducts().Where(p => p.IsActivated == true);
            Product p = products.SingleOrDefault(p => p.SlugName == slugName);

            if (p == null)
            {
                return(RedirectToAction("Index", "NotFound"));
            }

            ProductModelViewDetail res = new ProductModelViewDetail()
            {
                ProductId          = p.ProductId,
                ProductName        = p.ProductName,
                ProductDescription = p.ProductDescription,
                ProductImage       = p.ProductImage,
                ProductPrice       = p.ProductPrice,
                ProductDiscount    = p.ProductDiscount,
                CategoryName       = GetApiCategories.GetCategories().SingleOrDefault(k => k.CategoryId == p.CategoryId).CategoryName,
                DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(k => k.DistributorId == p.DistributorId).DistributorName,
                Rating             = getRatingProduct(p.ProductId),
                No_Ratings         = GetApiUserComments.GetUserComments().Where(k => k.ProductId == p.ProductId && k.UserCommentApproved == true).Count(),
                InitAt             = p.InitAt,
                Comments           = new List <UserComment>()
            };

            List <UserComment> comments = GetApiUserComments.GetUserComments().Where(k => k.ProductId == p.ProductId && k.UserCommentApproved == true).OrderByDescending(p => p.UserCommentPostedDate).ToList();

            foreach (var cmt in comments)
            {
                cmt.UserProfile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileId == cmt.UserProfileId);
            }

            res.Comments = comments;

            return(View(res));
        }
예제 #5
0
 public IActionResult Create()
 {
     ViewBag.Distributors = GetApiDistributors.GetDistributors().ToList();
     ViewBag.Categories   = GetApiCategories.GetCategories().ToList();
     return(View());
 }
예제 #6
0
        public IActionResult ProductDetail(string slugCategory = null, string slugProductName = null)
        {
            //get category
            Category category = CategoryByName(slugCategory);

            ViewBag.CategoryName = category.CategoryName;

            // get product by slugname
            Product product = ProductBySlugName(slugProductName);

            // init
            FoodProduct           food    = new FoodProduct();
            List <CostumeProduct> costume = new List <CostumeProduct>();
            ToyProduct            toy     = new ToyProduct();

            ProductModelViewDetail res = new ProductModelViewDetail();

            if (slugCategory == "food")
            {
                food = GetApiFoodProducts.GetFoodProducts().SingleOrDefault(p => p.ProductId == product.ProductId);
                res  = new ProductModelViewDetail()
                {
                    ProductId          = product.ProductId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductImage       = product.ProductImage,
                    ProductPrice       = product.ProductPrice,
                    ProductDiscount    = product.ProductDiscount,
                    SlugName           = product.SlugName,
                    CategoryName       = category.CategoryName,
                    Rating             = 0,
                    No_Ratings         = GetApiUserComments.GetUserComments().Where(p => p.ProductId == product.ProductId).Count(),
                    InitAt             = product.InitAt,
                    DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(p => p.DistributorId == product.DistributorId).DistributorName,
                    FoodExpiredDate    = food.FoodExpiredDate,
                    IsActivated        = product.IsActivated,
                    CostumeSize        = new List <CostumeSizeModel>(),
                    Amount             = food.FoodAmount
                };

                res.Rating = getRatingProduct(res.ProductId);
            }
            else if (slugCategory == "costume")
            {
                costume = GetApiCostumeProducts.GetCostumeProducts().Where(p => p.ProductId == product.ProductId).Select(p => new CostumeProduct()
                {
                    ProductId         = p.ProductId,
                    CostumeId         = p.CostumeId,
                    CostumeAmountSize = p.CostumeAmountSize,
                    CostumeSize       = p.CostumeSize
                }).ToList();

                res = new ProductModelViewDetail()
                {
                    ProductId          = product.ProductId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductImage       = product.ProductImage,
                    ProductPrice       = product.ProductPrice,
                    ProductDiscount    = product.ProductDiscount,
                    SlugName           = product.SlugName,
                    CategoryName       = category.CategoryName,
                    DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(p => p.DistributorId == product.DistributorId).DistributorName,
                    Rating             = 0,
                    No_Ratings         = GetApiUserComments.GetUserComments().Where(p => p.ProductId == product.ProductId).Count(),
                    InitAt             = product.InitAt,
                    IsActivated        = product.IsActivated,
                    FoodExpiredDate    = DateTime.Now,
                    CostumeSize        = new List <CostumeSizeModel>(),
                    Amount             = 0
                };

                res.CostumeSize = costume.Select(p => new CostumeSizeModel()
                {
                    CostumeSize       = p.CostumeSize,
                    CostumeAmountSize = p.CostumeAmountSize
                }).ToList();

                res.Rating = getRatingProduct(res.ProductId);
            }
            else
            {
                toy = GetApiToyProducts.GetToyProducts().SingleOrDefault(p => p.ProductId == product.ProductId);
                res = new ProductModelViewDetail()
                {
                    ProductId          = product.ProductId,
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductImage       = product.ProductImage,
                    ProductPrice       = product.ProductPrice,
                    ProductDiscount    = product.ProductDiscount,
                    SlugName           = product.SlugName,
                    CategoryName       = category.CategoryName,
                    DistributorName    = GetApiDistributors.GetDistributors().SingleOrDefault(p => p.DistributorId == product.DistributorId).DistributorName,
                    Rating             = 0,
                    No_Ratings         = GetApiUserComments.GetUserComments().Where(p => p.ProductId == product.ProductId).Count(),
                    InitAt             = product.InitAt,
                    IsActivated        = product.IsActivated,
                    FoodExpiredDate    = DateTime.Now,
                    CostumeSize        = new List <CostumeSizeModel>(),
                    Amount             = toy.ToyAmount
                };

                res.Rating = getRatingProduct(res.ProductId);
            }

            return(View(res));
        }