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()); } }
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)); } }
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))); }