public IActionResult Put(int id, [FromBody] TeethDto dto, [FromServices] UpdateTeethValidator validator) { dto.Id = id; var tooth = _context.Teeth.Find(id); if (tooth == 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, tooth); try { _context.SaveChanges(); return(NoContent()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public void Execute(TeethDto request) { _validator.ValidateAndThrow(request); var teeth = _context.Teeth.Find(request.Id); teeth.ToothNumber = request.ToothNumber; _context.SaveChanges(); }
public void Execute(TeethDto request) { _validator.ValidateAndThrow(request); var tooth = new Teeth { ToothNumber = request.ToothNumber }; _context.Teeth.Add(tooth); _context.SaveChanges(); }
public void Post([FromBody] TeethDto dto, [FromServices] ICreateToothCommand command, [FromServices] CreateTeethValidator validator) { _executor.ExecuteCommand(command, dto); }