示例#1
0
        public async Task <IActionResult> Update(int id)
        {
            var items = raffleItemRepository.GetAll();
            var order = (await mediator.Send(new GetRaffleOrderQuery {
                OrderId = id
            }));
            var model = MapOrderModel(id, items, order);

            return(View("RaffleOrderUpdate", model));
        }
示例#2
0
        public async Task <ActionResult <List <RaffleItemDuringRunModel> > > Get([FromQuery] RaffleItemRequest request)
        {
            var raffleItems = repository.GetAll();

            var items = raffleItems
                        .Where(x => !request.HasTicketDrawn || (request.HasTicketDrawn && x.HasBeenDrawn))
                        .Select(RaffleItemDuringRunMapper.Map)
                        .ToList();

            var ordersResult = await mediator.Send(new GetRaffleOrdersQuery());

            var possibleWinners = ordersResult.Orders.Select(x =>
                                                             new
            {
                Name = $"{x.Customer.FirstName} {x.Customer.LastName}",
                x.Customer.Email,
                Phone    = x.Customer.PhoneNumber,
                Address1 = x.Customer.AddressLine1,
                Address2 = x.Customer.AddressLine2,
                x.Customer.City,
                x.Customer.State,
                x.Customer.Zip,
                Tickets = GetOrderTickets(x.TicketNumber)
            });

            foreach (var item in items)
            {
                foreach (var winningTicket in item.WinningTickets)
                {
                    var winner = possibleWinners.Where(x => x.Tickets.Contains(winningTicket.Number)).FirstOrDefault();
                    item.Winners.Add(new Winner
                    {
                        Name         = winner.Name,
                        Email        = winner.Email,
                        Phone        = winner.Phone,
                        Address1     = winner.Address1,
                        Address2     = winner.Address2,
                        City         = winner.City,
                        State        = winner.State,
                        Zip          = winner.Zip,
                        For          = winningTicket.For,
                        TicketNumber = winningTicket.Number
                    });
                }
            }

            return(items.OrderBy(x => x.ItemNumber).ToList());
        }
示例#3
0
        public IReadOnlyList <RaffleItem> GetAll()
        {
            var e = cache.Get(CacheKeys.RaffleItemsAll);

            if (!cache.TryGetValue(CacheKeys.RaffleItemsAll, out List <RaffleItem> cacheEntry))
            {
                cacheEntry = repository.GetAll().ToList();

                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(30));

                cache.Set(CacheKeys.RaffleItemsAll, cacheEntry, cacheEntryOptions);
            }

            return(cacheEntry);
        }
示例#4
0
        public async Task <IActionResult> UpdateTicketCount(int raffleItemId, [FromBody] UpdateOrderItemModel model)
        {
            var raffleItems = raffleItemRepository.GetAll().ToList();

            if (HttpContext.Request.Cookies.ContainsKey(CookieKeys.RaffleOrderId))
            {
                var orderId = int.Parse(HttpContext.Request.Cookies[CookieKeys.RaffleOrderId]);
                var order   = await mediator.Send(new GetRaffleOrderQuery { OrderId = orderId });

                if (order == null)
                {
                    logger.LogWarning($"No order found for RaffleOrderId: {orderId}");
                    return(Json(new { Success = false }));
                }

                var raffleItem = raffleItems.FirstOrDefault(x => x.Id == raffleItemId);
                if (raffleItem == null)
                {
                    logger.LogWarning($"RaffleItemId: {raffleItemId} wasn't found to update count on order");
                    return(Json(new { Success = false }));
                }

                await mediator.Publish(new UpdateOrderCommand
                {
                    OrderId          = orderId,
                    RaffleOrderItems = new List <UpdateOrderCommand.RaffleOrderItem> {
                        new UpdateOrderCommand.RaffleOrderItem
                        {
                            RaffleItemId = raffleItemId,
                            Name         = $"#{raffleItem.ItemNumber} {raffleItem.Title}",
                            Price        = raffleItem.Cost,
                            Count        = model.Amount
                        }
                    }
                });

                return(Json(new { Success = true }));
            }

            logger.LogWarning("No RaffleOrderId cookie exists");
            return(Json(new { Success = false }));
        }