public JobEditWindow(JobDTO job)
 {
     JEViewModel = new JobEditViewModel {OriginalJob = job};
     InitializeComponent();
     this.DataContext = JEViewModel.EditedJob;
 }
 public JobDTO(JobDTO job)
 {
     JobId = job.JobId;
     JobTitle = job.JobTitle;
 }
 public ListResponse<JobDTO> GetAllJobs()
 {
     using (var context = new AF_Context())
     {
         try
         {
             List<JobDTO> tmp = new List<JobDTO>();
             foreach (Job jo in from j in context.Jobs select j)
             {
                 var newJobDto = new JobDTO()
                 {
                     JobId = jo.JobId,
                     JobTitle = jo.JobTitle
                 };
                 tmp.Add(newJobDto);
             }
             return (new ListResponse<JobDTO>(tmp));
         }
         catch (Exception ex)
         {
             throw;
         }
         return null;
     }
 }
        public SingleItemResponse<JobDTO> GetJob(int id)
        {
            using (var context = new AF_Context())
            {
                try
                {
                    Job jo = context.Jobs.First(j => j.JobId == id);

                    var newJobDto = new JobDTO()
                    {
                        JobId = jo.JobId,
                        JobTitle = jo.JobTitle
                    };
                    return (new SingleItemResponse<JobDTO>(newJobDto));
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
        public SingleItemResponse<JobDTO> UpdateJob(JobDTO updateData)
        {
            var updateDataFull = new Job()
            {
                JobId = updateData.JobId,
                JobTitle = updateData.JobTitle,
                EditedBy = GetUserId(),
                EditDate = DateTime.Now
            };

            using (var context = new AF_Context())
            {
                try
                {
                    Job jo = context.Jobs.First(j => j.JobId == updateData.JobId);
                    context.Entry(jo).CurrentValues.SetValues(updateDataFull);
                    context.SaveChanges();
                    int id = updateData.JobId;
                    return GetJob(id);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
        public SingleItemResponse<JobDTO> AddJob(JobDTO newJob)
        {
            var newJobFull = new Job()
            {
                JobTitle = newJob.JobTitle,
                EditedBy = GetUserId(),
                EditDate = DateTime.Now
            };

            using (var context = new AF_Context())
            {
                try
                {
                    context.Jobs.Add(newJobFull);
                    context.SaveChanges();
                    int id = newJobFull.JobId;
                    return GetJob(id);
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
 public JobDTO(JobDTO job)
 {
     JobId    = job.JobId;
     JobTitle = job.JobTitle;
 }