コード例 #1
0
        public async Task <IActionResult> EditTournament(int id)
        {
            Tournament model = tournamentRepository.Get(id);
            TournamentEditViewModel tournamentEditViewModel = new TournamentEditViewModel
            {
                Id                 = model.Id,
                Name               = model.Name,
                Email              = model.Email,
                CityId             = model.CityId,
                Description        = model.Description,
                SportId            = model.SportId,
                Phone              = model.Phone,
                PriceParticipation = model.PriceParticipation,
                PricePerGame       = model.PricePerGame,
                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(tournamentEditViewModel));
        }
コード例 #2
0
        public async Task <IActionResult> CreateorEdit(TournamentEditViewModel tournament)
        {
            token = await GetApiToken();

            HttpClient client = _api.Initial();

            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            if (tournament.TournamentID == 0)
            {
                HttpResponseMessage response = await client.PostAsJsonAsync("tournament", tournament);

                TempData["SuccessMessage"] = "Saved Successfully";
                return(RedirectToAction("Index"));
            }
            else
            {
                HttpResponseMessage response = await client.PutAsJsonAsync("tournament/" + tournament.TournamentID, tournament);

                TempData["SuccessMessage"] = "Updated Successfully";
                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
        public IActionResult EditTournament(TournamentEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Tournament tournament = tournamentRepository.Get(model.Id);
                tournament.Name               = model.Name;
                tournament.Email              = model.Email;
                tournament.CityId             = model.CityId;
                tournament.Description        = model.Description;
                tournament.SportId            = model.SportId;
                tournament.Phone              = model.Phone;
                tournament.PriceParticipation = model.PriceParticipation;
                tournament.PricePerGame       = model.PricePerGame;
                tournament.IsPayed            = model.IsPayed;

                if (model.Image1 != null)
                {
                    if (model.ExistingImage1Path != null)
                    {
                        string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images", model.ExistingImage1Path);
                        System.IO.File.Delete(filePath);
                    }
                    tournament.Image1Path = ProcessUploadFile(model.Image1);
                }

                if (model.Image2 != null)
                {
                    if (model.ExistingImage2Path != null)
                    {
                        string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images", model.ExistingImage2Path);
                        System.IO.File.Delete(filePath);
                    }
                    tournament.Image2Path = ProcessUploadFile(model.Image2);
                }

                tournamentRepository.Update(tournament);

                return(RedirectToAction("Details", "Tournament", new { id = tournament.Id }));
            }

            //return RedirectToAction("EditSportObject");

            Tournament modelOld = tournamentRepository.Get(model.Id);
            TournamentEditViewModel tournamentEditViewModel = new TournamentEditViewModel
            {
                Id                 = modelOld.Id,
                Name               = modelOld.Name,
                Email              = modelOld.Email,
                CityId             = modelOld.CityId,
                Description        = modelOld.Description,
                SportId            = modelOld.SportId,
                Phone              = modelOld.Phone,
                PriceParticipation = modelOld.PriceParticipation,
                PricePerGame       = modelOld.PricePerGame,
                IsPayed            = modelOld.IsPayed,
                ExistingImage1Path = modelOld.Image1Path,
                ExistingImage2Path = modelOld.Image2Path,
                Cities             = sportObjectRepository.GetAllCities(),
                Sports             = sportObjectRepository.GetAllSports()
            };

            return(View(tournamentEditViewModel));
        }