Пример #1
0
        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);
        }