Beispiel #1
0
        public async Task <IActionResult> Create([Bind("EventId,HomeTeam,AwayTeam,DateCreated")] Event @event)
        {
            if (ModelState.IsValid)
            {
                @event.DateCreated = DateTime.UtcNow;
                _context.Add(@event);

                // always add a default score
                var defaultScore = new Score()
                {
                    Away        = 0,
                    Home        = 0,
                    DateCreated = DateTime.UtcNow,
                    EventId     = @event.EventId,
                    Event       = @event
                };
                _context.Add(defaultScore);

                var result = await _context.SaveChangesAsync();

                if (result > 0 && await RabbitmqProvider.Publish(defaultScore, Constants.ScoresQueue))
                {
                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction("Error", "Home"));
            }
            return(View(@event));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Home,Away,DateCreated,EventId")] Score score)
        {
            if (ModelState.IsValid)
            {
                score.DateCreated = DateTime.UtcNow;
                _context.Add(score);
                score.Event = _context.Event.FirstOrDefault(e => e.EventId == score.EventId);
                var result = await _context.SaveChangesAsync();

                if (result > 0 && await RabbitmqProvider.Publish(score, Constants.ScoresQueue))
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["EventId"] = new SelectList(_context.Event, "EventId", "EventName", score.EventId);
            return(View(score));
        }