Exemplo n.º 1
0
        public ICollection <EditJobDTO> GetFullJobsList(string userId)
        {
            var jobs   = new List <EditJobDTO>();
            var jobIds = this.db.UserJobs.Where(y => y.UserId == userId).Select(x => x.JobId);

            foreach (var id in jobIds)
            {
                var job    = this.db.Jobs.Find(id);
                var jobDTO = new EditJobDTO
                {
                    Id             = job.Id,
                    Position       = job.Position,
                    PublishedOn    = job.PublishedOn.ToString("dd.MM.yyyy"),
                    Employer       = job.Employer,
                    Location       = job.Location.Name,
                    Description    = job.Description,
                    Salary         = job.Salary,
                    Industry       = job.SubIndustry.Industry.Name,
                    SubIndustry    = job.SubIndustry.Name,
                    EmploymentType = job.EmploymentType.Name,
                    SeniorityLevel = job.SeniorityLevel.Name,
                    UserIds        = job.UserJobs.Select(x => x.UserId).ToList(),
                    Applied        = job.UserJobs.FirstOrDefault(x => x.JobId == job.Id && x.UserId == userId).Applied,
                    Saved          = job.UserJobs.FirstOrDefault(x => x.JobId == job.Id && x.UserId == userId).Saved,
                };
                jobs.Add(jobDTO);
            }
            return(jobs);
        }
Exemplo n.º 2
0
        public async Task UpdateJobAsync(Guid id, EditJobDTO model)
        {
            var job = this.db.Jobs.Find(id);

            job.Position         = model.Position;
            job.Employer         = model.Employer;
            job.LocationId       = Guid.TryParse(model.Location, out _) ? Guid.Parse(model.Location) : job.LocationId;
            job.Description      = model.Description;
            job.Salary           = model.Salary;
            job.SubIndustryId    = Guid.Parse(model.SubIndustry);
            job.EmploymentTypeId = Guid.TryParse(model.EmploymentType, out _) ? Guid.Parse(model.EmploymentType) : job.EmploymentTypeId;
            job.SeniorityLevelId = Guid.TryParse(model.SeniorityLevel, out _) ? Guid.Parse(model.SeniorityLevel) : job.SeniorityLevelId;


            //var keys = model.Keywords;

            //if (keys != null)
            //{
            //    foreach (var key in keys)
            //    {
            //        JobKeyword jk = new JobKeyword();
            //        if (!this.db.Keywords.Any(k => k.Name == key.ToLower()))
            //        {
            //            {
            //                jk.Keyword = new Keyword()
            //                {
            //                    Name = key.ToLower(),
            //                    JobKeywords = job.JobKeywords
            //                };

            //                //jk.KeywordId = jk.Keyword.Id;

            //            };

            //        }
            //        else
            //        {
            //            jk.KeywordId = this.db.Keywords.FirstOrDefault(k => k.Name == key.ToLower()).Id;
            //        }

            //        jk.JobId = job.Id;
            //        //jk.Job = job;
            //        job.JobKeywords.Add(jk);
            //    }
            //}

            //this.db.Jobs.Update(job);
            await this.db.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public EditJobDTO GetJobInfo(Guid id, string userId)
        {
            var job = this.db.Jobs.FirstOrDefault(j => j.Id == id);
            //var i = this.db.Industries.Find(job.IndustryId);
            //var l = this.db.Locations.Find(job.LocationId);
            var jobInfo = new EditJobDTO()
            {
                Id             = job.Id,
                Position       = job.Position,
                Employer       = job.Employer,
                Location       = job.Location.Name,
                Description    = job.Description,
                Salary         = job.Salary,
                SubIndustry    = job.SubIndustry.Name,
                EmploymentType = job.EmploymentType.Name,
                SeniorityLevel = job.SeniorityLevel.Name,
                Applied        = job.UserJobs.FirstOrDefault(x => x.JobId == job.Id && x.UserId == userId)?.Applied ?? false,
                Saved          = job.UserJobs.FirstOrDefault(x => x.JobId == job.Id && x.UserId == userId)?.Saved ?? false,
            };

            jobInfo.LocationId = job.LocationId;
            foreach (var item in job.JobKeywords)
            {
                jobInfo.Keywords.Add(item.Keyword.Name);
            }

            //if (job.UserJobs != null)
            //{
            //    jobInfo.UserJobs = job.UserJobs.Where(x => x.JobId == job.Id).Select(x => new UserJobsDTO
            //    {
            //        JobId = job.Id,
            //        Applied = job.UserJobs.
            //    }).ToList();
            //}

            return(jobInfo);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Edit(Guid id, JobFullInfoViewModel model)
        {
            if (id != model.Job.Id)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                var job = new EditJobDTO
                {
                    Position    = model.Job.Position,
                    Employer    = model.Job.Employer,
                    Location    = model.Job.Location,
                    Description = model.Job.Description,
                    Salary      = model.Job.Salary,
                    SubIndustry = model.Job.SubIndustry,
                    //Keywords= model.Job.Keywords?.Split(',').ToList(),
                    EmploymentType = model.Job.EmploymentType,
                    SeniorityLevel = model.Job.SeniorityLevel
                };

                try
                {
                    await this.jobsService.UpdateJobAsync(id, job);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }

                return(RedirectToAction(nameof(JobsList)));
            }

            return(View());
        }