public async Task <Result <RoomExistResponse> > Handle(CheckRoomExistCommand request, CancellationToken cancellationToken) { using (_queueUnitOfWork) { try { var RoomExists = await _queueUnitOfWork.Repository <Rooms>().Get(x => x.RoomName.Trim().ToLower() == request.RoomName.Trim().ToLower()).ToListAsync(); if (RoomExists.Count > 0) { message += "The room already exists "; exist = true; } else { message += " The room does not exists"; exist = false; } return(Result <RoomExistResponse> .Valid(new RoomExistResponse() { Message = message, Rooms = RoomExists, Exists = exist })); } catch (Exception ex) { Log.Error(ex.Message); return(Result <RoomExistResponse> .Invalid(ex.Message)); } } }
public async Task <IActionResult> CheckRoomExists([FromBody] CheckRoomExistCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.Select(x => x.Errors))); } var response = await _mediator.Send(command, HttpContext.RequestAborted); if (!response.IsValid) { return(BadRequest(response)); } return(Ok(response.Value)); }