public async Task <GetAllHotelLinenResponse> Handle(GetAllHotelLinenRequest request, CancellationToken cancellationToken) { if (request.AuthenticationRole == "UserLaundry") { return(new GetAllHotelLinenResponse() { Error = new ErrorModel(ErrorType.Forbidden) }); } var query = new GetHotelLinensQuery() { Description = request.Description, CompanyId = request.AuthenticationCompanyId, WarehauseId = request.WarehauseId }; var getHotelLinen = await this.queryExecutor.Execute(query); if (getHotelLinen == null) { return(new GetAllHotelLinenResponse { Error = new ErrorModel(ErrorType.NotFound) }); } var mappedHotelLinen = this.mapper.Map <List <HotelLinen> >(getHotelLinen); var response = new GetAllHotelLinenResponse() { Data = mappedHotelLinen }; return(response); }
public async Task <CreateHotelLinenResponse> Handle(CreateHotelLinenRequest request, CancellationToken cancellationToken) { if (request.AuthenticationRole == "UserLaundry") { return(new CreateHotelLinenResponse { Error = new ErrorModel(ErrorType.Forbidden) }); } var query = new GetHotelLinensQuery() { Color = request.Color, Size = request.Size, Description = request.Description, Weight = request.Weight, LinenType = request.TypeName }; var getLinen = await this.queryExecutor.Execute(query); if (getLinen != null) { return(new CreateHotelLinenResponse() { Error = new ErrorModel(ErrorType.Conflict + " Bielizna o podanym typie oraz nazwie już istnieje!") }); } var mappedCommand = this.mapper.Map <HotelLinen>(request); var command = new CreateHoteLinenCommand() { Parameter = mappedCommand }; var createdHotelLinen = await this.commandExecutor.Execute(command); var response = new CreateHotelLinenResponse() { Data = this.mapper.Map <API.Domain.Models.HotelLinen>(createdHotelLinen) }; return(response); }