public void Execute(MechanismDto request)
 {
     request.Id = 0;
     _validator.ValidateAndThrow(request);
     _context.Mechanisms.Add(_mapper.Map <Mechanism>(request));
     _context.SaveChanges();
 }
예제 #2
0
        public void Execute(MechanismDto request)
        {
            _validator.ValidateAndThrow(request);
            var mechanism = _context.Mechanisms.Find(request.Id);

            if (mechanism == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Mechanism));
            }

            _mapper.Map(request, mechanism);
            _context.SaveChanges();
        }
 public IActionResult Put(int id, [FromBody] MechanismDto dto, [FromServices] IUpdateMechanismCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status204NoContent));
 }
 public IActionResult Post([FromBody] MechanismDto dto, [FromServices] IAddMechanismCommand command)
 {
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status201Created));
 }