Пример #1
0
        public async Task <ActionResult> Create(LotteryEventViewModel data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var lotteryEvent = mapper.Map <LotteryEvent>(data);
                    lotteryEvent.Cards = EventHelper.GenerateLotteryCards(lotteryEvent.TotalCards);

                    eventService.AddLotteryEventAsync(lotteryEvent);
                    await eventService.SaveChangesAsync();

                    TempData["success"] = true;
                    TempData["msg"]     = "Lottery Events created successfully";

                    return(RedirectToAction("Index"));
                }

                return(View(data));
            }
            catch
            {
                return(View());
            }
        }
Пример #2
0
        public async Task <ActionResult> Edit(LotteryEventViewModel data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var lotteryEvent = mapper.Map <LotteryEvent>(data);

                    await eventService.UpdateLotteryEventAsync(lotteryEvent);

                    await eventService.SaveChangesAsync();

                    TempData["success"] = true;
                    TempData["msg"]     = "Lottery Event edited successfully";

                    return(RedirectToAction("Index"));
                }

                return(View(data));
            }
            catch
            {
                return(View(data));
            }
        }
Пример #3
0
        public async Task <JsonResult> SelectedWinner(LotteryEventViewModel model)
        {
            var cards = await cardService.GetAllCardsByEventIdAsync(model.Id);

            var lotteryEvent = mapper.Map <LotteryEvent>(model);

            lotteryEvent.WinnerCard = EventHelper.SelectedWinner(cards);

            await eventService.UpdateLotteryEventAsync(lotteryEvent);

            await eventService.SaveChangesAsync();

            TempData["success"] = true;
            TempData["msg"]     = "Selected winner card successfully";

            return(Json(new HttpStatusCodeResult(HttpStatusCode.NoContent)));
        }