public IActionResult postComment([FromBody] CommentDTO commentPost)
        {
            CommentResponse             cmtRp = new CommentResponse();
            ICollection <CommentEntity> listCommentOfProduct;

            if (commentPost.userID == 0 || null == userDAO.getOneById(commentPost.userID))
            {
                return(BadRequest(new { message = "Vui lòng đăng nhập trước khi thực hiện chức năng này." }));
            }
            else
            {
                CommentEntity commentResponse = new CommentEntity();
                commentResponse.userID = commentPost.userID;
                commentResponse.user   = userDAO.getOneById(commentPost.userID);
                if (commentPost.productID == 0 || null == product2DAO.getProduct(commentPost.productID)) //cần thêm kiểm tra trên order của khách hàng
                {
                    return(BadRequest(new { message = "Sản phẩm không tồn tại trong hệ thống!" }));
                }
                else
                {
                    if (null != commentDAO.checkUserCommentProductById(commentPost.productID, commentPost.userID))
                    {
                        return(BadRequest(new { message = "Bạn đã đánh giá sản phẩm này rồi. Cảm ơn bạn đã mua sản phẩm!" }));
                    }
                    //save to table
                    commentResponse.createdDate = System.DateTime.Now;
                    commentResponse.rate        = commentPost.rate;
                    Console.WriteLine("rating post = " + commentPost.rate + ", db=" + commentResponse.rate);

                    commentResponse.productID = commentPost.productID;
                    commentResponse.Product   = product2DAO.getProduct(commentPost.productID);
                    commentResponse.user      = userDAO.getOneById(commentPost.userID);
                    commentResponse.active    = 1;
                    commentResponse.content   = commentPost.content;
                    int commentID = commentDAO.Save(commentResponse);
                    //kiem tra xem trong order của user có productID này không ?
                    //TODO
                    //
                    if (commentID == 0)
                    {
                        return(BadRequest(new { message = "Hệ thống đang gặp sự cố!" }));
                    }
                    else
                    {
                        commentResponse.id         = commentID;
                        listCommentOfProduct       = (ICollection <CommentEntity>)commentDAO.getAllByProductID(commentResponse.productID);
                        cmtRp.listCommentByProduct = listCommentOfProduct;
                        cmtRp.computeSumOfList();
                        cmtRp.computeTbcRate();
                    }
                }
                return(Ok(cmtRp));
            }
        }
Exemple #2
0
        public ActionResult TestInclude()

        {
            Product2 p = productDAO.getProduct(1);

            return(Ok(p));
        }
Exemple #3
0
        public CustomOrderItem toCustomOrderItem(OrderItemEntity orderItemEntity)
        {
            CustomOrderItem csi         = new CustomOrderItem();
            Product2DAO     product2DAO = new Product2DAO();

            csi.productID = orderItemEntity.ProductId;
            Product2 productItem = product2DAO.getProduct(csi.productID);

            //csi.productImg = productItem.Images[0].Image;
            csi.productName = productItem.Name;
            csi.pricePerOne = (double)productItem.OriginalPrice;
            csi.quatity     = orderItemEntity.Quantity;
            csi.priceAll    = csi.computePriceAllByProduct();

            return(csi);
        }
        //lấy ra một sản phẩm theo id dùng cho trang chi tiết sản phẩm,...
        public ActionResult GetOneProductById(int _id, int id)
        {
            //Console.WriteLine(_id);
            try
            {
                int tmp = _id;
                if (id != 0)
                {
                    tmp = id;
                }
                Product2 product = ProductDAO.getProduct(tmp);
                if (product == null)
                {
                    return(BadRequest(tmp));
                }
                product.Images.ForEach(delegate(ImageProduct ip) {
                    ip.setRequest(Request);
                });

                CommentResponse commentResponse = new CommentResponse();
                product.commentResponse = commentResponse;
                ICollection <CommentEntity> listResult = commentDAO.getAllByProductID(product.Id);
                if (listResult.Count == 0)
                {
                    commentResponse.tbcRate = 0.0;
                    commentResponse.tongCmt = 0;
                    commentResponse.listCommentByProduct = new List <CommentEntity>();
                    return(Ok(product));
                }
                commentResponse.listCommentByProduct = listResult;
                commentResponse.computeSumOfList();
                commentResponse.computeTbcRate();
                // return Ok(product);
                return(Ok(product));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(BadRequest(new MessageResponse("Không lấy được sản phẩm.", "None product take")));
            }
        }
Exemple #5
0
        public ActionResult postCart([FromBody] FormAddCart formAddCart)
        {
            // Lấy UserEntity đang đăng nhập từ jwt
            UserEntity user = (UserEntity)HttpContext.Items["User"];

            Console.WriteLine("User: "******"User"] = null;

            //Xóa hết tất cả sản phẩm trong giỏ hàng
            cartDAO.deleteAllItemCart(user.Id);

            CartEntity c = cartDAO.getCart(user.Id);

            foreach (CartItem ci in formAddCart.CartItems)
            {
                Console.WriteLine("productId: {0}, amount: {1}", ci.Idp, ci.Quantity);
                if (ci.Idp == 0)
                {
                    return(BadRequest("Thiếu tham số idp."));
                }



                Console.WriteLine("productSpecificId {0}", ci.Idp);
                Product2 p = product2DAO.getProduct(ci.Idp);
                if (p == null)
                {
                    return(BadRequest());
                }

                try
                {
                    CartItemEntity cartItemEntity = null;
                    if (c.Items != null)
                    {
                        cartItemEntity = c.Items.Find(X =>
                        {
                            int tmp = X.Product.Id;
                            Console.WriteLine("ProductId : {0}", tmp);
                            return
                            (tmp.CompareTo(ci.Idp) == 0);
                        });
                    }
                    else
                    {
                        c.Items = new List <CartItemEntity>();
                    }

                    Console.WriteLine("cartItemEntity" + cartItemEntity);
                    if (cartItemEntity == null)
                    {
                        cartItemEntity           = new CartItemEntity();
                        cartItemEntity.Quantity  = ci.Quantity;
                        cartItemEntity.ProductId = ci.Idp;
                        cartItemEntity.Product   = p;
                        cartItemEntity.CartId    = c.Id;
                        //
                        if (cartItemEntity.Deleted == false)
                        {
                            c.Items.Add(cartItemEntity);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Increase amount");
                        cartItemEntity.Quantity += ci.Quantity;
                        //cartItemEntity.Quantity = ci.Quantity;
                        if (cartItemEntity.Quantity < 0)
                        {
                            return(BadRequest("Số lượng item trong giỏ hàng nhỏ hơn 0, hãy xóa item này khỏi giỏ hàng"));
                        }
                    }

                    cartItemEntity.Actived = ci.Actived;
                    cartItemEntity.Deleted = ci.Deleted;
                    cartItemEntity         = cartDAO.SaveCart(cartItemEntity);
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                    return(BadRequest(e.Message));
                }
            }

            c = cartDAO.getCart(c);
            //return Ok(c);
            return(Ok(new CartDTO(c)));
        }
Exemple #6
0
        public ActionResult postOrder([FromBody] FormPutOrder formOrder)
        {
            // Lấy UserEntity đang đăng nhập từ jwt
            UserEntity user = (UserEntity)HttpContext.Items["User"];

            Console.WriteLine("User: "******"User"] = null;

            //Xóa hết tất cả sản phẩm trong giỏ hàng
            orderDAO.deleteAllItemCart(user.Id);

            OrderEntity c = new OrderEntity();

            c.AddressDelivery = formOrder.Address;
            c.Email           = formOrder.Email;
            c.Phone           = formOrder.Phone;
            c.Fullname        = formOrder.Fullname;
            c.Note            = formOrder.Note;



            c.UserId = user.Id;
            c        = orderDAO.SaveOrder(c);
            // c = orderDAO.getOrder(c);
            if (c == null)
            {
                return(BadRequest("Not save orderEntity"));
            }
            Console.WriteLine("Order: {0}", c.Id);
            // if(c!=null) return Ok(c); ;

            // return Ok(c);

            foreach (OrderItem ci in formOrder.CartItems)
            {
                Console.WriteLine("productId: {0}, amount: {1}", ci.Idp, ci.Quantity);
                if (ci.Idp == 0)
                {
                    return(BadRequest("Thiếu tham số idp."));
                }

                Console.WriteLine("productSpecificId {0}", ci.Idp);
                Product2 p = product2DAO.getProduct(ci.Idp); if (p == null)
                {
                    return(BadRequest());
                }

                try
                {
                    OrderItemEntity cartItemEntity = null;
                    if (c.Items != null)
                    {
                        cartItemEntity = c.Items.Find(X => X.ProductId.CompareTo(ci.Idp) == 0);
                    }
                    else
                    {
                        c.Items = new List <OrderItemEntity>();
                    }

                    Console.WriteLine("orderItemEntity: {0}", cartItemEntity);
                    if (cartItemEntity == null)
                    {
                        cartItemEntity           = new OrderItemEntity();
                        cartItemEntity.Quantity  = ci.Quantity;
                        cartItemEntity.ProductId = ci.Idp;
                        cartItemEntity.OrderId   = c.Id;
                        cartItemEntity.Product   = p;
                        //
                        if (cartItemEntity.Deleted == false)
                        {
                            c.Items.Add(cartItemEntity);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Increase amount");
                        cartItemEntity.Quantity += ci.Quantity;
                        //cartItemEntity.Quantity = ci.Quantity;
                        if (cartItemEntity.Quantity < 0)
                        {
                            return(BadRequest("Số lượng item trong giỏ hàng nhỏ hơn 0, hãy xóa item này khỏi giỏ hàng"));
                        }
                    }

                    cartItemEntity.Actived = ci.Actived;
                    cartItemEntity.Deleted = ci.Deleted;
                    cartItemEntity         = orderDAO.SaveOrder(cartItemEntity);
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                    }
                    return(BadRequest(e.Message));
                }
            }



            //Payment
            c = orderDAO.getOrder(c);

            PaymentEntity paymentEntity = new PaymentEntity();

            paymentEntity.userId   = user.Id;
            paymentEntity.Amount   = c.TotalPrice * 100;
            paymentEntity.CurrCode = "VND";
            //paymentEntity.UrlReturn = "htpp://localhost:3000/accept";
            paymentEntity.UrlReturn  = formOrder.UrlReturn;
            paymentEntity.CreateTime = DateTime.Now;
            paymentEntity.IpAddress  = "119.17.249.22";
            paymentEntity            = paymentDAO.AddPayment(paymentEntity);
            paymentEntity.gender("https://localhost:25002/payment/redirect");
            paymentEntity = paymentDAO.UpdatePayment(paymentEntity);
            c.Payment     = paymentEntity;
            c.PaymentId   = paymentEntity.Id;
            Console.WriteLine("REST-Payment Id: {0}", c.PaymentId);
            orderDAO.UpdateOrder(c);

            c = orderDAO.getOrder(c);

            // return Ok((OrderDTO)c);
            return(Ok(new OrderDTO(c)));
            //return Ok(c);
        }