public HttpResponseMessage PostListing(JobListingEntity jobListing)
        {
            //Woking , tested

            var 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 employerentity_full = (EmployerEntity)_employersManager.GetEmployerById(employer.EmployerId).Entity;

            if (employerentity_full.MembershipEndDate == DateTime.MinValue || employerentity_full.MembershipEndDate < (DateTime?)DateTime.Now)
            {
                // membership expired
                result         = new Result();
                result.Success = false;
                result.Message = "Membership expired";

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


            jobListing.CreateDate       = DateTime.Now;
            jobListing.EmployerId       = employer.EmployerId;
            jobListing.ModificationDate = jobListing.CreateDate;
            result = _jobListingManager.CreateJobListingById(jobListing, employer.EmployerId);

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


            // if success
            if (jobListing.JobListingCriteria != null || jobListing.JobListingCriteria.Count > 0)
            {
                var cri_res = _jobListingCriteriaManager.InsertCriteria(jobListing.JobListingCriteria);
            }

            //Result cri_result = null;
            var listingID = (int)result.Entity;
            var listing   = (JobListingEntity)_jobListingManager.GetListingById(listingID).Entity;

            result.Entity = listing;
            return(Request.CreateResponse(HttpStatusCode.Created, result));
        }
        public HttpResponseMessage Post([FromBody] JobApplicationEntity jobApplication)
        {
            Result result = new Result();

            // Authentication verify block
            object objuser = null;

            Request.Properties.TryGetValue("user", out objuser);
            if (objuser == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, result));
            }
            var user = objuser as UserEntity;

            // check if listing is valid
            var jobListingEntity_Result = _jobListingManager.GetListingById(jobApplication.JobListingId);

            if (!jobListingEntity_Result.Success || jobListingEntity_Result.Entity == null)
            {
                result.Entity  = null;
                result.Message = "Job Listing not exists";
                result.Success = false;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }
            var jobListingEntity = (JobListingEntity)jobListingEntity_Result.Entity;

            // check if listing expired
            if (DateTime.Compare(jobListingEntity.ApplicationDeadline, DateTime.Now) < 0)
            {
                result.Entity  = null;
                result.Message = "Job Listing expired";
                result.Success = false;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }

            if (jobApplication.IsDraft)
            {
                jobApplication.ApplicationStatus = ApplicationStatus.Draft.ToString();
            }
            else
            {
                jobApplication.ApplicationStatus = ApplicationStatus.Submitted.ToString();
            }

            jobApplication.EmployerId       = jobListingEntity.EmployerId;
            jobApplication.UserId           = user.UserId;
            jobApplication.AppliedDate      = DateTime.Now;
            jobApplication.LastModifiedDate = jobApplication.AppliedDate;
            jobApplication.IsShortlisted    = false;
            jobApplication.IsDeclined       = false;
            result = _jobApplicationManager.CreateJobApplication(jobApplication);



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

            // if success
            var response = new ApplicationWithInfo();

            response.jobApplicationEntity = (JobApplicationEntity)result.Entity;


            result.Entity = response;
            return(Request.CreateResponse(HttpStatusCode.Created, result));
        }