Esempio n. 1
0
        public async Task ApproveGymApplication()
        {
            bool added = await applicationRepository.addApplication(
                new GymApplications {
                Name        = "Longji",
                Surname     = "Kang",
                Email       = "*****@*****.**",
                PhoneNumber = "0629058357",
                GymName     = "Test",
                BranchName  = "Gym2",
                Address     = "An address",
                Extra       = "None",
                Status      = ApplicationStatus.Pending
            }
                );

            Assert.True(added);

            SetApplicationState request = new SetApplicationState {
                status     = "Approve",
                GymName    = "Test",
                BranchName = "Gym2"
            };

            var response = await gymApplicationController.AcceptApplications(request);

            Assert.IsType <OkObjectResult>(response.Result);

            bool removed = await applicationRepository.removeApplication((await applicationRepository.getApplication("Test", "Gym2"))[0]);

            Assert.True(removed);
        }
Esempio n. 2
0
        public async Task <ActionResult <GymApplications[]> > AcceptApplications(SetApplicationState request)
        {
            GymApplications[] application = await applicationRepository.getApplication(request.GymName, request.BranchName);

            if (request.status == "Approve")
            {
                //GymApplications[] application = await applicationRepository.getApplication(request.GymName, request.BranchName);
                application[0].Status = ApplicationStatus.Approved;
                Gym newgym = new Gym();
                newgym.GymName   = request.GymName.Trim();
                newgym.GymBranch = request.BranchName.Trim();
                bool creategym = await gymRepository.addGym(newgym);

                bool updateStatus = await applicationRepository.updateApplication(application[0]);

                /* Generate Code For Sign Up */
                string generated = getRandomString(10);

                GymApplicationCodes code = await codeRepository.getByCode(generated);

                while (code != null)
                {
                    generated = getRandomString(10);
                    code      = await codeRepository.getByCode(generated);
                }

                code = new GymApplicationCodes();

                code.BranchName = newgym.GymBranch;
                code.GymName    = newgym.GymName;
                code.Code       = generated;

                if (!await codeRepository.add(code))
                {
                    /* Remove gym from database and do not change application status */
                    return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to store generated code!"));
                }

                await mailer.sendEmail("*****@*****.**", "Gym Moves", "Gym Application Approval", $"Congratulations! Your gym approval has been approved! Use the following code {generated}\nAt https://gymmoveswebapi.azurewebsites.net/managerdetails", application[0].Email);
            }


            if (request.status == "Reject")
            {
                // GymApplications[] application = await applicationRepository.getApplication(request.GymName, request.BranchName);
                application[0].Status = ApplicationStatus.Rejected;
                bool updateStatus = await applicationRepository.updateApplication(application[0]);

                await mailer.sendEmail("*****@*****.**", "Gym Moves", "Gym Application Rejected", $"Unfortunately your gym application has been declined.", application[0].Email);
            }

            return(Ok(application));
        }