Beispiel #1
0
        public ActionResult Create()
        {
            var viewModel = new GoFormViewModel
            {
                Genres  = _context.Genres.ToList(),
                Heading = "Add a Go"
            };

            return(View("GoForm", viewModel));
        }
Beispiel #2
0
        public ActionResult Edit(int id)
        {
            var userId = User.Identity.GetUserId();
            var go     = _context.Gos.Single(g => g.Id == id && g.ArticalId == userId);

            var viewModel = new GoFormViewModel
            {
                Heading = "Edit a Go",
                Id      = go.Id,
                Genres  = _context.Genres.ToList(),
                Date    = go.DateTime.ToString("d MMM yyyy"),
                Time    = go.DateTime.ToString("HH:mm"),
                Genre   = go.GenreId,
                Venue   = go.Venue
            };

            return(View("GoForm", viewModel));
        }
Beispiel #3
0
        public ActionResult Update(GoFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("GoForm", viewModel));
            }

            var userId = User.Identity.GetUserId();
            var go     = _context.Gos.Single(g => g.Id == viewModel.Id && g.ArticalId == userId);

            go.Venue    = viewModel.Venue;
            go.DateTime = viewModel.GetDateTime();
            go.GenreId  = viewModel.Genre;

            go.Modify(viewModel.GetDateTime(), viewModel.Venue, viewModel.Genre);

            _context.SaveChanges();

            return(RedirectToAction("Mine", "Gos"));
        }
Beispiel #4
0
        public ActionResult Create(GoFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Genres = _context.Genres.ToList();
                return(View("GoForm", viewModel));
            }

            var go = new Go
            {
                ArticalId = User.Identity.GetUserId(),
                DateTime  = viewModel.GetDateTime(),
                //GetDateTime = viewModel.GetDateTime,
                //GetDateTime = GetDateTime.Parse(string.Format("{0} {1}", viewModel.Date, viewModel.Time)),
                GenreId = viewModel.Genre,
                Venue   = viewModel.Venue
            };

            _context.Gos.Add(go);
            _context.SaveChanges();

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