public async Task<IHttpActionResult> PostUserJob(AddUserJobBindingModel job)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var userId = this.User.Identity.GetUserId();
            if (userId == null)
            {
                return this.BadRequest("Invalid session token.");
            }

            Guid jobId = await getJobId(job);

            this.Data.UserJobs.Add(new UserJob()
            {
                JobId = jobId,
                UserId = userId,
                Description = job.Description,
                StartDate = job.StartDate,
                EndDate = job.EndDate
            });

            await this.Data.SaveChangesAsync();
            return this.StatusCode(HttpStatusCode.Created);
        }
        private async Task<Guid> getJobId(AddUserJobBindingModel job)
        {
            var existJob = await this.Data.Jobs.All().FirstOrDefaultAsync(j => j.Name == job.Name && j.Company.Name == job.CompanyName);
            Guid newJobId;
            if (existJob == null)
            {
                var existCompany = await this.Data.Companies.All().FirstOrDefaultAsync(c => c.Name == job.CompanyName);
                Guid newCompanyId;
                if (existCompany == null)
                {
                    var newCompany = new Company()
                    {
                        Name = job.CompanyName,
                        CreatedOn = DateTime.Now
                    };

                    this.Data.Companies.Add(newCompany);
                    await this.Data.SaveChangesAsync();
                    newCompanyId = newCompany.Id;
                }
                else
                {
                    newCompanyId = existCompany.Id;
                }

                var newJob = new Job()
                {
                    Name = job.Name,
                    CompanyId = newCompanyId
                };

                this.Data.Jobs.Add(newJob);
                await this.Data.SaveChangesAsync();
                newJobId = newJob.Id;
            }
            else
            {
                newJobId = existJob.Id;
            }
            return newJobId;
        }
        public async Task<IHttpActionResult> PutUserJob(string id, AddUserJobBindingModel job)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var userId = this.User.Identity.GetUserId();
            if (userId == null)
            {
                return this.BadRequest("Invalid session token.");
            }

            var userJob = await this.Data.UserJobs.All().FirstOrDefaultAsync(uj => uj.Id == new Guid(id) && uj.UserId == userId);
            if (userJob == null)
            {
                return NotFound();
            }

            Guid newJobId = await getJobId(job);

            var oldJobId = userJob.JobId;

            userJob.JobId = newJobId;
            userJob.StartDate = job.StartDate;
            userJob.EndDate = job.EndDate;
            userJob.Description = job.Description;
            await this.Data.SaveChangesAsync();

            await removeUnusedJobAndCompany(oldJobId);

            return this.StatusCode(HttpStatusCode.NoContent);
        }