public IActionResult SendInvitations(SendInvitationViewModel model)
        {
            Console.WriteLine("");

            try
            {
                var response = _service.GetAllTeamsFromQuiz(model.QuizId);
                if (response.DidError)
                {
                    return(BadRequest(response.Errors));
                }

                RestClient client = new RestClient();
                client.BaseUrl       = new Uri("https://api.mailgun.net/v3/sandbox3d7deafd31914a929d422e3699215cb8.mailgun.org/messages");
                client.Authenticator = new HttpBasicAuthenticator("api", "97cfda12723cac0322b1040bf1c133f3-ba042922-43f2ab8e");

                foreach (var team in response.DTO)
                {
                    var         pin     = Guid.NewGuid().ToString();
                    RestRequest request = new RestRequest();
                    request.AddParameter("domain", "sandbox3d7deafd31914a929d422e3699215cb8.mailgun.org", ParameterType.UrlSegment);
                    //request.Resource = "{domain}/messages";
                    request.AddParameter("from", "Excited User <*****@*****.**>");
                    request.AddParameter("to", team.Email);
                    //request.AddParameter("to", "*****@*****.**");
                    request.AddParameter("subject", "Invitation to play in a quiz!");
                    var message = model.Message + "\n \nHere is you pin to get access to the quiz: " + pin;
                    if (model.PaypalLink != "")
                    {
                        message += "\n \nHere is the link where you can pay before you can play the quiz: " + model.PaypalLink;
                    }
                    request.AddParameter("text", message);
                    request.Method = Method.POST;
                    var responseClient = client.Execute(request);

                    if (responseClient.IsSuccessful)
                    {
                        team.PIN    = pin;
                        team.QuizId = model.QuizId;


                        var teamResponse = _teamService.Update(team);
                        if (teamResponse.DidError)
                        {
                            return(BadRequest(teamResponse.Errors));
                        }
                        var teamReturn = TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(teamResponse.DTO);
                        return(Ok(teamReturn));
                    }
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #2
0
        public IActionResult GetAllTeamsFromOneUser(string email)
        {
            var teamDTOs = _service.GetAllTeamsFromOneUser(email);

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

            var teamModels = new List <TeamViewModelResponse>();

            foreach (var team in teamDTOs)
            {
                teamModels.Add(TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(team));
            }

            return(Ok(teamModels));
        }
Example #3
0
        public IActionResult Update(TeamViewModelResponse teamViewModel)
        {
            try
            {
                var teamDTO = TeamViewModelMapper.MapTeamViewModelResponseToDTO(teamViewModel);

                var team = _service.Update(teamDTO);
                if (team.DidError)
                {
                    return(BadRequest(team.Errors));
                }
                var teamReturn = TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(team.DTO);
                return(Ok(teamReturn));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #4
0
        public IActionResult GetById(int id)
        {
            try
            {
                var response = _service.FindTeam(id);
                if (response.DidError)
                {
                    return(BadRequest(response.Errors));
                }

                var teamViewModel = TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(response.DTO);

                return(Ok(teamViewModel));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public void GetAllTeamsCorrect()
        {
            var teamDTOs = new List <TeamDTO>();

            teamDTOs.Add(new TeamDTO
            {
                Id   = 1,
                Naam = "Team A"
            });

            IQueryable <TeamDTO> queryableTeamDTOs = teamDTOs.AsQueryable();

            var teamModels = new List <TeamViewModelResponse>();

            foreach (var team in teamDTOs)
            {
                teamModels.Add(TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(team));
            }

            //Arange

            var mockService = new Mock <ITeamService>();

            mockService.Setup(x => x.GetAllTeams()).Returns(queryableTeamDTOs);
            var controller = new TeamController(mockService.Object);


            //Act
            var alleTeam = controller.GetAll() as ObjectResult;

            var ListQuizen = alleTeam.Value as List <TeamViewModelResponse>;


            //Assert
            Assert.That(ListQuizen.Count(), Is.EqualTo(teamModels.Count()));

            for (int i = 0; i < ListQuizen.Count(); i++)
            {
                Assert.That(ListQuizen.ToArray()[i].Id, Is.EqualTo(teamModels.ToArray()[i].Id));
                Assert.That(ListQuizen.ToArray()[i].Naam, Is.EqualTo(teamModels.ToArray()[i].Naam));
            }
        }
Example #6
0
        public IActionResult Create(TeamViewModelRequest teamViewModel)
        {
            try
            {
                var createDTO = TeamViewModelMapper.MapTeamViewModelRequestToTeamDTO(teamViewModel);
                var response  = _service.AddTeam(createDTO);


                if (response.DidError)
                {
                    return(BadRequest(response.Errors));
                }

                var createdTeam = TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(response.DTO);

                return(Ok(createdTeam));
            }
            catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
        public IActionResult GetAllTeamsFromQuiz(int quizId)
        {
            try
            {
                var response = _service.GetAllTeamsFromQuiz(quizId);
                if (response.DidError)
                {
                    return(BadRequest(response.Errors));
                }
                List <TeamViewModelResponse> responseList = new List <TeamViewModelResponse>();

                foreach (var item in response.DTO)
                {
                    responseList.Add(TeamViewModelMapper.MapTeamDTOToTeamViewModelResponse(item));
                }

                return(Ok(responseList));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }