public bool Create(School entity) { if (Validation(entity, false)) { _schoolRepository.Create(entity); return(true); } return(false); }
public ActionResult Post([FromBody] SchoolDto dto) { if (string.IsNullOrEmpty(dto.RequesterEmail) || Regex.IsMatch(dto.RequesterEmail, Regexes.Email)) { Problem("The requesterEmail is invalid"); } if (string.IsNullOrEmpty(dto.Url) || Regex.IsMatch(dto.Url, Regexes.Url)) { Problem("The url is invalid"); } var school = new School { Name = dto.Name, Url = dto.Url, KeeperEmail = dto.RequesterEmail }; school.GenerateId(); _repository.Create(school); return(Ok("Created!"));//TODO: Saturday }
public async Task creating_school_with_new_teacher_should_propagate_the_teacher_to_db() { var school = new School { Name = "VUT", Country = "CZE", SchoolOwnsSeason = null, Teacher = new List <Teacher> { new Teacher { Firstname = "Tomas", Lastname = "Sobek", } } }; var addedSchool = _sut.Create(school); await _sut.UnitOfWork.SaveEntitiesAsync(); var testSchool = await _context.Set <School>() .Include(x => x.Teacher) .FirstOrDefaultAsync(x => x.Id == addedSchool.Id); testSchool.ShouldNotBeNull(); testSchool.Country.ShouldBe(addedSchool.Country); testSchool.Name.ShouldBe(addedSchool.Name); testSchool.Id.ShouldBe(addedSchool.Id); testSchool.Teacher.ShouldBe(addedSchool.Teacher); var testTeacher = await _context.Set <Teacher>() .Include(x => x.School) .FirstOrDefaultAsync(x => x.Id == addedSchool.Teacher.First().Id); testTeacher.ShouldNotBeNull(); testTeacher.Firstname.ShouldBe(testSchool.Teacher.First().Firstname); testTeacher.Lastname.ShouldBe(testSchool.Teacher.First().Lastname); testTeacher.School.ShouldBe(testSchool); }
public ServiceResponse <int> CreateSchool(string schoolName) { var serviceResponse = new ServiceResponse <int>(); var school = new School() { Name = schoolName }; _schoolRepository.Create(school); serviceResponse.Data = school.SchoolId; return(serviceResponse.Success()); }
public async Task <SchoolResponse> AddSchoolAsync(AddSchoolRequest request) { if (request == null) { throw new ArgumentNullException($"Request is null"); } var pupil = _schoolMapper.Map(request); var result = _schoolRepository.Create(pupil); await _schoolRepository.UnitOfWork.SaveChangesAsync(); return(_schoolMapper.Map(result)); }
public async Task <bool> Create(School school) { //var school = _mapper.Map<School>(schoolDTO); var schoolIsValid = Validade(new SchoolValidation(), school); var addressIsValid = Validade(new AddressValidation(), school.Address); if (!schoolIsValid || !addressIsValid) { return(false); } await _schoolRepository.Create(school); return(true); }
public ICommandResult Handle(CreateSchoolCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Ops, parece que os dados da escola estão errados!", command.Notifications)); } var school = new School(command.Name, command.MaxSchoolClass, command.MaxSchoolStudents, command.SchoolPrincipal); // Salva no banco _repository.Create(school); // Retorna o resultado return(new GenericCommandResult(true, "Escola salva com sucesso!", school)); }
public ActionResult Create([Bind(Include = "LastName, FirstMidName, EnrollmentDate")] Student student) { try { if (ModelState.IsValid) { _repository.Create(student); return(RedirectToAction("Index")); } } catch (RetryLimitExceededException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(student)); }
public Task <bool> Handle(CreateSchoolCommand request, CancellationToken cancellationToken) { // TODO : Extract to base or validations if (request == null) { throw new InvalidCommandException(); } var School = new School { Name = request.Name, Description = request.Description }; schoolRepository.Create(School); return(Task.FromResult(true)); }
public bool Create(School school) { return(_schoolRepository.Create(school)); }
public int Create(SchoolVM schoolVM) { return(schoolRepository.Create(schoolVM)); }
public Task Create(School school) => _repository.Create(school);