Esempio n. 1
0
        public ActionResult Create(CreateClimbViewModel createClimb)
        {
            Climb climb = new Climb();
            if (TryUpdateModel(climb))
            {
                climb.Climber = db.Users.Single(u => u.UserName == User.Identity.Name);
                climb.Date = DateTime.Now;

                db.Climbs.Add(climb);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(climb);
        }
Esempio n. 2
0
        //
        // GET: /Climb/Create
        public ActionResult Create()
        {
            var viewModel = new CreateClimbViewModel();

            var userId = db.Users.Single(u => u.UserName == User.Identity.Name).Id;
            var lastLocation = db.Climbs
                .Where(c => c.ClimberId == userId)
                .OrderByDescending(c => c.Date)
                .Select(c => c.Route.LocationId)
                .FirstOrDefault();

            viewModel.LocationId = lastLocation;

            ViewBag.Locations = db.Locations.ToList();
            ViewBag.LastLocation = lastLocation;

            ViewBag.Routes = db.Routes.ToList();
            ViewBag.ClimbTypes = db.ClimbTypes.ToList();

            return View(viewModel);
        }