public ActionResult Create(CreateOfferViewModel createModel) { if (!ModelState.IsValid) { return(PartialView(createModel)); } string userId = User.Identity.GetUserId(); CreateOfferParams createOfferParams = new CreateOfferParams() { EmployeeId = userId, JobId = createModel.JobId, Text = createModel.Text, ImplementationDays = createModel.DaysToImplement, OfferPayment = createModel.OfferPayment }; _offerService.CreateOffer(createOfferParams); _commitProvider.SaveChanges(); return(Redirect(Request.UrlReferrer.PathAndQuery)); }
public void CreateOffer(CreateOfferParams offerParams) { var employee = _employeeRepository.FindEmployeeById(offerParams.EmployeeId); if (employee == null) { throw new ObjectNotFoundException($"Employee profile with id={offerParams.EmployeeId} not found"); } var job = _jobRepository.FindJobById(offerParams.JobId); if (job == null) { throw new ObjectNotFoundException($"Job with id={offerParams.JobId} not found"); } if (offerParams.EmployeeId == job.CustomerId) { throw new ArgumentException("You cannot create offer on youe job"); } var offerForJob = _offerRepository.FindOffer(offerParams.JobId, offerParams.EmployeeId); if (offerForJob != null) { throw new ArgumentException($"At user with id={employee.Id} already have offer to job with id={job.Id}"); } var offer = new Offer() { Job = job, Employee = employee, Text = offerParams.Text, AddedDate = DateTime.UtcNow, OfferPayment = offerParams.OfferPayment, ImplementationDays = offerParams.ImplementationDays }; _offerRepository.Create(offer); }