public IActionResult Put(int id, [FromBody] ServiceTypeDto dto, [FromServices] UpdateServiceTypeValidator validator)
        {
            dto.Id = id;

            var service = _context.ServiceTypes.Find(id);

            if (service == 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, service);

            try
            {
                _context.SaveChanges();
                return(NoContent());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
예제 #2
0
 public EfUpdateServiceTypeCommand(DentaCareContext context, UpdateServiceTypeValidator validator)
 {
     this._context   = context;
     this._validator = validator;
 }