Ejemplo n.º 1
0
        public async Task <Specialty> Create(Specialty speciality)
        {
            List <Task> tasks = new List <Task>();

            var facultyIdExists = _facultyRepository.GetById(speciality.FacultyId);

            tasks.Add(facultyIdExists);
            var uniqueId = _specialtyRepository.GetById(speciality.Id);

            tasks.Add(uniqueId);
            var uniqueName = _specialtyRepository.GetByName(speciality.Name);

            tasks.Add(uniqueName);

            await Task.WhenAll(tasks);

            var lectorIdExists = _lectorRepository.GetById(speciality.LectorId) != null;

            if (facultyIdExists.Result != null && lectorIdExists && uniqueId.Result == null && uniqueName.Result == null)
            {
                return(await _specialtyRepository.Create(speciality));
            }
            else
            {
                throw new Exception();
            }
        }