Beispiel #1
0
        /// <summary>
        /// This takes in ProductReviewModell / review giving it and guid id and add it to the database.
        /// </summary>
        /// <param name="ínputProduct"></param>
        /// <returns></returns>
        public async Task <bool> createReviewAsync(ProductReviewModell ínputProduct)
        {
            try
            {
                if (ínputProduct != null)
                {
                    ínputProduct.ReviewIDKey = Guid.NewGuid();

                    while (await validateIDToDatabaseAsync(ínputProduct) == true)
                    {
                        ínputProduct.ReviewIDKey = Guid.NewGuid();
                    }

                    ProductReviewModellContext.Productreviews.Add(ínputProduct);
                    await ProductReviewModellContext.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    throw new InvalidOperationException("Emty / Invalid input.");
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #2
0
        public async System.Threading.Tasks.Task <ActionResult> WriteReviews(ProductReviewModell Review, WriteReview DataBaseWriteReview)
        {
            try
            {
                bool succesfullywriten = await DataBaseWriteReview.createReviewAsync(Review);

                return(RedirectToAction("Details", new { id = Review.ProductIDKey, UrlParameter.Optional }));
            }
            catch (Exception e)
            {
                return(View());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Validating if id of in ProductReviewModell exist or not. Return an bool.
        /// </summary>
        /// <param name="ínputProduct"></param>
        /// <returns></returns>
        private async Task <bool> validateIDToDatabaseAsync(ProductReviewModell ínputProduct)
        {
            try
            {
                ProductModell PruductId = await ProductsContext.Products.FindAsync(ínputProduct.ReviewIDKey);

                while (PruductId != null)
                {
                    return(true);
                }
            }
            catch
            {
                throw;
            }

            return(false);
        }
Beispiel #4
0
        public ActionResult WriteReviews(Guid id, ProductReviewModell GetReviewDetails)
        {
            GetReviewDetails.ProductIDKey = id;

            return(View(GetReviewDetails));
        }