コード例 #1
0
        public async Task<ActionResult> Unregister(Guid? id)
        {
            if (id == null)
            {
                throw new HttpException(NotFound, nameof(Event));
            }

            Event currentEvent = await db.Events.FindAsync(id);

            if (currentEvent == null)
            {
                throw new HttpException(NotFound, nameof(Event));
            }

            Member currentMember = await db.Members.FindAsync(idGetter.GetUserId(User.Identity));

            currentMember.RegisteredEvents.Remove(currentEvent);
            db.MarkAsModified(currentMember);

            await db.SaveChangesAsync();

            var model = new EventDetailsViewModel
            {
                Event = currentEvent,
                CurrentMemberIsRegistered = currentEvent.RegisteredMembers.Contains(currentMember)
            };

            this.AddAlert(AlertType.Info, $"You are no longer attending {currentEvent.Name}.");

            return View("Details", model);
        }
コード例 #2
0
        // GET: Events/Details/5
        /// <summary>
        ///     Displays information about a specific event
        /// </summary>
        /// <param name="id">
        ///     The id of the event to view details of
        /// </param>
        /// <returns>
        ///     Details view for the Event matching id
        ///     404 Not Found view if the id does not match an Event
        /// </returns>
        public async Task<ActionResult> Details(Guid? id)
        {
            if (id == null)
            {
                throw new HttpException(NotFound, nameof(Event));
            }

            var model = new EventDetailsViewModel
            {
                Event = await db.Events.FindAsync(id)
            };

            if (model.Event == null)
            {
                throw new HttpException(NotFound, nameof(Event));
            }

            Member currentMember = await db.Members.FindAsync(idGetter.GetUserId(User.Identity));

            if (currentMember != null)
            {
                model.CurrentMemberIsRegistered = model.Event.RegisteredMembers.Contains(currentMember);
            }

            return View(model);
        }