コード例 #1
0
        public async Task <IActionResult> Create(ArenaCreateInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                var location  = this.GetLocation();
                var countryId = await this.countriesService.GetIdAsync(location.Country);

                inputModel.Sports = await this.sportsService.GetAllAsSelectListAsync();

                inputModel.Countries = await this.countriesService.GetAllAsSelectListAsync();

                inputModel.Cities = await this.citiesService.GetAllInCountryByIdAsync(countryId);

                inputModel.CountryId = countryId;
                inputModel.CityId    = await this.citiesService.GetIdAsync(location.City, countryId);

                return(this.View(inputModel));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.arenasService.CreateAsync(inputModel, user.Id, user.Email, user.UserName);

            this.TempData[TempDataMessage] = string.Format(ArenaCreated, inputModel.Name);

            return(this.RedirectToAction(nameof(this.MyArena)));
        }
コード例 #2
0
        public async Task <IActionResult> Create()
        {
            var user = await this.userManager.GetUserAsync(this.User);

            if (await this.usersService.IsUserHasArenaAsync(user.Id))
            {
                return(this.RedirectToAction(nameof(this.MyArena)));
            }

            var location  = this.GetLocation();
            var countryId = await this.countriesService.GetIdAsync(location.Country);

            var viewModel = new ArenaCreateInputModel
            {
                Sports      = await this.sportsService.GetAllAsSelectListAsync(),
                Countries   = await this.countriesService.GetAllAsSelectListAsync(),
                Cities      = await this.citiesService.GetAllInCountryByIdAsync(countryId),
                CountryName = location.Country,
                CityName    = location.City,
                CountryId   = countryId,
                CityId      = await this.citiesService.GetIdAsync(location.City, countryId),
            };

            return(this.View(viewModel));
        }
コード例 #3
0
        public async Task CreateAsyncAddArenaInDb()
        {
            var inputModel = new ArenaCreateInputModel
            {
                Name         = "newArena",
                SportId      = 1,
                CityId       = 1,
                CountryId    = 1,
                PricePerHour = 20,
                Status       = ArenaStatus.Active,
                PhoneNumber  = "0877777777",
            };

            await this.Service.CreateAsync(inputModel, this.userId, "email", "username");

            Assert.Equal(3, this.DbContext.Arenas.Count());
        }
コード例 #4
0
        public async Task CreateAsync(ArenaCreateInputModel inputModel, string userId, string userEmail, string username)
        {
            var arena = inputModel.To <Arena>();

            arena.ArenaAdminId = userId;

            if (inputModel.MainImageFile != null)
            {
                var avatar = await this.imagesService.CreateAsync(inputModel.MainImageFile);

                arena.MainImageId = avatar.Id;
            }

            if (inputModel.ImageFiles != null)
            {
                foreach (var img in inputModel.ImageFiles)
                {
                    var image = await this.imagesService.CreateAsync(img);

                    arena.Images.Add(image);
                }
            }

            await this.arenasRepository.AddAsync(arena);

            await this.arenasRepository.SaveChangesAsync();

            var sportName = await this.sportsService.GetNameByIdAsync(inputModel.SportId);

            await this.emailSender.SendEmailAsync(
                userEmail,
                EmailSubjectConstants.ArenaCreated,
                EmailHtmlMessages.GetArenaCreationHtml(
                    username,
                    inputModel.Name,
                    sportName));
        }