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(); } }
public ActionResult Create(Speciality speciality) { if (ModelState.IsValid) { repository.Create(speciality); TempData["message"] = "Специальность успешно добавлена"; return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", speciality.DepartmentId); return(View(speciality)); }
public Speciality Create(CreateSpecialityCommand command) { var speciality = new Speciality(command.Name, command.Description); speciality.Validate(); _repository.Create(speciality); if (Commit()) { return(speciality); } return(null); }
Speciality ISpecialtyService.Create(Speciality speciality) { _specialtyRepository.Create(speciality); return(_specialtyRepository.GetById(speciality.Id)); }