示例#1
0
        public async Task <IActionResult> Create([Bind("StatID,PullUp,PushUp,HangEdge,HangWeight,HighestSportGrade,HighestBoulderingGrade,UserID")] Stat stat)
        {
            stat.UserID = UserIDSess;



            _context.PullUps.Add(new PullUp
            {
                NPullUp = stat.PullUp,
                StatID  = stat.StatID
            }
                                 );



            _context.PushUps.Add(new PushUp
            {
                NPushUp = stat.PushUp,
                StatID  = stat.StatID
            }
                                 );


            _context.HangEdges.Add(new HangEdge
            {
                NHangEdge = stat.HangEdge,
                StatID    = stat.StatID
            }
                                   );



            _context.HangWeights.Add(new HangWeight
            {
                NHangWeight = stat.HangWeight,
                StatID      = stat.StatID
            }
                                     );


            if (ModelState.IsValid)
            {
                _context.Update(stat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            var sport = from SportClimbingGrade s in Enum.GetValues(typeof(SportClimbingGrade))
                        select new { ID = (int)s, Name = s.GetDescription() };

            var boulder = from BoulderingClimbingGrade b in Enum.GetValues(typeof(BoulderingClimbingGrade))
                          select new { ID = (int)b, Name = b.GetDescription() };

            ViewData["Sport"]   = new SelectList(sport, "ID", "Name");
            ViewData["Boulder"] = new SelectList(boulder, "ID", "Name");
            ViewData["UserID"]  = UserIDSess;

            return(View(stat));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("BoulderAverageID,PullUps,PushUps,HangEdge,HangWeight,RowVersion")] BoulderAverage boulderAverage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(boulderAverage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(boulderAverage));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("SportID,Name,Area,Location,SportClimbingGrade,ConsensusGrade,ModifyDate")] Sport sport)
        {
            sport.ModifyDate = DateTime.Now;
            if (ModelState.IsValid)
            {
                _context.Add(sport);
                await _context.SaveChangesAsync();

                return(Redirect("/Logbook/create"));
            }
            return(View(sport));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("BoulderID,Name,Area,Location,BoulderingClimbingGrade,ConsensusGrade,ModifyDate")] Boulder boulder)
        {
            boulder.ModifyDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                _context.Add(boulder);
                await _context.SaveChangesAsync();

                return(Redirect("/Logbook/create"));
            }
            return(View(boulder));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("LogID,Type,ModifyDate,BoulderID,SportID,UserID")] Log log)
        {
            if (ModelState.IsValid)
            {
                _context.Add(log);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BoulderID"] = new SelectList(_context.Boulders, "BoulderID", "Name", log.BoulderID);
            ViewData["SportID"]   = new SelectList(_context.Sports, "SportID", "Name", log.SportID);
            ViewData["UserID"]    = new SelectList(_context.Users, "UserID", "UserID", log.UserID);
            return(View(log));
        }
示例#6
0
        public async Task <IActionResult> Edit(string id, [Bind("UserID,Weight,Height,ApeIndex,StatID")] User user)
        {
            if (id != user.UserID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.UserID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
示例#7
0
        // Add a user upon new signup and add a sesssion
        public User Authenticate(string id)
        {
            var user = _context.Users.Find(id);


            if (user == null)
            {
                User userNew = new User
                {
                    UserID = id
                };

                Stat stat = new Stat
                {
                    UserID = id
                };


                _context.Users.Add(userNew);

                _context.Stats.Add(stat);

                _context.SaveChangesAsync();
            }

            if (UserIDSess != id)
            {
                _httpContextAccessor.HttpContext.Session.SetString("oic", id);
            }

            // authentication successful
            return(null);
        }
示例#8
0
        public async Task<IActionResult> Create(CreateLogViewModel viewModel)
        {

            viewModel.Log.UserID = UserIDSess;
            viewModel.Boulders = await _context.Boulders.ToListAsync();
            viewModel.SportClimbs = await _context.Sports.ToListAsync();


            if (viewModel.Log.Type == ClimbType.Boulder) {
                viewModel.Log.BoulderID = viewModel.climbID;
            }
            else {
                viewModel.Log.SportID = viewModel.climbID;
            }


            Log log = new Log
            {
                Type = viewModel.Log.Type,
                UserID = UserIDSess,
                ModifyDate = viewModel.Log.ModifyDate

            };
            Debug.WriteLine("checking select valuye" + viewModel.climbID);

            if (viewModel.Log.Type == ClimbType.Boulder)
            {
                if (viewModel.climbID == null)
                {
                    ModelState.AddModelError(nameof(viewModel.climbID), "Must select a climb.");
                }
                log.BoulderID = viewModel.climbID;

            }
            else
            {
                if (viewModel.climbID == null)
                {
                    
                    ModelState.AddModelError(nameof(viewModel.climbID), "Must select a climb.");
                }
                log.SportID = viewModel.climbID;
            }


            if (ModelState.IsValid)
            {

                _context.Logs.Add(log);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }



            var List1 = viewModel.Boulders.Select(
              c => new
              {
                  c.Area
              });

            var List2 = viewModel.SportClimbs.Select(
            c => new
            {
                c.Area
            });
            Debug.WriteLine(viewModel.SportClimbs);
            Debug.WriteLine(List1.Concat(List2).Distinct().ToList());

            var aList = List1.Concat(List2).Distinct().ToList();

            ViewData["Area"] = new SelectList(aList, "Area", "Area");
            return View(viewModel);

        }