public IActionResult Put(int id, [FromBody] DentistDto dto, [FromServices] UpdateDentistValidator validator) { dto.Id = id; var dentist = _context.Dentists.Find(id); if (dentist == null) { return(NotFound()); } var result = validator.Validate(dto); if (!result.IsValid) { throw new Exception();// prepraviti sa klasom error/ medelja 5-subota termin } _mapper.Map(dto, dentist); try { _context.SaveChanges(); return(NoContent()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <int> AddAsync(DentistDto dentistDto) { var dentist = _mapper.Map <Dentist>(dentistDto); _dentalClinicContext.Add(dentist); return(await _dentalClinicContext.SaveChangesAsync()); }
public void Execute(DentistDto request) { _validator.ValidateAndThrow(request); var dentist = _context.Dentists.Find(request.Id); dentist.FirstName = request.FirstName; dentist.LastName = request.LastName; _context.SaveChanges(); }
public void Execute(DentistDto request) { _validator.ValidateAndThrow(request); var dentist = new Dentist { FirstName = request.FirstName, LastName = request.LastName }; _context.Dentists.Add(dentist); _context.SaveChanges(); }
public async Task <ActionResult <int> > Post([FromBody] DentistDto dentist) { int recordId; try { recordId = await _dentistRepository.AddAsync(dentist); } catch (ArgumentException) { return(BadRequest()); } return(recordId); }
public async Task <int> UpdateAsync(DentistDto dentistDto) { var dentist = await _dentalClinicContext.Dentists .FirstOrDefaultAsync(p => p.Id == dentistDto.Id); if (dentist == null) { throw new KeyNotFoundException("Patient with given id doesn't exist"); } _mapper.Map(dentistDto, dentist); _dentalClinicContext.Update(dentist); return(_dentalClinicContext.SaveChanges()); }
public async Task <ActionResult> Put([FromBody] DentistDto dentist) { try { await _dentistRepository.UpdateAsync(dentist); } catch (KeyNotFoundException) { return(NotFound()); } catch (ArgumentException) { return(BadRequest()); } return(Ok()); }
public void Post([FromBody] DentistDto dto, [FromServices] ICreateDentistCommand command, [FromServices] CreateDentistValidator validator) { _executor.ExecuteCommand(command, dto); }