Пример #1
0
        public async Task <IActionResult> Payment(ShoppingCartVM shoppingcart)
        {
            var    reservationsFromCart  = shoppingcart.Reservations;
            var    subscriptionsFromCart = shoppingcart.Subscriptions;
            string userID = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (reservationsFromCart != null && reservationsFromCart.Count != 0)
            {
                var validations = await IsValidReservations(userID, reservationsFromCart);

                if (!validations[0])
                {
                    ModelState.AddModelError("error", "U kunt maar 10 tickets per match kopen.");
                    return(View("Index", shoppingcart));
                }
                if (!validations[1])
                {
                    ModelState.AddModelError("error", "U kunt geen 2 verschillende matchen op dezelfde dag kopen.");
                    return(View("Index", shoppingcart));
                }
                if (!validations[2])
                {
                    ModelState.AddModelError("error", "Uw aantal tickets overschrijdt het aantal beschikbare plaatsen.");
                    return(View("Index", shoppingcart));
                }

                List <Reservation> reservations = _mapper.Map <List <Reservation> >(reservationsFromCart);
                for (var i = 0; i < reservationsFromCart.Count; i++)
                {
                    reservations[i].CustomerId         = userID;
                    shoppingcart.Reservations[i].Price = shoppingcart.Reservations[i].Price * shoppingcart.Reservations[i].NumberOfTickets;
                    reservations[i].Price = shoppingcart.Reservations[i].Price;
                    await _reservationService.CreateAsync(reservations[i]);
                }
            }
            if (subscriptionsFromCart != null && subscriptionsFromCart.Count != 0)
            {
                List <Subscription> subscriptions = _mapper.Map <List <Subscription> >(subscriptionsFromCart);
                foreach (var sub in subscriptions)
                {
                    sub.CustomerId = userID;
                    await _subscriptionService.CreateAsync(sub);
                }
            }

            var user = await _userManager.FindByIdAsync(userID);

            var useremail = user.Email;
            var customer  = await _customerService.GetAsync(userID);

            await _emailSender.SendEmailAsync(
                useremail,
                "Betaling Ontvangen",
                BuildVoucherMessage(shoppingcart, customer.LastName + " " + customer.FirstName)
                );

            HttpContext.Session.SetObject("ShoppingCart", null);
            return(View(shoppingcart));
        }
Пример #2
0
        public void GivenCreateAsyncWhenExpectedExceptionIsThrownThenHandlesGracefully()
        {
            // Arrange

            // Act
            var exception = Assert.ThrowsAsync <NotImplementedException>(
                () => subscriptionService.CreateAsync(It.IsAny <Subscription>()));

            // Assert
            exception.Should().NotBeNull().And.BeOfType <NotImplementedException>();
        }
Пример #3
0
        public void GivenCreateAsyncWhenExpectedExceptionIsThrownThenHandlesGracefully()
        {
            // Arrange

            // Act
            var exception = Assert.ThrowsAsync <NotImplementedException>(
                () => subscriptionService.CreateAsync(It.IsAny <Subscription>()));

            // Assert
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception, Is.TypeOf <NotImplementedException>());
        }
Пример #4
0
        internal async Task GivenCreateAsyncWhenExpectedExceptionIsThrownThenHandlesGracefully()
        {
            // Arrange

            // Act
            var exception = await Assert.ThrowsAsync <NotImplementedException>(
                () => subscriptionService.CreateAsync(It.IsAny <Subscription>()));

            // Assert
            Assert.NotNull(exception);
            Assert.IsType <NotImplementedException>(exception);
        }
        public async Task <IActionResult> CreateAsync([FromBody] Subscription subscription)
        {
            try
            {
                await subscriptionService.CreateAsync(subscription);

                return(Created($"api/v1/subscriptions/{ subscription?.Id }", subscription));
            }
            catch
            {
                return(BadRequest());
            }
        }
Пример #6
0
        public async Task <IActionResult> PostAsync([Required] CreateSubscriptionRequestDto request, [Required][FromHeader(Name = "User-Id")] string userId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            var response = await _subscriptionService.CreateAsync(request, userId);

            response.Url    = GetUrl(response.SubscriptionId);
            response.UserId = userId;

            return(Ok(response));
        }
        public async Task <ActionResult> CreateOrUpdateAsync(Guid subscriptionId, [FromBody] Subscription subscription)
        {
            if (subscription == null)
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(nameof(subscription)), UserErrorCode.PayloadNotProvided);
            }

            if (!subscriptionId.Equals(subscription.SubscriptionId))
            {
                throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(Subscription).Name),
                                                      UserErrorCode.NameMismatch);
            }

            if (await _subscriptionService.ExistsAsync(subscriptionId))
            {
                _logger.LogInformation($"Update subscription {subscriptionId} with payload {JsonSerializer.Serialize(subscription)}.");
                var sub = await _subscriptionService.GetAsync(subscriptionId);

                AADAuthHelper.VerifyUserAccess(this.HttpContext, _logger, false, sub.Owner);
                if (!sub.OfferName.Equals(subscription.OfferName, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new LunaBadRequestUserException("Offer name of an existing subscription can not be changed.", UserErrorCode.InvalidParameter);
                }

                if (!string.IsNullOrEmpty(subscription.Owner) && !sub.Owner.Equals(subscription.Owner, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new LunaBadRequestUserException("Owner name of an existing subscription can not be changed.", UserErrorCode.InvalidParameter);
                }

                if (sub.PlanName.Equals(subscription.PlanName, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new LunaConflictUserException($"The subscription {subscription.SubscriptionId} is already in plan {subscription.PlanName}.");
                }
                // Update existing subscription
                await _fulfillmentManager.RequestUpdateSubscriptionAsync(subscriptionId, subscription.PlanName);

                return(Ok(await _subscriptionService.GetAsync(subscriptionId)));
            }
            else
            {
                _logger.LogInformation($"Create subscription {subscriptionId} with payload {JsonSerializer.Serialize(subscription)}.");
                // Create a new subscription
                AADAuthHelper.VerifyUserAccess(this.HttpContext, _logger, false, subscription.Owner);
                await _subscriptionService.CreateAsync(subscription);

                return(CreatedAtRoute(nameof(GetAsync) + nameof(Subscription), new { subscriptionId = subscription.SubscriptionId }, subscription));
            }
        }