public FuneralModel Create(FuneralModel model) { var employeeIds = model.Employees.Select(x => x.ID); var employees = _employeeRepository.GetByIds(employeeIds); var funerals = employees .SelectMany(x => x.FuneralEmployees.Select(y => y.Funeral)) .Where(x => model.DateUtc.Date == x.DateUtc.Date) .ToList(); foreach (var employee in employees) { if (employee.FuneralEmployees.Select(x => x.Funeral).Any(x => x.DateUtc.Date == model.DateUtc.Date)) { throw new System.Exception($"Employee {employee.FirstName} {employee.LastName} is busy at this date"); } } var funeral = _mapper.Map <Funeral>(model); var newFuneral = _funeralRepository.Create(funeral); return(_mapper.Map <FuneralModel>(newFuneral)); }
public void Create(FuneralModel model) { var funeral = _mapper.Map <Funeral>(model); _funeralRepository.Create(funeral); }