コード例 #1
0
        public async Task <IActionResult> GetEvent(int id)
        {
            IActionResult result = null;

            var addresses = await _eventServices
                            .GetAll();

            await _eventTypeServices.GetAll();

            var oneEvent = await _eventServices
                           .Get(id);

            if (oneEvent == null)
            {
                result = NotFound();
            }
            else
            {
                var model = new EventViewModel {
                    Event = oneEvent
                };
                model.Event.Address = await _addressServices.Get(oneEvent.Address.Id);

                model.Event.EventType = await _eventTypeServices.Get(oneEvent.EventType.Id);

                model.Event.Commentaires = await _context.Commentaires
                                           .Where(x => x.EventId == oneEvent.Id)
                                           .ToListAsync();

                var links = await _context.EventApplicationUsers
                            .Where(x => x.EventId == oneEvent.Id)
                            .ToListAsync();

                foreach (var link in links)
                {
                    var user = await _userManager
                               .FindByIdAsync(link.ApplicationUserId);

                    model.Event.Members.Add(user);
                }

                result = View("Event", model);
            }

            return(result);
        }