public async Task <IActionResult> Generate([FromQuery] SubscriptionRequest subscriptionRequest)
        {
            var contentType = new ContentType(Request.ContentType);

            var result = await _subscriptionService.Create(subscriptionRequest, contentType);

            return(Content(result, contentType.MediaType));
        }
Exemple #2
0
        public IActionResult Create([FromBody] Subscription model)
        {
            var user = this.userService.GetUserByUserName(model.UserName);

            var serviceSubscription = SubscriptionMapper.MapToService(model, user.Result.Id);

            var createdSubscription = subscriptionService.Create(serviceSubscription);

            return(StatusCode((int)createdSubscription.Status, SubscriptionMapper.MapToController(createdSubscription.Result)));
        }
Exemple #3
0
 public IHttpActionResult Post([FromBody] SubscriptionCreateDTO subscription)
 {
     try
     {
         return(Ok(_subscriptionService.Create(subscription)));
     }
     catch (Exception e)
     {
         return(GetExceptionResponse(e));
     }
 }
Exemple #4
0
 private void SeedData()
 {
     for (int i = 1; i < 11; i++)
     {
         _subscriptionService.Create(new Subscription()
         {
             Id        = i,
             StartDate = DateTime.Now,
             EndDate   = DateTime.Now.AddSeconds(i * 10)
         });
     }
 }
        public async Task <IActionResult> Create(SubscriptionForm subscription)
        {
            subscription.AddedDate = DateTime.Now;
            await _subscriptionService.Create(subscription);

            var viewModel = new SubscriptionListViewModel()
            {
                VirtualAccountId = subscription.VirtualAccountId,
                Subscriptions    = await _subscriptionService.GetAll(subscription.VirtualAccountId)
            };

            return(PartialView("_SubscriptionList", viewModel));
        }
Exemple #6
0
        public async void IsBankAccountCreatePossible()
        {
            var form = new SubscriptionForm()
            {
                Name             = "Internet",
                Amount           = 15.20,
                AddedDate        = DateTime.Now,
                ExpirationDate   = DateTime.Now,
                FrequncyMonth    = 3,
                VirtualAccountId = 1,
            };
            var result = await _subscriptionService.Create(form);

            Assert.NotEqual(0, result);
        }
        public async Task <ActionResult> Create(CustomerSubscriptionViewModel viewModel, IFormCollection collection)
        {
            try
            {
                var newSubscription = viewModel.Subscription;
                newSubscription.CustomerId = Guid.Parse(viewModel.CustomerSelected);
                newSubscription.ProductId  = Guid.Parse(viewModel.ProductSelected);

                await _subscriptionService.Create(newSubscription);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task Subscribe(string topicName)
        {
            var subscription = await _subscriptionService.Get(Context.ConnectionId);

            if (subscription != null)
            {
                await Groups.RemoveFromGroupAsync(Context.ConnectionId, subscription.Topic);

                await _subscriptionService.Remove(Context.ConnectionId);
            }

            await _subscriptionService.Create(new Subscription
            {
                Topic          = topicName,
                SubscriptionId = Context.ConnectionId
            });

            await Groups.AddToGroupAsync(Context.ConnectionId, topicName);

            var messages = await _messageService.GetByTopic(topicName);

            await Clients.Caller.SendAsync("connect", messages.ToJson());
        }
Exemple #9
0
        // Subscription
        public IActionResult OnPostSubscribe(string email)
        {
            _subscriptionService.Create(email);

            return(RedirectToPage("Confirmation", "SubscriptionCompleted"));
        }
    public async Task <IActionResult> Create(SubscriptionDto subscriptionDto)

    {
        return(Ok(new { Success = true, subscriptionId = await _subscriptionService.Create(subscriptionDto) }));
    }
Exemple #11
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            ISubscriptionService service = testServer.Host.Services.GetService(typeof(ISubscriptionService)) as ISubscriptionService;
            var model = new ApiSubscriptionServerRequestModel();

            model.SetProperties("B", "B");
            CreateResponse <ApiSubscriptionServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.SubscriptionDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiSubscriptionServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
        public async Task <ActionResult> Confirm()
        {
            var userId    = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var userEmail = User.FindFirstValue(ClaimTypes.Email);

            ShoppingCartVM cart;

            cart = HttpContext.Session.GetObject <ShoppingCartVM>(KEY_SHOPPINGCART);
            if (cart == null)
            {
                return(NotFound());
            }

            var newOrder = new Order
            {
                Customer = Guid.Parse(userId)
            };
            var newOrderLines = new List <NewOrderLineVM>();

            foreach (var item in cart.Cart)
            {
                if (item.MatchTicket.HasValue)
                {
                    // New ticket
                    var msl = await _mslService.GetById(item.MatchTicket.Value);

                    if (DateTime.Now >= msl.Match.Start || DateTime.Now.AddMonths(1) < msl.Match.Start.Date)
                    {
                        TempData["CartError"] = "Probleem met winkelmandje!";
                        cart.Cart.Remove(item);
                        return(RedirectToAction(nameof(Cart)));
                    }

                    var previousMatchTickets = await _ticketService.GetByCustomerAndMatch(Guid.Parse(userId), msl.MatchId);

                    int prevMatchTicketCount = 0;
                    if (previousMatchTickets != null)
                    {
                        prevMatchTicketCount = previousMatchTickets.Count();
                    }

                    var totalTicketCount = cart.Cart.Where(x => x.ForMatchId == item.ForMatchId).Select(x => x.Count).Sum() + prevMatchTicketCount;

                    if (item.Count <= msl.RemainingSeats && totalTicketCount <= 10)
                    {
                        for (int i = 0; i < item.Count; i++)
                        {
                            newOrderLines.Add(new NewOrderLineVM
                            {
                                MSL   = item.MatchTicket,
                                Match = msl.MatchId
                            });
                        }
                    }
                    else
                    {
                        TempData["CartError"] = $"Maximum 10 tickets per match toegelaten! U bestelde al {prevMatchTicketCount} tickets voor {msl.Match.TeamHomeNavigation.Name} - {msl.Match.TeamAwayNavigation.Name} op {msl.Match.Start.ToShortDateString()}! Gelieve uw winkelmandje aan te passen";
                        return(RedirectToAction(nameof(Cart)));
                    }
                }
                else if (item.TeamSubscription.HasValue)
                {
                    // New subscription
                    newOrderLines.Add(new NewOrderLineVM
                    {
                        TSL = item.TeamSubscription
                    });
                }
            }

            if (newOrderLines.Count < 1)
            {
                TempData["CartError"] = "Probleem met winkelmandje!";
                return(RedirectToAction(nameof(Cart)));
            }

            await _orderService.Create(newOrder);

            List <string> orderLineEmail = new List <string>();

            foreach (var newOL in newOrderLines)
            {
                if (newOL.MSL.HasValue && newOL.Match.HasValue)
                {
                    // Is ticket
                    var msl = await _mslService.GetById(newOL.MSL.Value);

                    msl.RemainingSeats--;
                    await _mslService.Update(msl);

                    var newTicket = new Ticket
                    {
                        MatchStadiumLocationId = newOL.MSL.Value,
                        MatchId  = newOL.Match.Value,
                        Customer = Guid.Parse(userId)
                    };
                    await _ticketService.Create(newTicket);

                    await _orderLineService.Create(new OrderLine
                    {
                        TicketId = newTicket.Id,
                        OrderId  = newOrder.Id,
                        Price    = msl.Price
                    });

                    orderLineEmail.Add($"<p>Ticket: {newTicket.Code}</p> <p>Match: {msl.Match.TeamHomeNavigation.Name} - {msl.Match.TeamAwayNavigation.Name}</p> <p>Start: {msl.Match.Start.ToShortDateString()} {msl.Match.Start.ToShortTimeString()}</p> <p>Plaats:  {msl.StadiumLocation.Location.Location}</p>");
                }
                else if (newOL.TSL.HasValue)
                {
                    // Is subscription

                    var tsl = await _tclService.GetById(newOL.TSL.Value);

                    var matches = await _matchService.GetByCompetitionTeamId(tsl.CompetitionId, tsl.TeamId);

                    var msls = await _mslService.GetMslByMatches(matches);

                    foreach (var msl in msls.Where(x => x.LocationId == tsl.LocationId).ToList())
                    {
                        if (msl.RemainingSeats < 1)
                        {
                            TempData["CartError"] = $"Kies een andere zitplaats aub. De zitplaatsen voor {tsl.Location.Location} zijn uitverkocht";
                            return(RedirectToAction(nameof(Cart)));
                        }
                    }

                    var newSubscription = new Subscription
                    {
                        TeamCompetitionLocation = tsl,
                        Customer = Guid.Parse(userId)
                    };

                    await _subscriptionService.Create(newSubscription);

                    await _orderLineService.Create(new OrderLine
                    {
                        SubscriptionId = newSubscription.Id,
                        OrderId        = newOrder.Id,
                        Price          = tsl.Price
                    });

                    foreach (var msl in msls.Where(x => x.LocationId == tsl.LocationId).ToList())
                    {
                        msl.RemainingSeats--;
                        await _mslService.Update(msl);
                    }

                    orderLineEmail.Add($"<p>Ticket: {newSubscription.Code}</p> <p>Subscrition: {tsl.Team.Name} from {tsl.Competition.StartDate} until {tsl.Competition.EndDate}</p> <p>Plaats:  {tsl.Location.Location}</p>");
                }
            }

            await _emailSender.SendEmailOrderAsync(userEmail, $"Ticketverkoop: order confirmation {newOrder.Id}", $"<h1> Order confirmation Order Id: {newOrder.Id} </h1>", orderLineEmail.ToArray());

            TempData["LatestOrderId"] = newOrder.Id;
            cart.Cart = new List <CartVM>();
            HttpContext.Session.SetObject(KEY_SHOPPINGCART, cart);
            return(RedirectToAction("Details", "Orders", new { id = newOrder.Id }));
        }