Пример #1
0
        public async Task <IActionResult> Edit(int id)
        {
            var review = _reviews.Get(id);

            if (review == null)
            {
                return(RedirectToAction("Index", "Movie"));
            }

            if (!(await _authorizationService.AuthorizeAsync(User, review, Authorization.ReviewOperations.Edit)))
            {
                return(Challenge());
            }

            var movie = _movies.GetDetails(review.MovieId);

            var model = new EditReviewModel
            {
                ReviewId   = id,
                Comment    = review.Comment,
                Stars      = review.Stars,
                MovieTitle = movie.Title,
            };

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id)
        {
            var review = _reviews.Get(id);

            if (review == null)
            {
                return(RedirectToAction("Index", "Movie"));
            }

            var authz = await _authorization.AuthorizeAsync(User, review, ReviewOperations.Update);

            if (!authz.Succeeded)
            {
                return(Forbid());
            }

            var movie = _movies.GetDetails(review.MovieId);

            var model = new EditReviewModel
            {
                ReviewId   = id,
                Comment    = review.Comment,
                Stars      = review.Stars,
                MovieTitle = movie.Title,
            };

            return(View(model));
        }
        public async Task <IActionResult> Get(int id)
        {
            var review = _reviews.Get(id);

            if (review == null)
            {
                return(NotFound());
            }

            review.CanEdit = (await _authorization.AuthorizeAsync(User, review, Authorization.ReviewOperations.Edit)).Succeeded;

            return(Ok(review));
        }
Пример #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,BookId,Created,Qualification,Comment")] ReviewViewModel reviewViewModel)
        {
            if (id != reviewViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var service = new ReviewService(HttpContext.Session.GetString("Token"));
                var item    = service.Get((int)id);
                if (item == null)
                {
                    return(NotFound());
                }

                var items = service.Edit(reviewViewModel);
                if (items == null)
                {
                    return(BadRequest());
                }

                return(RedirectToAction(nameof(Index)));
            }

            var bookService = new BookService(HttpContext.Session.GetString("Token"));
            var userService = new UserService(HttpContext.Session.GetString("Token"));

            ViewData["BookId"]        = new SelectList(bookService.Get(), "Id", "Name", reviewViewModel.BookId);
            ViewData["UserId"]        = new SelectList(userService.Get(), "Id", "Name", reviewViewModel.UserId);
            ViewData["Qualification"] = new SelectList(Common.Reviews, "Value", "Key", reviewViewModel.Qualification);
            return(View(reviewViewModel));
        }
Пример #5
0
        // GET: Review/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var review = await _reviewService.Get(id);

            if (review == null)
            {
                return(NotFound());
            }

            return(View(review));
        }
Пример #6
0
        //Post Method, passing a userModel to Login
        public IActionResult LogIn(UserModel userModel) //Requires a userModel, firstName and password
        {
            UserModel um = new UserModel();

            um.FirstName = userModel.FirstName;
            um.Password  = userModel.Password;

            bool myVar = carService.Get(um.FirstName, um.Password); //Calls a Method in CarService to start connection to Mongo, returns a Bool, True if in DB

            if (!myVar)                                             //Failed Authentication, send back to Login, clear fields
            {
                ModelState.Clear();
                UserModel ObjContact = new UserModel() //Create a new userModel, set to an empty string
                {
                    FirstName = string.Empty,
                    Password  = string.Empty,
                };
                ViewBag.LoginMessage = "Not a valid email or password. Try agin please. ";
                return(View("Index", ObjContact));
            }
            HttpContext.Session.SetString("personFirst", um.FirstName); //Succsessfull Authentication, save to Session so we can use elsewhere in Application
            HttpContext.Session.SetString("personLast", um.Password);

            Console.WriteLine($"Login Successful! {um.FirstName}");
            ViewBag.firstName = um.FirstName;
            return(View("Landing")); //Send user to Landing Page
        }
Пример #7
0
        public static Review Get(int id)
        {
            var apiCallTask = ReviewService.Get(id);
            var result      = apiCallTask.Result;

            JObject jsonResponse = JsonConvert.DeserializeObject <JObject>(result);
            Review  review       = JsonConvert.DeserializeObject <Review>(jsonResponse.ToString());

            return(review);
        }
Пример #8
0
        // GET: Reviews
        public async Task <IActionResult> Index()
        {
            var service = new ReviewService(HttpContext.Session.GetString("Token"));
            var items   = service.Get();

            if (items == null)
            {
                return(NotFound());
            }

            return(View(items));
        }
Пример #9
0
        public async Task <IActionResult> Edit(int id)
        {
            var review = _reviews.Get(id);

            if (review == null)
            {
                return(RedirectToAction("Index", "Movie"));
            }

            // TODO: authorize the user to edit the review

            var movie = _movies.GetDetails(review.MovieId);

            var model = new EditReviewModel
            {
                ReviewId   = id,
                Comment    = review.Comment,
                Stars      = review.Stars,
                MovieTitle = movie.Title,
            };

            return(View(model));
        }
Пример #10
0
        public void Get_GivenGuid_ReturnsCorrectReview()
        {
            var review = new Review
            {
                ReviewPublicId = Guid.NewGuid(),
                ReviewId       = Guid.NewGuid(),
                Restaurant     = _testContext.Restaurants.First()
            };

            _testContext.Reviews.Add(review);
            _testContext.SaveChanges();

            var result = _reviewService.Get(review.ReviewPublicId);

            Assert.AreEqual(review, result);
        }
Пример #11
0
        // GET: Reviews/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var service = new ReviewService(HttpContext.Session.GetString("Token"));
            var items   = service.Get((int)id);

            if (items == null)
            {
                return(NotFound());
            }

            return(View(items));
        }
Пример #12
0
        public void GetReviewTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <Review>(applicationDbContext);
            reviewService        = new ReviewService(repository);
            applicationDbContext.Reviews.Add(new Review()
            {
                Id = Guid.Parse("0602e418-69c8-499c-94af-0466139fc504")
            });
            applicationDbContext.SaveChanges();
            var review = reviewService.Get(Guid.Parse("0602e418-69c8-499c-94af-0466139fc504"));

            Assert.NotNull(review);
            Assert.IsType <Review>(review);
            Assert.Equal(Guid.Parse("0602e418-69c8-499c-94af-0466139fc504"), review.Id);
        }
Пример #13
0
        public void ReviewOkTest()
        {
            ReviewService reviewService = getService();
            OrderService  orderService  = getOrderService();
            User          u             = registerUser();
            Product       p             = generateProduct();
            Guid          orderId       = orderService.GetActiveOrderFromUser(u).Id;

            orderService.AddProduct(u, p.Id);
            orderService.SetAddress(u, u.Address.Id);
            orderService.Ship(orderId);
            orderService.Pay(orderId);
            string reviewText = "Muy bueno";

            reviewService.Evaluate(u, p.Id, orderId, reviewText);
            Review myReview = reviewService.Get(p.Id, orderId);

            Assert.IsNotNull(myReview);
        }
Пример #14
0
        // GET: Reviews/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var service         = new ReviewService(HttpContext.Session.GetString("Token"));
            var reviewViewModel = service.Get((int)id);

            if (reviewViewModel == null)
            {
                return(NotFound());
            }

            var bookService = new BookService(HttpContext.Session.GetString("Token"));
            var userService = new UserService(HttpContext.Session.GetString("Token"));

            ViewData["BookId"]        = new SelectList(bookService.Get(), "Id", "Name", reviewViewModel.BookId);
            ViewData["UserId"]        = new SelectList(userService.Get(), "Id", "Name", reviewViewModel.UserId);
            ViewData["Qualification"] = new SelectList(Common.Reviews, "Value", "Key", reviewViewModel.Qualification);

            return(View(reviewViewModel));
        }
Пример #15
0
        // GET: Reviews/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var service = new ReviewService(HttpContext.Session.GetString("Token"));
            var item    = service.Get((int)id);

            if (item == null)
            {
                return(NotFound());
            }

            var items = service.Delete((int)id);

            if (!items)
            {
                return(NotFound());
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #16
0
        protected async Task <StripeWebhookEvent> GetWebhookStripeEventAsync(PaymentProviderContext <TSettings> ctx, string webhookSigningSecret)
        {
            StripeWebhookEvent stripeEvent = null;

            if (ctx.AdditionalData.ContainsKey("Vendr_StripeEvent"))
            {
                stripeEvent = (StripeWebhookEvent)ctx.AdditionalData["Vendr_StripeEvent"];
            }
            else
            {
                try
                {
                    var json = await ctx.Request.Content.ReadAsStringAsync();

                    var stripeSignature = ctx.Request.Headers.GetValues("Stripe-Signature").FirstOrDefault();

                    // Just validate the webhook signature
                    EventUtility.ValidateSignature(json, stripeSignature, webhookSigningSecret);

                    // Parse the event ourselves to our custom webhook event model
                    // as it only captures minimal object information.
                    stripeEvent = JsonConvert.DeserializeObject <StripeWebhookEvent>(json);

                    // We manually fetch the event object type ourself as it means it will be fetched
                    // using the same API version as the payment providers is coded against.
                    // NB: Only supports a number of object types we are likely to be interested in.
                    if (stripeEvent?.Data?.Object != null)
                    {
                        switch (stripeEvent.Data.Object.Type)
                        {
                        case "checkout.session":
                            var sessionService = new SessionService();
                            stripeEvent.Data.Object.Instance = sessionService.Get(stripeEvent.Data.Object.Id);
                            break;

                        case "charge":
                            var chargeService = new ChargeService();
                            stripeEvent.Data.Object.Instance = chargeService.Get(stripeEvent.Data.Object.Id);
                            break;

                        case "payment_intent":
                            var paymentIntentService = new PaymentIntentService();
                            stripeEvent.Data.Object.Instance = paymentIntentService.Get(stripeEvent.Data.Object.Id);
                            break;

                        case "subscription":
                            var subscriptionService = new SubscriptionService();
                            stripeEvent.Data.Object.Instance = subscriptionService.Get(stripeEvent.Data.Object.Id);
                            break;

                        case "invoice":
                            var invoiceService = new InvoiceService();
                            stripeEvent.Data.Object.Instance = invoiceService.Get(stripeEvent.Data.Object.Id);
                            break;

                        case "review":
                            var reviewService = new ReviewService();
                            stripeEvent.Data.Object.Instance = reviewService.Get(stripeEvent.Data.Object.Id);
                            break;
                        }
                    }

                    ctx.AdditionalData.Add("Vendr_StripeEvent", stripeEvent);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Stripe - GetWebhookStripeEvent");
                }
            }

            return(stripeEvent);
        }
Пример #17
0
 public async Task DetailTest()
 {
     var id = 1;
     await reviewService.Get(id);
 }
Пример #18
0
        public void GetById_OnGuid_CallsRepositoryMethod()
        {
            _reviewService.Get(new Guid());

            _reviewRepository.Verify(x => x.GetById(It.IsAny <Guid>()), Times.AtLeastOnce);
        }
Пример #19
0
 // GET: ReviewController
 public ActionResult Index()
 {
     return(View(reviewService.Get()));
 }
Пример #20
0
 public ActionResult <List <Review> > Get() =>
 _reviewService.Get();