public void CreateJob(CreateJobParams jobParams) { var customerProfile = _customerRepository.FindCustomerProfileById(jobParams.CustomerId); if (customerProfile == null) { throw new ObjectNotFoundException($"Customer profile with id={jobParams.CustomerId} not found"); } var job = new Job() { Customer = customerProfile, Title = jobParams.Title, Description = jobParams.Description, Price = jobParams.Price, PriceDiscussed = jobParams.PriceDiscussed, DateAdded = DateTime.UtcNow }; foreach (var skillId in jobParams.SkillsId) { Skill skill = _skillRepository.FindById(skillId); if (skill == null) { throw new ObjectNotFoundException($"Skill with id={skillId} not found"); } job.Skills.Add(skill); } _jobRepository.Create(job); }
public ActionResult Create(CreateJobViewModel jobModel) { if (!ModelState.IsValid) { ViewBag.Skills = GetCategories(); return(View(jobModel)); } CreateJobParams jobParams = new CreateJobParams() { CustomerId = User.Identity.GetUserId(), SkillsId = jobModel.SelectedSkills, Title = jobModel.Title, Description = jobModel.Description, Price = jobModel.Price, PriceDiscussed = jobModel.PriceDiscussed }; _jobService.CreateJob(jobParams); _commitProvider.SaveChanges(); return(RedirectToAction("Jobs", "Job")); }