public IActionResult CreateSportObject()
        {
            var model = new SportObjectCreateViewModel {
                Cities = sportObjectRepository.GetAllCities(),
                Sports = sportObjectRepository.GetAllSports()
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> EditSportObject(int id)
        {
            SportObject model = sportObjectRepository.Get(id);
            SportObjectEditViewModel sportObjectEditViewModel = new SportObjectEditViewModel
            {
                Id                 = model.Id,
                Name               = model.Name,
                Email              = model.Email,
                Address            = model.Address,
                CityId             = model.CityId,
                WorkEnds           = model.WorkEnds,
                WorkStarts         = model.WorkStarts,
                Description        = model.Description,
                SportId            = model.SportId,
                Phone              = model.Phone,
                PriceForHour       = model.PriceForHour,
                IsPayed            = model.IsPayed,
                ExistingImage1Path = model.Image1Path,
                ExistingImage2Path = model.Image2Path,
                Cities             = sportObjectRepository.GetAllCities(),
                Sports             = sportObjectRepository.GetAllSports()
            };

            if (User.IsInRole("Client"))
            {
                var user = await userManager.FindByIdAsync(User.FindFirstValue(ClaimTypes.NameIdentifier));

                if (user == null)
                {
                    ViewBag.ErrorMessage = $"User with ID = {user.Id} cannot be found";
                    return(View("NotFound"));
                }

                if (user.Email != model.Email)
                {
                    return(RedirectToAction("AccessDenied", "Administration"));
                }
            }

            return(View(sportObjectEditViewModel));
        }