public async Task <IActionResult> AddRequestNewClub(AddClubInputModel model)
        {
            bool isFileValid = true;

            if (model.ImageFile != null)
            {
                isFileValid = this.clubService.IsFileValid(model.ImageFile);
            }

            if (ModelState.IsValid && isFileValid && model.Interests.Any() == true)
            {
                string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                await this.clubService.AddRequestNewClub(model, userId);

                return(this.Redirect("/Home/Index"));
            }

            if (model.Interests.Any() == false)
            {
                ModelState.AddModelError(ClubFields.Interests, ErrorMessages.ClubInterestsRequired);
            }

            var interests = this.clubService.GetInterests();

            model.InterestsToList = interests;
            return(this.View(model));
        }
Beispiel #2
0
        public async Task <RequestNewClub> AddRequestNewClub(AddClubInputModel model, string userId)
        {
            string currentUrl = await this.cloudinaryService.UploadImage(model.ImageFile);

            User user = await this.userService.FindUserById(userId);

            RequestNewClub requestNewClub = new RequestNewClub
            {
                Name        = model.Name,
                Fee         = (decimal)model.Fee,
                PriceType   = (PriceType)Enum.Parse(typeof(PriceType), model.PriceType, true),
                IsPublic    = (bool)model.IsPublic,
                Description = model.Description,
                Town        = model.Town,
                PictureUrl  = currentUrl != "" ? currentUrl : defaultPictureUrl,
                Interests   = this.userService.InterestsToString(model.Interests),
                Author      = user,
                AuthorId    = user.Id
            };

            var result = await this.dbContext.RequestNewClubs.AddAsync(requestNewClub);

            await this.dbContext.SaveChangesAsync();

            return(result.Entity);
        }
        public IActionResult AddRequestNewClub()
        {
            AddClubInputModel model = new AddClubInputModel();
            var interests           = this.clubService.GetInterests();

            model.InterestsToList = interests;
            return(this.View(model));
        }
        public async Task <IActionResult> AddClub()
        {
            AddClubInputModel model = new AddClubInputModel();
            var interests           = this.clubService.GetInterests();

            model.InterestsToList = interests;
            return(this.View(model));
        }
        public async Task AddClubAsync_ThrowsException_NullInput()
        {
            //arrange
            IEntityGateway     entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddClubPresenter  presenter     = new FakeAddClubPresenter(_output);
            IAddClubInteractor interactor    = new AddClubInteractor(presenter, entityGateway);
            AddClubInputModel  inputModel    = null;

            //act
            async Task <CommandResult <AddClubOutputModel> > function() => await interactor.AddClubAsync(inputModel);

            //assert
            await Assert.ThrowsAsync <ArgumentNullException>(function);
        }
        public async Task <IActionResult> AddClub(AddClubInputModel model)
        {
            if (ModelState.IsValid)
            {
                string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                await this.clubService.AddClub(model, userId);

                return(this.Redirect("/Home/Index"));
            }

            var interests = this.clubService.GetInterests();

            model.InterestsToList = interests;
            return(this.View(model));
        }
        public async Task AddClubAsync_FailedModelValidation_NullName()
        {
            //arrange
            IEntityGateway     entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddClubPresenter  presenter     = new FakeAddClubPresenter(_output);
            IAddClubInteractor interactor    = new AddClubInteractor(presenter, entityGateway);
            AddClubInputModel  inputModel    = new AddClubInputModel();

            //act
            var result = await interactor.AddClubAsync(inputModel);

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.FailedModelValidation);
            Assert.True(result.ModelValidationErrors.ContainsKey(Domain.Common.ModelValidationStatusCode.RequiredInformationMissing));
        }
Beispiel #8
0
        // methods
        public async Task <CommandResult <AddClubOutputModel> > AddClubAsync(AddClubInputModel inputModel)
        {
            _inputModel = inputModel ?? throw new ArgumentNullException(nameof(inputModel));
            _clubToAdd  = new Club(inputModel.ToClubModel());

            if (!_clubToAdd.IsValid)
            {
                return(PresentValidationErrors());
            }

            if (await IsClubAlreadyStoredAsync())
            {
                return(PresentDuplicatedResult());
            }

            _clubToAdd = await SaveToStorageAsync();

            return(PresentSuccessfulResult());
        }
        public async Task AddClubAsync_CommandResult_Success()
        {
            //arrange
            IEntityGateway     entityGateway = InMemoryEntityGatewayFactory.CreateEntityGateway();
            IAddClubPresenter  presenter     = new FakeAddClubPresenter(_output);
            IAddClubInteractor interactor    = new AddClubInteractor(presenter, entityGateway);
            AddClubInputModel  inputModel    = new AddClubInputModel {
                Name = "C# Knights"
            };

            //act
            var result = await interactor.AddClubAsync(inputModel);

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.Success);
            Assert.Null(result.ModelValidationErrors);
            Assert.NotNull(result.OutputModel);
            Assert.True(result.OutputModel.Id != Guid.Empty);
        }
        public async Task AddClubAsyncExistingClubNameDifferentCase_CommandResult_DuplicateEntry()
        {
            //arrange
            string duplicatedClubName = "C# Knights";
            var    clubsToPreload     = new Club[] { new Club {
                                                         Name = duplicatedClubName
                                                     } };
            IEntityGateway entityGateway = await InMemoryEntityGatewayFactory.CreateEntityGatewayAsync(clubsToPreload);

            IAddClubPresenter  presenter  = new FakeAddClubPresenter(_output);
            IAddClubInteractor interactor = new AddClubInteractor(presenter, entityGateway);
            AddClubInputModel  inputModel = new AddClubInputModel {
                Name = duplicatedClubName.ToLowerInvariant()
            };

            //act
            var result = await interactor.AddClubAsync(inputModel);

            //assert
            Assert.NotNull(result);
            Assert.True(result.Status == Application.Common.CommandResultStatusCode.DuplicateEntry);
        }