예제 #1
0
        //
        // GET: /Product/Details/5

        public ActionResult Details(int id = 0)
        {
            Product product = db.Products.Find(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            Store store = product.Store;

            if (product.StatusId == Constant.STATUS_BANNED || product.StatusId == Constant.STATUS_INACTIVE || store.StatusId == Constant.STATUS_BANNED || store.StatusId == Constant.STATUS_INACTIVE)
            {
                ViewBag.Message = "Sorry, this product is not available.";
                return(View("Error"));
            }
            if (store.StatusId == Constant.STATUS_PENDING)
            {
                ViewBag.Message = "Sorry, The store of product is pending.";
                return(View("Error"));
            }
            if (User.Identity.IsAuthenticated != false)
            {
                UserProfile user = UserProfiles_Logic.GetUserProfileByUserName(User.Identity.Name);
                ViewBag.detailuser = user;
            }
            else
            {
                ViewBag.detailuser = null;
            }

            // List product recommend
            List <Product> listrecommend = Product_Logic.GetListProdcutRecommend(id, 4);

            ViewBag.listrecommend = listrecommend;
            // List user like product
            List <UserProfile> listlike = Product_Logic.GetListUserProfileRandom(1, id, 5, WebSecurity.IsAuthenticated ? WebSecurity.CurrentUserId : 0);

            ViewBag.listlike = listlike;
            // List user buy product
            List <UserProfile> listbuy = Product_Logic.GetListUserProfileRandom(2, id, 5, WebSecurity.IsAuthenticated ? WebSecurity.CurrentUserId : 0);

            ViewBag.listbuy = listbuy;
            // List comment product
            List <Comment> listcmt = Comment_Logic.GetListCommentByProductID(id);

            ViewBag.listcmt = listcmt;
            return(View(product));
        }
예제 #2
0
        public ActionResult PostComment(Comment cmt)
        {
            if (User.Identity.IsAuthenticated == false)
            {
                return(Json("You must login to comment"));
            }
            cmt.CreateDate = DateTime.Now;
            cmt.UserId     = WebSecurity.CurrentUserId;

            // publish message to subscribers
            UserProfile productOwner = db.Products.Find(cmt.ProductId).Store.Owner;
            bool        pubResult    = Message_Logic.PublishMessage(
                productOwner.UserId, Constant.PRONOUN_TYPE_USER,
                cmt.ProductId.HasValue ? cmt.ProductId.Value : 1, Constant.PRONOUN_TYPE_PRODUCT,
                Constant.MESSAGE_TYPE_COMMENT);

            if (Comment_Logic.AddNewComment(cmt) > 0)
            {
                return(Json("true"));
            }
            return(Json("Add comment error"));
        }