Example #1
0
        public IActionResult Delete(int gymId)
        {
            string id       = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var    UserGyms = _usersGymsRepo.GetByUserIdAndGymId(id, gymId);

            if (id == null || gymId == 0)
            {
                return(BadRequest("Wrong gymid or userid"));
            }

            try
            {
                _usersGymsRepo.Delete(UserGyms);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.InnerException.Message);
                ModelState.AddModelError("0", e.InnerException.Message);
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(BadRequest($"{e.Message}"));
            }

            return(Ok());
        }
Example #2
0
        public async Task <IActionResult> Index(int id, int Length = 0)
        {
            if (id == 0)
            {
                return(BadRequest("Wrong id"));
            }

            var gym = _gymRepo.Get(id);

            if (gym == null)
            {
                return(NotFound());
            }

            if (Length != 0)
            {
                ViewData["Errors"] = "error";
            }
            var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            ViewData["CurrentUserId"] = userId;

            //userId gym.id
            if (_userRepo.GetByUserIdAndGymId(userId, gym.Id) == null)
            {
                ViewData["MyGym"] = false;
            }
            else
            {
                ViewData["MyGym"] = true;
            }

            if (userId == null)
            {
                userId = "";
            }
            var user = await _userManager.FindByIdAsync(userId);

            if (user != null)
            {
                ViewData["LoggedIn"]         = true;
                ViewData["CurrentUserName"]  = user.FullName;
                ViewData["CurrentUserLogin"] = user.UserName;
            }
            else
            {
                ViewData["LoggedIn"]         = false;
                ViewData["CurrentUserName"]  = "";
                ViewData["CurrentUserLogin"] = "";
            }

            return(View(gym));
        }