Esempio 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();
            }
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        public Speciality Create(CreateSpecialityCommand command)
        {
            var speciality = new Speciality(command.Name, command.Description);

            speciality.Validate();
            _repository.Create(speciality);

            if (Commit())
            {
                return(speciality);
            }

            return(null);
        }
Esempio n. 4
0
        Speciality ISpecialtyService.Create(Speciality speciality)
        {
            _specialtyRepository.Create(speciality);

            return(_specialtyRepository.GetById(speciality.Id));
        }