Example #1
0
        public async Task <IActionResult> CompleteRaffle(int orderId, CompleteRaffleModel model)
        {
            var raffleEvent = raffleEventRepository.GetById(1);

            if (DateTime.UtcNow >= raffleEvent.CloseDate)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                var command = new CompleteRaffleOrderCommand
                {
                    OrderId              = orderId,
                    Confirmed21          = model.Confirmed21,
                    FirstName            = model.CustomerFirstName.Trim(),
                    LastName             = model.CustomerLastName.Trim(),
                    PhoneNumber          = model.PhoneNumber.Trim(),
                    Email                = model.CustomerEmail.Trim(),
                    AddressLine1         = model.AddressLine1.Trim(),
                    AddressLine2         = model.AddressLine2?.Trim(),
                    City                 = model.City?.Trim(),
                    State                = model.State?.Trim(),
                    Zip                  = model.Zip?.Trim(),
                    IsInternational      = model.IsInternational,
                    InternationalAddress = model.InternationalAddress?.Trim() ?? string.Empty,
                    HowDidYouHear        = model.HowDidYouHear?.Trim() ?? string.Empty,
                    HowDidYouHearOther   = model.HowDidYouHearOther?.Trim() ?? string.Empty
                };

                await mediator.Publish(command);

                HttpContext.Response.Cookies.Delete(CookieKeys.RaffleOrderId);
                return(RedirectToAction("DonationSuccessful", new { orderId }));
            }

            var order       = (await mediator.Send(new GetRaffleOrderQuery {
                OrderId = orderId
            }));
            var raffleItems = raffleItemRepository.GetAll();

            model.Items = order.Lines.Select(x => new CompleteRaffleLineItemModel
            {
                Name      = x.Name,
                Price     = x.Price,
                Amount    = x.Count,
                ImageUrls = raffleItems.First(ri => ri.Id == x.RaffleItemId).ImageUrls
            }).ToList();
            model.TotalPrice   = order.TotalPrice;
            model.TotalTickets = order.TotalTickets;

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> CompleteRaffle(int orderId)
        {
            var raffleEvent = raffleEventRepository.GetById(1);

            if (DateTime.UtcNow >= raffleEvent.CloseDate)
            {
                return(RedirectToAction("Index"));
            }

            var order = await mediator.Send(new GetRaffleOrderQuery { OrderId = orderId });

            if (order.CompletedDate.HasValue)
            {
                if (HttpContext.Request.Cookies.ContainsKey(CookieKeys.RaffleOrderId))
                {
                    HttpContext.Response.Cookies.Delete(CookieKeys.RaffleOrderId);
                }

                return(RedirectToAction("DonationSuccessful", new { orderId }));
            }

            var raffleItems = raffleItemRepository.GetAll();
            var model       = new CompleteRaffleModel
            {
                TotalPrice   = order.TotalPrice,
                TotalTickets = order.TotalTickets,
                Items        = order.Lines.Select(x => new CompleteRaffleLineItemModel
                {
                    Name      = x.Name,
                    Price     = x.Price,
                    Amount    = x.Count,
                    ImageUrls = raffleItems.First(ri => ri.Id == x.RaffleItemId).ImageUrls
                }).ToList()
            };

            return(base.View(model));
        }