public async Task <CourseDto> Handle(Query request, CancellationToken cancellationToken)
            {
                // handler logic goes here
                var item = await services.GetByIdAsync(request.Id);

                if (item == null)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { message = "Không tìm thấy khóa học" });
                }
                return(item);
            }
예제 #2
0
        public async Task <IHttpActionResult> GetByIdAsync(string id)
        {
            //validate id
            if (string.IsNullOrEmpty(id) || !Guid.TryParse(id, out var _))
            {
                return(BadRequest());
            }

            try
            {
                var result = await _courseService.GetByIdAsync(id);

                return(result == null?NotFound() : (IHttpActionResult)Ok(result));
            }
            catch (InvalidOperationException ex)
            {
                return(InternalServerError(ex));
            }
        }