Ejemplo n.º 1
0
        public async Task <ActionResult> GetProductDetail(string id, string sortBy)
        {
            ProductReviewDTO productReviewDTO = new ProductReviewDTO();

            // Get the product based on the id
            ProductDetailDTO product = await unitOfWork.Products.Get(x => x.Id == id, new ProductDetailDTO());

            // If the product is found in the database, return the product with other product details
            if (product != null)
            {
                var response = new
                {
                    product,
                    media   = await unitOfWork.Media.GetCollection(x => x.ProductId == product.Id, new ProductMediaDTO()),
                    content = await unitOfWork.ProductContent.GetCollection(x => x.ProductId == product.Id, x => new
                    {
                        Type = new {
                            x.ProductContentType.Name,
                            x.ProductContentType.Image
                        },
                        x.Title,
                        PriceIndices = x.PriceIndices.Select(y => y.Index).ToList()
                    }),
                    pricePoints    = await unitOfWork.PricePoints.GetCollection(x => x.ProductId == product.Id, x => string.Format(x.Description, x.Price)),
                    reviews        = await unitOfWork.ProductReviews.GetReviews(product.Id, sortBy, 1),
                    sortOptions    = productReviewDTO.GetSortOptions(),
                    reviewsPerPage = productReviewDTO.GetReviewsPerPage()
                };

                return(Ok(response));
            }

            return(NotFound());
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            ProductReviewDTO productReview = new ProductReviewDTO();

            productReview.Name   = "Варежки 'Бабушка-рукодельница'";
            productReview.Number = "123456";
            IndexDTO reviews1 = new IndexDTO();

            reviews1.NameCustomer = "Василий Петров";
            reviews1.DateReview   = new DateTime(2008, 02, 05);
            reviews1.TextReview   = "Варежки прекрасные!";
            IndexDTO reviews2 = new IndexDTO();

            reviews2.NameCustomer = "Мария Ситникова";
            reviews2.DateReview   = new DateTime(2008, 02, 06);
            reviews2.TextReview   = "Говно ваши варежки!";
            IndexDTO reviews3 = new IndexDTO();

            reviews3.NameCustomer = "Ольга Иванова";
            reviews3.DateReview   = new DateTime(2008, 02, 07);
            reviews3.TextReview   = "На разок пойдут…";
            IndexDTO reviews4 = new IndexDTO();

            reviews4.NameCustomer = "Василий Муравьев";
            reviews4.DateReview   = new DateTime(2008, 02, 05);
            reviews4.TextReview   = "Моя бабушка лучше вяжет. Обращайтесь!";
            IndexDTO reviews5 = new IndexDTO();

            reviews5.NameCustomer = "Петр Кошкин";
            reviews5.DateReview   = new DateTime(2008, 02, 05);
            reviews5.TextReview   = "В -30 в них холодно. Отморозила руки!";
            IndexDTO reviews6 = new IndexDTO();

            reviews6.NameCustomer = "Алла Пугачева";
            reviews6.DateReview   = new DateTime(2008, 02, 05);
            reviews6.TextReview   = "На зимнюю рыбалку вообще отлично!";
            IndexDTO reviews7 = new IndexDTO();

            reviews7.NameCustomer = "Вася Пупкин";
            reviews7.DateReview   = new DateTime(2008, 02, 05);
            reviews7.TextReview   = "Варежки пришли поеденные молью!";
            productReview.Reviews.Add(reviews1);
            productReview.Reviews.Add(reviews2);
            productReview.Reviews.Add(reviews3);
            productReview.Reviews.Add(reviews4);
            productReview.Reviews.Add(reviews5);
            productReview.Reviews.Add(reviews6);
            productReview.Reviews.Add(reviews7);
            return(View(productReview));
        }
Ejemplo n.º 3
0
        // ..................................................................................Get Reviews.....................................................................
        public async Task <IEnumerable <ProductReviewDTO> > GetReviews(string productId, string sortBy, int page)
        {
            ProductReviewDTO productReviewDTO = new ProductReviewDTO(sortBy);

            return(await context.ProductReviews
                   .AsNoTracking()
                   .SortBy(productReviewDTO)
                   .ThenByDescending(x => x.Date)
                   .Where(x => x.ProductId == productId)
                   .Select(productReviewDTO)
                   .Skip((page - 1) * productReviewDTO.GetReviewsPerPage())
                   .Take(productReviewDTO.GetReviewsPerPage())
                   .ToListAsync());
        }
Ejemplo n.º 4
0
        //DTO
        public ProductReviewDTO ToDto()
        {
            ProductReviewDTO dto = new ProductReviewDTO();

            dto.Approved      = this.Approved;
            dto.Bvin          = this.Bvin;
            dto.Description   = this.Description;
            dto.Karma         = this.Karma;
            dto.ProductBvin   = this.ProductBvin;
            dto.ProductName   = this.ProductName;
            dto.Rating        = (ProductReviewRatingDTO)((int)this.Rating);
            dto.ReviewDateUtc = this.ReviewDateUtc;
            dto.UserID        = this.UserID;

            return(dto);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Allows you to convert the current product review object to the DTO equivalent for use with the REST API
        /// </summary>
        /// <returns>A new instance of ProductReviewDTO</returns>
        public ProductReviewDTO ToDto()
        {
            var dto = new ProductReviewDTO();

            dto.Approved      = Approved;
            dto.Bvin          = Bvin;
            dto.Description   = Description;
            dto.Karma         = Karma;
            dto.ProductBvin   = ProductBvin;
            dto.ProductName   = ProductName;
            dto.Rating        = (ProductReviewRatingDTO)(int)Rating;
            dto.ReviewDateUtc = ReviewDateUtc;
            dto.UserID        = UserID;

            return(dto);
        }
Ejemplo n.º 6
0
        public void FromDto(ProductReviewDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            this.Approved      = dto.Approved;
            this.Bvin          = dto.Bvin;
            this.Description   = dto.Description;
            this.Karma         = dto.Karma;
            this.ProductBvin   = dto.ProductBvin;
            this.ProductName   = dto.ProductName;
            this.Rating        = (ProductReviewRating)((int)dto.Rating);
            this.ReviewDateUtc = dto.ReviewDateUtc;
            this.UserID        = dto.UserID;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Allows you to populate the current product review object using a ProductReviewDTO instance
        /// </summary>
        /// <param name="dto">An instance of the product review from the REST API</param>
        public void FromDto(ProductReviewDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            Approved      = dto.Approved;
            Bvin          = dto.Bvin;
            Description   = dto.Description;
            Karma         = dto.Karma;
            ProductBvin   = dto.ProductBvin;
            ProductName   = dto.ProductName;
            Rating        = (ProductReviewRating)(int)dto.Rating;
            ReviewDateUtc = dto.ReviewDateUtc;
            UserID        = dto.UserID;
        }
Ejemplo n.º 8
0
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse <ProductReviewDTO> response = new ApiResponse <ProductReviewDTO>();

            ProductReviewDTO postedItem = null;

            try
            {
                postedItem = MerchantTribe.Web.Json.ObjectFromJson <ProductReviewDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return(MerchantTribe.Web.Json.ObjectToJson(response));
            }

            ProductReview item = new ProductReview();

            item.FromDto(postedItem);

            if (bvin == string.Empty)
            {
                if (MTApp.CatalogServices.ProductReviews.Create(item))
                {
                    bvin = item.Bvin;
                }
            }
            else
            {
                MTApp.CatalogServices.ProductReviews.Update(item);
            }
            ProductReview resultItem = MTApp.CatalogServices.ProductReviews.Find(bvin);

            if (resultItem != null)
            {
                response.Content = resultItem.ToDto();
            }

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return(data);
        }
        public IHttpActionResult PutProductReview([FromBody] ProductReviewDTO model)
        {
            var product             = Ucommerce.EntitiesV2.Product.FirstOrDefault(x => x.Sku == model.Sku && x.VariantSku == null);
            var productCatalogGroup = Ucommerce.EntitiesV2.ProductCatalogGroup
                                      .FirstOrDefault(x => x.ProductCatalogGroupId == CatalogContext.CurrentCatalogGroup.ProductCatalogGroupId);
            var request = System.Web.HttpContext.Current.Request;
            var basket  = TransactionLibrary.HasBasket() ? TransactionLibrary.GetBasket(false) : null;

            if (basket != null)
            {
                if (basket.Customer == null)
                {
                    basket.Customer = new Ucommerce.EntitiesV2.Customer()
                    {
                        FirstName = model.Name, LastName = string.Empty, EmailAddress = model.Email
                    };
                    basket.Save();
                }
            }

            var review = new Ucommerce.EntitiesV2.ProductReview()
            {
                ProductCatalogGroup = productCatalogGroup,
                ProductReviewStatus = Ucommerce.EntitiesV2.ProductReviewStatus.SingleOrDefault(s => s.ProductReviewStatusId == (int)ProductReviewStatusCode.New),
                CreatedOn           = DateTime.Now,
                CreatedBy           = model.Name,
                Product             = product,
                Customer            = basket?.Customer,
                Rating         = model.Rating,
                ReviewHeadline = model.Title,
                ReviewText     = model.Comments,
                Ip             = request.UserHostName,
            };

            product.AddProductReview(review);

            PipelineFactory.Create <Ucommerce.EntitiesV2.ProductReview>("ProductReview").Execute(review);

            return(Ok());
        }
        public async Task <ActionResult> GetReviewsDetail(string productId, string sortBy, int page = 1)
        {
            ProductReviewDTO productReviewDTO = new ProductReviewDTO();

            // Get the product that is in review
            var product = await unitOfWork.Products.Get(x => x.Id == productId, x => new
            {
                id           = x.Id,
                title        = x.Title,
                urlTitle     = x.UrlTitle,
                rating       = x.Rating,
                totalReviews = x.TotalReviews,
                minPrice     = x.MinPrice,
                maxPrice     = x.MaxPrice,
                image        = x.Image,
                shareImage   = x.ShareImage,
                oneStar      = x.OneStar,
                twoStars     = x.TwoStars,
                threeStars   = x.ThreeStars,
                fourStars    = x.FourStars,
                fiveStars    = x.FiveStars
            });


            // If product is not null
            if (product != null)
            {
                return(Ok(new
                {
                    product,
                    positiveReview = await unitOfWork.ProductReviews.GetPositiveReview(product.id),
                    negativeReview = await unitOfWork.ProductReviews.GetNegativeReview(product.id),
                    reviews = await unitOfWork.ProductReviews.GetReviews(product.id, sortBy, page),
                    sortOptions = productReviewDTO.GetSortOptions(),
                    reviewsPerPage = productReviewDTO.GetReviewsPerPage()
                }));
            }

            return(BadRequest());
        }
Ejemplo n.º 11
0
        public void ProductReviews_CreateUpdateFindDelete()
        {
            //Create API Proxy.
            var proxy = CreateApiProxy();

            //Create product review
            var productReview = new ProductReviewDTO
            {
                Approved      = true,
                ProductBvin   = TestConstants.TestProductBvin,
                Rating        = ProductReviewRatingDTO.FiveStars,
                UserID        = "1",
                ReviewDateUtc = DateTime.UtcNow
            };
            var createResponse = proxy.ProductReviewsCreate(productReview);

            CheckErrors(createResponse);
            Assert.IsFalse(string.IsNullOrEmpty(createResponse.Content.Bvin));

            //Find Product review
            var findResponse = proxy.ProductReviewsFind(createResponse.Content.Bvin);

            CheckErrors(findResponse);
            Assert.AreEqual(createResponse.Content.ProductBvin, findResponse.Content.ProductBvin);
            Assert.AreEqual(createResponse.Content.Rating, findResponse.Content.Rating);

            //Update product review
            createResponse.Content.Rating = ProductReviewRatingDTO.TwoStars;
            var updateResponse = proxy.ProductReviewsUpdate(createResponse.Content);

            CheckErrors(updateResponse);
            Assert.AreEqual(createResponse.Content.Rating, updateResponse.Content.Rating);

            //Delete product review
            var deleteResponse = proxy.ProductReviewsDelete(createResponse.Content.Bvin);

            CheckErrors(deleteResponse);
            Assert.IsTrue(deleteResponse.Content);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Allows the REST API to create or update a product review
        /// </summary>
        /// <param name="parameters">
        ///     Parameters passed in the URL of the REST API call. If there is a first parameter found in the
        ///     URL, the method will assume it is the product review ID (bvin) and that this is an update, otherwise it assumes to
        ///     create a product review.
        /// </param>
        /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param>
        /// <param name="postdata">Serialized (JSON) version of the ProductReviewDTO object</param>
        /// <returns>ProductReviewDTO - Serialized (JSON) version of the product review</returns>
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            // an object used to return the response
            var data = string.Empty;

            // the ID of the product review to update
            var bvin = FirstParameter(parameters);

            // a response object used to send back the new/updated review
            var response = new ApiResponse <ProductReviewDTO>();

            // an object used to house the posted review for parsing
            ProductReviewDTO postedItem = null;

            try
            {
                // load the posted review object to the local REST API object
                postedItem = Json.ObjectFromJson <ProductReviewDTO>(postdata);
            }
            catch (Exception ex)
            {
                // add an error to send back to the calling application
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return(Json.ObjectToJson(response));
            }

            // create a new review object
            var item = new ProductReview();

            // convert the posted review object for parsing
            item.FromDto(postedItem);

            // if bvin is empty this is a new review
            if (bvin == string.Empty)
            {
                // create the new review
                if (HccApp.CatalogServices.ProductReviews.Create(item))
                {
                    // populate the local bvin object for use in querying for the update later
                    bvin = item.Bvin;
                }
            }
            else
            {
                item.StoreId = HccApp.CurrentRequestContext.CurrentStore.Id;

                // update the review in the data source
                HccApp.CatalogServices.ProductReviews.Update(item);
            }


            // find a fresh instance of the new/updated product review
            var resultItem = HccApp.CatalogServices.ProductReviews.Find(bvin);

            // add the review object to the response
            if (resultItem != null)
            {
                response.Content = resultItem.ToDto();
            }

            // serialize the response for return
            data = Json.ObjectToJson(response);

            // send the response back to the calling application
            return(data);
        }