public bool AddTicket(TicketModel model) { var ticketList = CreateTicket(model.Ticket); var session = _sessionRepository.GetAll().Last().Id; if (ticketList.Count() == 7) { var ticketString = _createTicket.CreateTicketString(ticketList); ticketString = ticketString.Remove(ticketString.Length - 1); var user = _userRepository.GetAll().SingleOrDefault(x => x.Id == model.UserId); if (user == null) { throw new Exception("User was not found"); } else { TicketsDto ticket = new TicketsDto() { UserId = user.Id, Ticket = ticketString, SessionId = session }; _ticketRepository.Add(ticket); } return(true); } return(false); }
public void StartSession() { var model = _sessionRepository.GetAll().Last(); List <int> modelNumbers = new List <int>(); var ran = new Random(); for (var n = 0; modelNumbers.Count() < 8; n++) { n = ran.Next(1, 38); if (!modelNumbers.Contains(n)) { modelNumbers.Add(n); } } //list for checking winnerlist // List<int> modelNumbers = new List<int>() { 1, 2, 33, 23, 36, 6, 7 }; var winnerList = GetWinnerList(modelNumbers); model.Winners = winnerList; var numberString = _createTicket.CreateTicketString(modelNumbers); numberString = numberString.Remove(numberString.Length - 1); model.Numbers = numberString; string winnerBoard = ""; foreach (var winner in winnerList) { winnerBoard += $"#. {winner.FirstName} {winner.LastName} Prize:{(Prize)winner.Prize} "; } if (winnerBoard == "") { model.WinnerBoard = "There is no winner"; } else { model.WinnerBoard = winnerBoard; } _sessionRepository.Update(model); var session = new SessionDto(); _sessionRepository.Add(session); }