public bool AddFireTruckToAction(AssignFireTruckToActionRequestDto dto) { var action = _context.Actions.FirstOrDefault(a => a.IdAction.Equals(dto.IdAction)); if (action == null) { throw new ResourceNotFoundException("Not found"); } var fireTruck = _context.FireTrucks.FirstOrDefault(ft => ft.IdFireTruck.Equals(dto.IdFireTruck)); if (fireTruck == null) { throw new ResourceNotFoundException("Not found"); } if (!action.NeedSpecialEquipment.Equals(fireTruck.SpecialEquipment)) { throw new ResourceNotFoundException("Track doesnt have required equipment"); } var fireTruckAction = new FireTruckAction { Action = action, FireTruck = fireTruck }; _context.Add(fireTruckAction); _context.SaveChanges(); return(true); }
public IActionResult AddFireTruckToAction(AssignFireTruckToActionRequestDto dto) { try { return(Ok(_service.AddFireTruckToAction(dto))); } catch (ResourceNotFoundException e) { return(NotFound(e)); } }