public void Put(int id, [FromBody] StadiumViewModel stadiumView)
        {
            if (id != stadiumView.id)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            stadiumBll.SaveStadium(stadiumView.ToBaseModel());
        }
Exemple #2
0
        public IActionResult Edit(int id)
        {
            var stadium          = stadiumService.Get(id);
            var stadiumViewModel = new StadiumViewModel
            {
                Id             = id,
                Name           = stadium.Name,
                FoundedOn      = stadium.FoundedOn,
                Capacity       = stadium.Capacity,
                CountryId      = stadium.Country.Id,
                CountryName    = stadium.Country.Name,
                CountriesItems = countryService.GetAllAsKeyValuePairs()
            };

            return(View(stadiumViewModel));
        }
Exemple #3
0
 public ActionResult Create(StadiumViewModel stadium)
 {
     try
     {
         var stadiumDTO = new StadiumDTO {
             Name = stadium.Name
         };
         stadiumService.Create(stadiumDTO);
         return(RedirectToAction("Index"));
     }
     catch (ValidationException ex)
     {
         ModelState.AddModelError(ex.Property, ex.Message);
     }
     return(View(stadium));
 }
Exemple #4
0
        public IActionResult Delete(int id)
        {
            var stadium          = stadiumService.Get(id);
            var stadiumViewModel = new StadiumViewModel
            {
                Id          = id,
                Name        = stadium.Name,
                FoundedOn   = stadium.FoundedOn,
                Capacity    = stadium.Capacity,
                CountryId   = stadium.Country.Id,
                CountryName = stadium.Country.Name,
            };

            ViewData["EntityName"] = "Stadium";

            return(View("../Shared/_Delete", stadiumViewModel));
        }
Exemple #5
0
        public async Task <IActionResult> Delete(StadiumViewModel stadiumViewModel)
        {
            try
            {
                await stadiumService.DeleteAsync(stadiumViewModel.Id);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.InnerException?.Message ?? ex.Message);
                ViewData["EntityName"] = "Stadium";

                return(View("../Shared/_Delete", stadiumViewModel));
            }

            TempData["SuccessMessage"] = "Stadium deleted successfully.";

            return(RedirectToAction("Index"));
        }
        void EditClub(object parameter)
        {
            if (!ValidateParams(parameter))
            {
                ShowInfoWindow("Podaj poprawne dane");
                return;
            }
            var              values      = (object[])parameter;
            string           newName     = values[0].ToString();
            StadiumViewModel newStadium  = (StadiumViewModel)values[1];
            RecordViewModel  newRecord   = (RecordViewModel)values[2];
            ClubViewModel    currentClub = (ClubViewModel)values[3];

            if (clubService.EditClub(newName, newStadium.ID, newRecord.ID, currentClub.ID))
            {
                RefereshAll();
            }
        }
        void EditStadium(object parameter)
        {
            if (!ValidateParams(parameter))
            {
                ShowInfoWindow("Podaj poprawne dane");
                return;
            }
            var              values         = (object[])parameter;
            string           newName        = values[0].ToString();
            string           newCity        = values[1].ToString();
            string           newCountry     = values[2].ToString();
            StadiumViewModel currentStadium = (StadiumViewModel)values[3];

            if (stadiumService.EditStadium(newName, newCity, newCountry, currentStadium.ID))
            {
                RefereshAll();
            }
        }
Exemple #8
0
        public StadiumViewModel StadiumDetails(int id)
        {
            _logger.LogInformation($"StadiumDetails- id: {id}");

            Stadium stadium = GetSingleStadiumById(id);
            Club    club    = GetSingleClubByClubId(stadium.ClubId);

            StadiumViewModel stadiumVM = new StadiumViewModel()
            {
                StadiumId    = stadium.StadiumId,
                StadiumName  = stadium.StadiumName,
                Location     = stadium.Location,
                BuildDate    = stadium.BuildDate,
                StadiumImage = stadium.StadiumImage,
                ClubName     = club.ClubName
            };

            return(stadiumVM);
        }
Exemple #9
0
        public static Stadium ToBaseModel(this StadiumViewModel stadiumViewModel)
        {
            if (stadiumViewModel == null)
            {
                return(null);
            }

            return(new Stadium()
            {
                Address = stadiumViewModel.address,
                Capacity = stadiumViewModel.capacity,
                cityId = stadiumViewModel.cityId,
                Description = stadiumViewModel.description,
                Id = stadiumViewModel.id,
                Image = stadiumViewModel.image,
                Name = stadiumViewModel.name,
                NameFull = stadiumViewModel.nameFull
            });
        }
        public void AddStadiumToDb(StadiumViewModel stadiumVm)
        {
            var stadiumExists = this.stadiumRepository
                                .GetAllFiltered(s => s.Name == stadiumVm.Name && s.Capacity == stadiumVm.Capacity)
                                .Any();

            if (stadiumExists)
            {
                throw new InvalidOperationException();
            }

            var stadium = new Stadium()
            {
                Name     = stadiumVm.Name,
                Capacity = stadiumVm.Capacity
            };

            this.stadiumRepository.Add(stadium);
        }
        public async Task CreateAsync(StadiumViewModel stadiumViewModel)
        {
            var doesStadiumExist = stadiumRepository.All().Any(c => c.Name == stadiumViewModel.Name);

            if (doesStadiumExist)
            {
                throw new Exception($"Stadium with a name {stadiumViewModel.Name} already exists.");
            }

            var stadium = new Stadium
            {
                Name      = stadiumViewModel.Name,
                FoundedOn = stadiumViewModel.FoundedOn,
                Capacity  = stadiumViewModel.Capacity,
                Country   = countryRepository.Get(stadiumViewModel.CountryId)
            };

            await stadiumRepository.AddAsync(stadium);

            await stadiumRepository.SaveChangesAsync();
        }
        public async Task SaveAndLoadStadiumWithRelatedData()
        {
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "Spain", Code = "SP"
                }
            };
            var stadiumsList = new List <Stadium>();

            var mockCountryRepo = new Mock <IRepository <Country> >();

            mockCountryRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => countriesList.FirstOrDefault(c => c.Id == id));

            var mockStadiumRepo = new Mock <IRepository <Stadium> >();

            mockStadiumRepo.Setup(r => r.All()).Returns(stadiumsList.AsQueryable()); mockStadiumRepo.Setup(r => r.AddAsync(It.IsAny <Stadium>())).Callback <Stadium>(stadium => stadiumsList.Add(new Stadium
            {
                Id       = 1,
                Name     = stadium.Name,
                Capacity = stadium.Capacity,
                Country  = stadium.Country
            }));

            var stadiumService = new StadiumService(mockStadiumRepo.Object, mockCountryRepo.Object);

            var stadiumViewModel = new StadiumViewModel
            {
                Name      = "Santiago Bernabeu",
                Capacity  = 80000,
                FoundedOn = DateTime.Now,
                CountryId = 1
            };

            await stadiumService.CreateAsync(stadiumViewModel);

            var savedStadium = stadiumService.Get(1, true);

            Assert.Equal("Santiago Bernabeu", savedStadium.Name);
            Assert.Equal(80000, savedStadium.Capacity);
        }
Exemple #13
0
        private void AddMatch(object parameter)
        {
            if (!ValidateParams(parameter))
            {
                ShowInfoWindow("Podaj poprawne dane");
                return;
            }
            var values = (object[])parameter;

            StadiumViewModel stadionName      = (StadiumViewModel)values[0];
            ClubViewModel    hostName         = (ClubViewModel)values[1];
            ClubViewModel    guestName        = (ClubViewModel)values[2];
            ReffereViewModel mainReffere      = (ReffereViewModel)values[3];
            ReffereViewModel technicalReffere = (ReffereViewModel)values[4];
            ReffereViewModel linearReffere    = (ReffereViewModel)values[5];
            ReffereViewModel observerReffere  = (ReffereViewModel)values[6];
            int hostGoals  = Int32.Parse((string)values[7].ToString());
            int guestGoals = Int32.Parse((string)values[8].ToString());

            matchService.AddMatch(stadionName.ID, hostName.ID, guestName.ID, mainReffere.ID, technicalReffere.ID, linearReffere.ID, observerReffere.ID, hostGoals, guestGoals);
            UpdateMatchGrid();
        }
        public void Post([FromBody] StadiumViewModel stadiumView)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            int teamId = stadiumBll.SaveStadium(stadiumView.ToBaseModel());

            // move images from temp folder
            if (teamId > 0 &&
                !string.IsNullOrWhiteSpace(stadiumView.image) &&
                stadiumView.tempGuid.HasValue)
            {
                string tempGuid    = stadiumView.tempGuid.ToString();
                string storagePath = MainCfg.Images.Teams.Replace("{id}", teamId.ToString());
                string tempPath    = MainCfg.Images.Teams.Replace("{id}", tempGuid);

                LocalStorageHelper.MoveFromTempToStorage(storagePath, tempPath, tempGuid);
            }
        }
        public async Task SaveAndDeleteStadium()
        {
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "Spain", Code = "SP"
                }
            };
            var stadiumsList = new List <Stadium>();

            var mockCountryRepo = new Mock <IRepository <Country> >();

            mockCountryRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => countriesList.FirstOrDefault(c => c.Id == id));

            var mockStadiumRepo = new Mock <IRepository <Stadium> >();

            mockStadiumRepo.Setup(r => r.All()).Returns(stadiumsList.AsQueryable());
            mockStadiumRepo.Setup(r => r.AddAsync(It.IsAny <Stadium>())).Callback <Stadium>(stadium => stadiumsList.Add(new Stadium
            {
                Id       = 1,
                Name     = stadium.Name,
                Capacity = stadium.Capacity,
                Country  = stadium.Country
            }));
            mockStadiumRepo.Setup(r => r.Delete(It.IsAny <Stadium>())).Callback <Stadium>(stadium => stadiumsList.Remove(stadium));

            var stadiumService = new StadiumService(mockStadiumRepo.Object, mockCountryRepo.Object);

            var stadiumViewModel = new StadiumViewModel
            {
                Name      = "Santiago Bernabeu",
                CountryId = 1
            };

            await stadiumService.CreateAsync(stadiumViewModel);

            await stadiumService.DeleteAsync(1);

            Assert.Empty(stadiumService.GetAll(false));
        }
        public async Task SaveTwoStadiumsWithSameNames()
        {
            var countriesList = new List <Country> {
                new Country {
                    Id = 1, Name = "Spain", Code = "SP"
                }
            };
            var stadiumsList = new List <Stadium>();

            var mockCountryRepo = new Mock <IRepository <Country> >();

            mockCountryRepo.Setup(r => r.Get(It.IsAny <int>())).Returns <int>(id => countriesList.FirstOrDefault(c => c.Id == id));

            var mockStadiumRepo = new Mock <IRepository <Stadium> >();

            mockStadiumRepo.Setup(r => r.All()).Returns(stadiumsList.AsQueryable());
            mockStadiumRepo.Setup(r => r.AddAsync(It.IsAny <Stadium>())).Callback <Stadium>(stadium => stadiumsList.Add(stadium));

            var stadiumService = new StadiumService(mockStadiumRepo.Object, mockCountryRepo.Object);

            var firstStadiumViewModel = new StadiumViewModel
            {
                Name      = "Santiago Bernabeu",
                CountryId = 1
            };

            var secondStadiumViewModel = new StadiumViewModel
            {
                Name      = "Santiago Bernabeu",
                CountryId = 1
            };

            await stadiumService.CreateAsync(firstStadiumViewModel);

            await Assert.ThrowsAsync <Exception>(() => stadiumService.CreateAsync(secondStadiumViewModel));
        }
        public async Task UpdateAsync(StadiumViewModel stadiumViewModel)
        {
            var allStadiums = stadiumRepository.All();
            var stadium     = allStadiums.FirstOrDefault(c => c.Id == stadiumViewModel.Id);

            if (stadium is null)
            {
                throw new Exception($"Stadium not found");
            }

            var doesStadiumExist = allStadiums.Any(c => c.Id != stadiumViewModel.Id && c.Name == stadiumViewModel.Name);

            if (doesStadiumExist)
            {
                throw new Exception($"Stadium with a name {stadiumViewModel.Name} already exists.");
            }

            stadium.Name      = stadiumViewModel.Name;
            stadium.FoundedOn = stadiumViewModel.FoundedOn;
            stadium.Capacity  = stadiumViewModel.Capacity;
            stadium.Country   = countryRepository.Get(stadiumViewModel.CountryId);

            await stadiumRepository.SaveChangesAsync();
        }
Exemple #18
0
        void EditMatch(object parameter)
        {
            if (!ValidateParams(parameter))
            {
                ShowInfoWindow("Podaj poprawne dane");
                return;
            }
            var values = (object[])parameter;
            StadiumViewModel stadionName      = (StadiumViewModel)values[0];
            ClubViewModel    hostName         = (ClubViewModel)values[1];
            ClubViewModel    guestName        = (ClubViewModel)values[2];
            ReffereViewModel mainReffere      = (ReffereViewModel)values[3];
            ReffereViewModel technicalReffere = (ReffereViewModel)values[4];
            ReffereViewModel linearReffere    = (ReffereViewModel)values[5];
            ReffereViewModel observerReffere  = (ReffereViewModel)values[6];
            int            hostGoals          = Int32.Parse((string)values[7].ToString());
            int            guestGoals         = Int32.Parse((string)values[8].ToString());
            MatchViewModel currentMatch       = (MatchViewModel)values[9];

            if (matchService.EditMatch(stadionName.ID, hostName.ID, guestName.ID, mainReffere.ID, technicalReffere.ID, linearReffere.ID, observerReffere.ID, hostGoals, guestGoals, currentMatch.ID))
            {
                RefereshAll();
            }
        }