// добавление нового обращения public async Task AppendPersonRequest(PersonRequestViewData personRequestViewData) { Person person = new Person { Surname = personRequestViewData.Surname, Name = personRequestViewData.Name, Patronymic = personRequestViewData.Patronymic, Passport = personRequestViewData.Passport }; // проверяем есть ли уже человек с таким паспортом но с другими ФИО. Если есть то мы будем кидать исключение if (_context.Persons.Any(p => p.Passport == person.Passport && (p.Surname != person.Surname || p.Patronymic != person.Patronymic || p.Name != person.Name))) { throw new WebApiException("Человек с таким паспортом уже существует. Проверьте корректность данных"); } // если у нас нет такого человека с такими данными, то мы добавляем его if (!_context.Persons.Any(p => p.Passport == person.Passport)) { await _personProcess.AppendPerson(person); } PersonRequest personRequest = new PersonRequest { PersonId = _context.Persons.First(p => p.Passport == person.Passport).Id, PersonRequestStatusId = _context.PersonRequestStatuses.First(prs => prs.Title == "Необходимо перезвонить!").Id, DescriptionOfTheProblem = personRequestViewData.DescriptionOfTheProblem, TelephoneNumber = personRequestViewData.Telephone }; _context.PersonRequests.Add(personRequest); await _context.SaveChangesAsync(); }
public async Task PostPersonRequest(PersonRequestViewData personRequestViewData) => await _personRequestProcess.AppendPersonRequest(personRequestViewData);