public string Post(JobListingModel newJobListing)
        {
            string success = "ERROR: ";

            try
            {
                JobListing dbJobListing = new JobListing();
                dbJobListing.Id                = Guid.NewGuid().ToString();
                dbJobListing.JobSearchId       = newJobListing.JobSearchId;
                dbJobListing.PostedDate        = DateTime.Parse(newJobListing.PostedDate);
                dbJobListing.JobTitle          = newJobListing.JobTitle;
                dbJobListing.AgentId           = newJobListing.AgentId;
                dbJobListing.TargetCompanyId   = newJobListing.TargetCompanyId;
                dbJobListing.Comments          = newJobListing.Comments;
                dbJobListing.Rate              = newJobListing.Rate;
                dbJobListing.Distance          = newJobListing.Distance;
                dbJobListing.JobLocation       = newJobListing.Location;
                dbJobListing.ListingStatusRef  = newJobListing.Status;
                dbJobListing.EmploymentTypeRef = newJobListing.EmploymentType;
                dbJobListing.ListingSourceRef  = newJobListing.ListingSource;
                dbJobListing.DesirabilityRef   = newJobListing.Desirability;
                dbJobListing.FitnessRef        = newJobListing.Fit;

                using (GetaJobContext db = new GetaJobContext())
                {
                    db.JobListings.Add(dbJobListing);
                    db.SaveChanges();
                    success = dbJobListing.Id.ToString();
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
        public List <JobListingModel> GetMany(string jobSearchId, string kludge)
        {
            var jobListingModels = new List <JobListingModel>();

            try
            {
                using (var db = new GetaJobContext())
                {
                    var dbJobListings = db.JobListings.Where(l => l.JobSearchId == jobSearchId).ToList();
                    foreach (JobListing dbListing in dbJobListings)
                    {
                        // just need items for list
                        JobListingModel jobListingModel = new JobListingModel();
                        jobListingModel.Id         = dbListing.Id;
                        jobListingModel.PostedDate = dbListing.PostedDate.ToShortDateString();
                        jobListingModel.Location   = dbListing.JobLocation;

                        var dbstatusRef = db.JobRefs.Where(r => r.RefCode == dbListing.ListingStatusRef).FirstOrDefault();
                        if (dbstatusRef != null)
                        {
                            jobListingModel.StatusText = dbstatusRef.RefDescription;
                        }

                        //dbJobListing.JobSearchId = newJobListing.JobSearchId;
                        //jobListingModel.JobTitle = listing.JobTitle;
                        //jobListingModel.AgentId = listing.AgentId;
                        //jobListingModel.TargetCompanyId = listing.TargetCompanyId;
                        //jobListingModel.Comments = listing.Comments;
                        //jobListingModel.Rate = listing.Rate;
                        //jobListingModel.Status = listing.ListingStatusRef;
                        //jobListingModel.EmploymentType = listing.EmploymentTypeRef;
                        //jobListingModel.Distance = listing.Distance;
                        //jobListingModel.ListingSource = listing.ListingSourceRef;
                        //jobListingModel.Desirability = listing.DesirabilityRef;
                        //jobListingModel.Fit = listing.FitnessRef;

                        jobListingModels.Add(jobListingModel);
                    }
                }
            }
            catch (Exception ex) { jobListingModels.Add(new JobListingModel()
                {
                    Id = Helpers.ErrorDetails(ex)
                }); }
            return(jobListingModels);
        }
        public JobListingModel GetOne(string jobListingId)
        {
            var jobListing = new JobListingModel();

            try
            {
                using (GetaJobContext db = new GetaJobContext())
                {
                    var dbJobListing = db.JobListings.Where(s => s.Id == jobListingId).FirstOrDefault();
                    if (dbJobListing != null)
                    {
                        jobListing.Id         = dbJobListing.Id;
                        jobListing.PostedDate = dbJobListing.PostedDate.ToShortDateString();
                        jobListing.JobTitle   = dbJobListing.JobTitle;
                        jobListing.AgentId    = dbJobListing.AgentId;
                        if (dbJobListing.AgentId != null)
                        {
                            jobListing.AgentId  = dbJobListing.AgentId;
                            jobListing.AgencyId = dbJobListing.Agent.AgencyId;
                        }

                        jobListing.TargetCompanyId = dbJobListing.TargetCompanyId;


                        jobListing.Comments       = dbJobListing.Comments;
                        jobListing.Status         = dbJobListing.ListingStatusRef;
                        jobListing.Rate           = dbJobListing.Rate;
                        jobListing.EmploymentType = dbJobListing.EmploymentTypeRef;
                        jobListing.Distance       = dbJobListing.Distance;
                        jobListing.ListingSource  = dbJobListing.ListingSourceRef;
                        jobListing.Desirability   = dbJobListing.DesirabilityRef;
                        jobListing.Fit            = dbJobListing.FitnessRef;
                        jobListing.Location       = dbJobListing.JobLocation;
                    }
                }
            }
            catch (Exception ex) { jobListing.Id = Helpers.ErrorDetails(ex); }
            return(jobListing);
        }
        public string Put(JobListingModel editJobListing)
        {
            string success = "";

            try
            {
                using (GetaJobContext db = new GetaJobContext())
                {
                    JobListing dbJobListing = db.JobListings.Where(j => j.Id == editJobListing.Id).FirstOrDefault();
                    if (dbJobListing != null)
                    {
                        dbJobListing.PostedDate        = DateTime.Parse(editJobListing.PostedDate);
                        dbJobListing.JobLocation       = editJobListing.Location;
                        dbJobListing.JobTitle          = editJobListing.JobTitle;
                        dbJobListing.AgentId           = editJobListing.AgentId;
                        dbJobListing.TargetCompanyId   = editJobListing.TargetCompanyId;
                        dbJobListing.Comments          = editJobListing.Comments;
                        dbJobListing.ListingStatusRef  = editJobListing.Status;
                        dbJobListing.Rate              = editJobListing.Rate;
                        dbJobListing.EmploymentTypeRef = editJobListing.EmploymentType;
                        dbJobListing.Distance          = editJobListing.Distance;
                        dbJobListing.ListingSourceRef  = editJobListing.ListingSource;
                        dbJobListing.DesirabilityRef   = editJobListing.Desirability;
                        dbJobListing.FitnessRef        = editJobListing.Fit;

                        db.SaveChanges();
                        success = "ok";
                    }
                    else
                    {
                        success = "Id: " + editJobListing.Id + "  not found";
                    }
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }