public HttpResponseMessage GetApplicationsByListingId(int id)
        {
            Result result = new Result();

            //Employer vertification
            object objemployer = null;

            Request.Properties.TryGetValue("employer", out objemployer);
            if (objemployer == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, new Result(false)));
            }
            var employer = objemployer as EmployerEntity;
            var listing  = (JobListingEntity)_jobListingManager.GetListingById(id).Entity;

            if (listing == null || listing.EmployerId != employer.EmployerId)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, new Result(false)));
            }
            result = _jobApplicationManager.GetJobApplicationByListingId(id);
            var applications = (List <JobApplicationEntity>)result.Entity;

            foreach (JobApplicationEntity application in applications)
            {
                var nurse        = (UserEntity)_usersManager.GetSecuredUserDetails(application.UserId).Entity;
                var quizzAnswers = (List <NurseSelfAssessmentAnswersEntity>)_nurseSelfAssessmentAnswersManager.GetAnswersbyUserQuizzId(nurse.defaultQuizId).Entity;
                application.PreferedQuizz = quizzAnswers;
            }

            result.Entity = applications;
            //If failed
            if (!result.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }
            //If if not found
            if (result.Entity == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, result));
            }

            //If it is good
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public HttpResponseMessage GetAllListingsOfCurrentNurse()
        {
            //Working, tested
            var    result  = new Result();
            object objuser = null;

            Request.Properties.TryGetValue("user", out objuser);
            var user = objuser as UserEntity;

            if (user == null)
            {
                result = new Result(false);
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, result));
            }

            var nurse = (UserEntity)_usersManager.GetUserDetails(user).Entity;

            if (nurse.defaultQuizId == 0)
            {
                result.Success = false;
                result.Message = "User must complete and nominate a Quizz to use as their profile";
                result.Entity  = null;
                return(Request.CreateResponse(HttpStatusCode.NotFound, result));
            }

            result = _nurseSelfAssessmentManager.GetAnswersbyUserQuizzId(nurse.defaultQuizId);
            var answersList = (List <NurseSelfAssessmentAnswersEntity>)result.Entity;

            result = _jobListingManager.GetAllListingsByNurseSelfAssessmentAnswer(answersList);

            if (!result.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }

            if (result.Entity == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, result));
            }

            var listings           = (List <int>)result.Entity;
            var listingEntityLists = new List <JobListingEntity>();

            foreach (int listingId in listings)
            {
                var lt_entity = (JobListingEntity)_jobListingManager.GetListingById(listingId).Entity;
                if (lt_entity.maxSalary >= nurse.salary)
                {
                    listingEntityLists.Add(lt_entity);
                }
            }

            result.Entity = listingEntityLists;

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }