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(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"));
        }