Ejemplo n.º 1
0
        public ActionResult Update(MeetupsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = _context.Categories.ToList();
                return(View("MeetupForm", viewModel));
            }

            var userId = User.Identity.GetUserId();

            var meetup = _context.Meetups
                         .Include(m => m.Attendances.Select(a => a.Attendee))
                         .Single(m => m.Id == viewModel.Id && m.DeveloperId == userId);

            var modifiedMeetup = new Meetup
            {
                Topic      = viewModel.Topic,
                Venue      = viewModel.Venue,
                CategoryId = viewModel.Category,
                DateTime   = viewModel.GetDateTime()
            };

            meetup.Update(modifiedMeetup);

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Meetups"));
        }
Ejemplo n.º 2
0
        public ActionResult Create()
        {
            var viewModel = new MeetupsFormViewModel
            {
                Heading    = "Add a Meetup",
                Categories = _context.Categories.ToList()
            };

            return(View("MeetupForm", viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int meetupId)
        {
            var userId = User.Identity.GetUserId();

            var meetupData = _context.Meetups.Single(m => m.Id == meetupId && m.DeveloperId == userId);

            var viewModel = new MeetupsFormViewModel
            {
                Categories = _context.Categories.ToList(),
                Category   = meetupData.CategoryId,
                Date       = meetupData.DateTime.ToString("d MMM yyyy"),
                Time       = meetupData.DateTime.ToString("HH:mm"),
                Topic      = meetupData.Topic,
                Venue      = meetupData.Venue,
                Heading    = "Edit a meetup",
                Id         = meetupData.Id
            };

            return(View("MeetupForm", viewModel));
        }
Ejemplo n.º 4
0
        public ActionResult Create(MeetupsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = _context.Categories.ToList();
                return(View("MeetupForm", viewModel));
            }

            var meetup = new Meetup
            {
                Topic       = viewModel.Topic,
                Venue       = viewModel.Venue,
                DateTime    = viewModel.GetDateTime(),
                DeveloperId = User.Identity.GetUserId(),
                CategoryId  = viewModel.Category
            };

            _context.Meetups.Add(meetup);
            _context.SaveChanges();

            return(RedirectToAction("Mine", "Meetups"));
        }