public async Task <ResponseDto> Create([FromBody] CreateRouteRequestDto request) { if (!ModelState.IsValid) { return(new ResultDto <RouteDto>(ResponseCode.Validate, "Đầu vào không hợp lệ", null)); } var routeId = await _routeService.CreateAsync(request); if (routeId == 0) { return(new ResultDto <RouteDto>(ResponseCode.LogicError, "Tạo không thành công", null)); } return(new ResponseDto(ResponseCode.Success, "Tạo mới thành công")); }
public async Task <int> CreateAsync(CreateRouteRequestDto request) { var route = new Route() { RouteCode = request.RouteCode, Name = request.Name, Distance = request.Distance, Desctiption = request.Description, Status = (Status)request.Status }; await _context.Routes.AddAsync(route); await _context.SaveChangesAsync(); return(route.Id); }