Example #1
0
        public async Task <ActionResult <GymApplications> > addApplication(GymApplicationsRequest application)
        {
            if (application.GymName == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Gym name cannot be empty!"));
            }

            if (application.BranchName == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Branch name cannot be empty!"));
            }

            if (application.Name == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Name cannot be empty!"));
            }

            if (application.Surname == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Surname cannot be empty!"));
            }

            if (application.Email == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Email cannot be empty!"));
            }

            if (application.PhoneNumber == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Phone number cannot be empty!"));
            }

            if (application.Address == "")
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Gym address cannot be empty!"));
            }


            Gym gym = await gymRepository.getGymByNameAndBranch(application.GymName, application.BranchName);

            if (gym != null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, $"Gym with name {application.GymName} and branch {application.BranchName} is already taken!"));
            }

            if ((await applicationRepository.getApplication(application.GymName, application.BranchName)).Length != 0)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "An application for this gym is already in progress!"));
            }

            GymApplications existingApplication = new GymApplications();

            existingApplication.Name        = application.Name;
            existingApplication.Surname     = application.Surname;
            existingApplication.Email       = application.Email;
            existingApplication.PhoneNumber = application.PhoneNumber;
            existingApplication.GymName     = application.GymName;
            existingApplication.BranchName  = application.BranchName;
            existingApplication.Address     = application.Address;
            existingApplication.Extra       = application.Extra;
            existingApplication.Status      = ApplicationStatus.Pending;

            if (await applicationRepository.addApplication(existingApplication))
            {
                return(Ok(existingApplication));
            }
            else
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "We were unable to add your application to the database!"));
            }
        }
Example #2
0
 public async Task <bool> updateApplication(GymApplications application)
 {
     context.Update(application);
     return((await context.SaveChangesAsync()) > 0);
 }
Example #3
0
 public async Task <bool> addApplication(GymApplications application)
 {
     context.Add(application);
     return((await context.SaveChangesAsync()) > 0);
 }
Example #4
0
 public async Task <bool> removeApplication(GymApplications application)
 {
     context.Remove(application);
     return((await context.SaveChangesAsync()) > 0);
 }
Example #5
0
        public async Task <ActionResult <UserResponseModel> > firstManager(FirstManagerModel user)
        {
            GymApplicationCodes code = await codeRepository.getByCode(user.Code);

            if (code == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound, "Invalid code!"));
            }

            Users existingUser = await userGymMovesRepository.getUser(user.Username);

            if (existingUser != null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "A user with that username already exists!"));
            }

            GymApplications[] applications = await applicationRepository.getApplication(code.GymName, code.BranchName);

            if (applications.Length == 0)
            {
                return(StatusCode(StatusCodes.Status404NotFound, "Application for gym not found!"));
            }

            GymApplications application = applications[0];
            Gym             gym         = await gymRepository.getGymByNameAndBranch(code.GymName, code.BranchName);

            existingUser = new Users();

            existingUser.GymIdForeignKey = gym.GymId;
            existingUser.Username        = user.Username;
            existingUser.MembershipId    = $"{code.GymName}{code.BranchName}defaultmanager";
            existingUser.Name            = application.Name;
            existingUser.Surname         = application.Surname;
            existingUser.PhoneNumber     = application.PhoneNumber;
            existingUser.Email           = application.Email;
            existingUser.UserType        = UserTypes.Manager;

            Random random = new Random();

            existingUser.Salt = getRandomString(random.Next(5, 10));
            string hash = getHash(SHA256.Create(), user.Password + existingUser.Salt);

            existingUser.Password = hash;

            if (await userGymMovesRepository.addUser(existingUser))
            {
                await applicationRepository.removeApplication(application);

                await codeRepository.remove(code);

                UserResponseModel response = new UserResponseModel();

                response.gymID       = existingUser.GymIdForeignKey;
                response.gymMemberID = existingUser.MembershipId;
                response.name        = existingUser.Name;
                response.userType    = existingUser.UserType;

                return(Ok(response));
            }
            else
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "An internal server error occured while adding the manager account!"));
            }
        }