Exemple #1
0
        public IActionResult DetailsProduct(int productId = 0)
        {
            if (productId == 0)
            {
                return(null);
            }

            ApplicationDbContext database = new ApplicationDbContext();

            var qProduct = database.Tbl_Products.Where(c => c.ProductId == productId && c.IsShowProduct == true)
                           .Include(c => c.Tbl_Gallery)
                           .Include(c => c.Tbl_Category)
                           .Include(c => c.Tbl_FirstSubCategory)
                           .Include(c => c.Tbl_SecondSubCategory)
                           .Include(c => c.Tbl_LastSubCategory)
                           .Include(c => c.Tbl_Comments)
                           .Include(c => c.Tbl_User).SingleOrDefault();

            if (qProduct == null)
            {
                return(null);
            }

            CategoryRepository Rep_Category = new CategoryRepository();
            CommentRepository  Rep_Comment  = new CommentRepository();
            GalleryRepository  Rep_Gallery  = new GalleryRepository();
            UserRepository     Rep_User     = new UserRepository();

            var qGetComment = Rep_Comment.ShowListComments(productId);
            var qGetGallery = Rep_Gallery.GetGalleryProduct(productId);
            var qGetCat     = Rep_Category.ShowFirstSubCategory().Where(c => c.FirstSubCatId == qProduct.FirstSubCat_FK).FirstOrDefault();
            var qUser       = Rep_User.GetUserById(qProduct.UserId_FK);//***

            //----------------------------------
            qProduct.SeeProduct = qProduct.SeeProduct + 1;
            database.Tbl_Products.Update(qProduct);
            database.SaveChanges();

            VmDetailsProduct vm = new VmDetailsProduct();

            vm.ListCommentsProduct = qGetComment == null ? null : qGetComment;
            vm.ListImagesProduct   = qGetGallery == null ? null : qGetGallery;
            vm.CategoryId_FK       = qProduct.CategoryId_FK;
            vm.CategoryName        = qGetCat.FirstSubCatTitle;
            vm.CountProduct        = qProduct.CountProduct;
            vm.DefaultPic          = qProduct.DefaultPic;
            vm.Description         = qProduct.Description;
            vm.FirstSubCat_FK      = qProduct.FirstSubCat_FK;
            vm.LastSubCat_FK       = qProduct.LastSubCat_FK;
            vm.LinkProduct         = qGetCat.FirstSubCatId + "-" + qGetCat.FirstSubCatTitle;//For Example : 1-موبایل
            vm.OffProduct          = qProduct.OffProduct;
            vm.Price           = qProduct.Price;
            vm.ProductCode     = qProduct.ProductCode;
            vm.ProductId       = qProduct.ProductId;
            vm.ProductNameEN   = qProduct.ProductNameEN;
            vm.ProductNameFA   = qProduct.ProductNameFA;
            vm.SecondSubCat_FK = qProduct.SecondSubCat_FK;
            vm.SeeProduct      = qProduct.SeeProduct;
            vm.Weight          = qProduct.Weight;
            vm.SecondCatName   = qProduct.Tbl_SecondSubCategory.SecondSubCatTitle;
            vm.LastCatName     = qProduct.Tbl_LastSubCategory.LastSubCatTitle;
            vm.UserId_FK       = qUser.Id;
            vm.Username        = qUser.UserName;
            return(View(vm));
        }