private void PreInit()
        {
            _mockInterestDTO = new InterestDTO()
            {
                Id = 3, InterestDescription = "mock", InterestName = "mock"
            };
            _mockInterest    = Interest.Create("mock", "mock").Value;
            _mockInterest.Id = 3;
            _interestsList   = new List <Interest>()
            {
                Interest.Create("mock", "mock").Value,
                Interest.Create("mock", "mock").Value
            };

            _interestDTOs = new List <InterestDTO>()
            {
                new InterestDTO()
                {
                    Id = 1, InterestDescription = "mock", InterestName = "mock"
                },
                new InterestDTO()
                {
                    Id = 2, InterestDescription = "mock2", InterestName = "mock2"
                }
            };
        }
        public IActionResult Interest([FromBody] InterestModel model)
        {
            InterestDTO dto = Mapping.Mapper.Map <InterestModel, InterestDTO>(model);

            _curriculumService.AddOrUpdateSectionBlock <InterestDTO>(dto, model.FormMode, SectionNames.Interest);

            return(Ok(new { id = model.InterestId }));
        }
        public async Task <ActionResult <InterestDTO> > GetInterest(int id)
        {
            InterestDTO service = await _interestDAO.FindById(id);

            if (service == null)
            {
                return(new NotFoundResult());
            }

            return(new ObjectResult(service));
        }
Beispiel #4
0
        public async Task <InterestDTO> FindById(int id)
        {
            Interest Interest = await _context.Interests
                                .Find(Builders <Interest> .Filter.Eq(s => s.Id, id))
                                .FirstOrDefaultAsync();

            if (Interest == null)
            {
                return(null);
            }

            return(InterestDTO.FromInterest(Interest));
        }
Beispiel #5
0
        public async Task <IEnumerable <InterestDTO> > FindAll()
        {
            IEnumerable <Interest> interests = await _context.Interests.Find(_ => true).ToListAsync();

            List <InterestDTO> result = new List <InterestDTO>();

            foreach (Interest interest in interests)
            {
                result.Add(InterestDTO.FromInterest(interest));
            }

            return(result);
        }
        public IActionResult AddInterest(int id, [FromBody] InterestDTO interest)
        {
            Event eventModel = _repository.Events.GetById(id, true);

            if (eventModel == null)
            {
                return(NotFound());
            }
            Interest newInterest = _mapper.Map <Interest>(interest);

            _repository.Events.AddInterest(eventModel, newInterest);
            _repository.Save();
            return(NoContent());
        }
Beispiel #7
0
        public async Task <IActionResult> Update([FromBody] InterestDTO interestDTO)
        {
            if (interestDTO == null)
            {
                return(BadRequest(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty));
            }
            var result = await _interestService.UpdateInterest(interestDTO);

            if (!result.IsSuccessed)
            {
                return(BadRequest(result.GetErrorString()));
            }
            return(Ok(result.IsSuccessed));
        }
Beispiel #8
0
        public IActionResult AddInterest(string num, [FromBody] InterestDTO interest)
        {
            User user = _repository.Users.GetByNumber(num, true);

            if (user == null)
            {
                return(NotFound());
            }

            Interest newInterest = _mapper.Map <Interest>(interest);

            _repository.Users.AddInterest(user, newInterest);
            _repository.Save();
            return(NoContent());
        }
Beispiel #9
0
        public IActionResult RemoveInterest(string num, [FromBody] InterestDTO interestDto)
        {
            User user = _repository.Users.GetByNumber(num, true);

            if (user == null)
            {
                return(NotFound());
            }
            InterestsUser iu = user.InterestsUsers.Where(x => x.InterestId == interestDto.InterestId).FirstOrDefault();

            if (iu == null)
            {
                return(NotFound());
            }

            user.InterestsUsers.Remove(iu);
            _repository.Save();
            return(NoContent());
        }
Beispiel #10
0
        public async Task Update_Should_Return_Failure_Result_When_There_Is_Issue_While_Saving()
        {
            var testDto = new InterestDTO()
            {
                Id = 1
            };
            var mockInterestsService = new Mock <IInterestService>();

            mockInterestsService.Setup(x => x.UpdateInterest(It.IsAny <InterestDTO>())).ReturnsAsync(Result.Fail(Constants.InterestErrorMessages.Error_Occured_While_Updating_Interest));
            var controller = new InterestController(mockInterestsService.Object);
            var result     = await controller.Update(testDto);

            var contentResult = result as BadRequestObjectResult;

            contentResult.StatusCode.Should().Be(400);
            contentResult.Value.Should().BeAssignableTo <string>();
            var actualValue = contentResult.Value as string;

            actualValue.Should().Be(Constants.InterestErrorMessages.Error_Occured_While_Updating_Interest);
        }
Beispiel #11
0
        public async Task Update_Should_Return_Ok_Result_When_Valid_InterestsDto_Is_Passed()
        {
            var testDto = new InterestDTO()
            {
                Id = 1
            };
            var mockInterestsService = new Mock <IInterestService>();

            mockInterestsService.Setup(x => x.UpdateInterest(It.IsAny <InterestDTO>())).ReturnsAsync(Result.Ok());
            var controller = new InterestController(mockInterestsService.Object);
            var result     = await controller.Update(testDto);

            var contentResult = result as OkObjectResult;

            contentResult.StatusCode.Should().Be(200);
            contentResult.Value.Should().BeAssignableTo <bool>();
            var actualValue = contentResult.Value as bool?;

            actualValue.Should().BeTrue();
        }
        public IActionResult RemoveInterest(int id, [FromBody] InterestDTO interestDto)
        {
            Event eventModel = _repository.Events.GetById(id, true);

            if (eventModel == null)
            {
                return(NotFound());
            }

            Interest       interest          = _mapper.Map <Interest>(interestDto);
            InterestsEvent interestForRemove = eventModel.InterestsEvents.Where(x => x.InterestId == interest.InterestId).FirstOrDefault();

            if (interestForRemove == null)
            {
                return(NotFound());
            }

            eventModel.InterestsEvents.Remove(interestForRemove);
            _repository.Save();
            return(NoContent());
        }
        public async Task UpdateInterest_Should_Return_Success_Result()
        {
            var updatedInterest = new InterestDTO()
            {
                Id = 2, InterestDescription = "sample", InterestName = "sample"
            };
            var mockInterestRepository = new Mock <IInterestRepository>();

            mockInterestRepository.Setup(x => x.GetInterestById(It.IsAny <int>())).ReturnsAsync(Result.Ok(_mockInterest));
            mockInterestRepository.Setup(x => x.Update(It.IsAny <Interest>()));
            mockInterestRepository.Setup(x => x.SaveChangesAsync(It.IsAny <string>())).ReturnsAsync(Result.Ok());

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <Interest>(It.IsAny <InterestDTO>())).Returns(_mockInterest);

            var interestService = new InterestService(mockInterestRepository.Object, mockMapper.Object);
            var result          = await interestService.UpdateInterest(updatedInterest);

            result.IsSuccessed.Should().BeTrue();
        }
Beispiel #14
0
        public async Task <Result> UpdateInterest(InterestDTO interestDTO)
        {
            if (interestDTO == null)
            {
                return(Result.Fail(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty));
            }
            var interest = Interest.Create(interestDTO.InterestName, interestDTO.InterestDescription);

            if (!interest.IsSuccessed)
            {
                return(Result.Fail(interest.GetErrorString()));
            }
            var actualInterest = await _interestRepository.GetInterestById(interestDTO.Id);

            if (!actualInterest.IsSuccessed)
            {
                return(Result.Fail(actualInterest.GetErrorString()));
            }
            actualInterest.Value.UpdateInterest(interest.Value);
            _interestRepository.Update(actualInterest.Value);
            return(await _interestRepository.SaveChangesAsync(InterestErrorMessages.Error_Occured_While_Updating_Interest));
        }