public async Task <IResponse> NewVehicleReservation(NewVehicleReservation newVehicleReservation) { var vehicle = await _vehicleRepository.GetAsync(newVehicleReservation.VehicleId); if (vehicle == null) { return(ResponseType.NotFound()); } vehicle.BookingName = newVehicleReservation.BookingName; var vehicleBookingDate = DateTime.UtcNow; vehicle.BookingDate = vehicleBookingDate; vehicle.UpdatedOn = vehicleBookingDate; await _unitOfWork.CommitAsync(); return(ResponseType.Success); }
private bool TryHandleException(ExceptionContext context) { switch (context.Exception) { case NotFoundException _: context.ExceptionHandled = true; context.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; context.Result = new ObjectResult(new StandardResponse(ResponseType.NotFound())); return(true); case UnauthorizedException _: context.ExceptionHandled = true; context.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; context.Result = new ObjectResult(new StandardResponse(ResponseType.Unauthorised())); return(true); case ValidationException exception: context.ExceptionHandled = true; context.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; context.Result = new ObjectResult(new StandardResponse(ResponseStatus.Invalid, exception.Message, exception.Errors)); return(true); } return(false); }