示例#1
0
        public async Task <GetHotelLinenByIdResponse> Handle(GetHotelLinenByIdRequest request, CancellationToken cancellationToken)
        {
            if (request.AuthenticationRole == "UserLaundry")
            {
                return(new GetHotelLinenByIdResponse
                {
                    Error = new ErrorModel(ErrorType.Forbidden)
                });
            }

            var query = new GetHotelLinenQuery()
            {
                Id = request.Id
            };
            var hotelLinen = await this.queryExecutor.Execute(query);

            //if (hotelLinen == null)
            //{
            //    return new GetHotelLinenByIdResponse
            //    {
            //        Error = new ErrorModel(ErrorType.NotFound)
            //    };
            //}

            var mappedHotelLinen = this.mapper.Map <HotelLinen>(hotelLinen);
            var response         = new GetHotelLinenByIdResponse()
            {
                Data = mappedHotelLinen
            };

            return(response);
        }
示例#2
0
        public async Task <PatchHotelLinenByIdResponse> Handle(PatchHotelLinenByIdRequest request, CancellationToken cancellationToken)
        {
            if (request.AuthenticationRole == "UserLaundry")
            {
                return(new PatchHotelLinenByIdResponse
                {
                    Error = new ErrorModel(ErrorType.Forbidden)
                });
            }
            var query = new GetHotelLinenQuery()
            {
                Id = request.Id
            };
            var getHotelLinen = await this.queryExecutor.Execute(query);

            if (getHotelLinen == null)
            {
                return(new PatchHotelLinenByIdResponse
                {
                    Error = new ErrorModel(ErrorType.NotFound)
                });
            }
            var hotelLinenModel = this.mapper.Map <API.Domain.Models.HotelLinen>(getHotelLinen);

            request.LinenUpdate.ApplyTo(hotelLinenModel);

            var hotelLinenEntity = this.mapper.Map <DataAccess.Entities.HotelLinen>(hotelLinenModel);

            var command = new UpdateHotelLinenByIdCommand()
            {
                Parameter = hotelLinenEntity
            };

            var updatedHotelLinen = await this.commandExecutor.Execute(command);

            var resopnse = new PatchHotelLinenByIdResponse()
            {
                Data = this.mapper.Map <API.Domain.Models.HotelLinen>(updatedHotelLinen)
            };

            return(resopnse);
        }
示例#3
0
        public async Task <DeleteHotelLinenByIdResponse> Handle(DeleteHotelLinenByIdRequest request, CancellationToken cancellationToken)
        {
            if (request.AuthenticationRole == "UserLaundry")
            {
                return(new DeleteHotelLinenByIdResponse
                {
                    Error = new ErrorModel(ErrorType.Forbidden)
                });
            }

            var query = new GetHotelLinenQuery()
            {
                Id = request.Id
            };
            var getHotelLinen = await this.queryExecutor.Execute(query);

            if (getHotelLinen == null)
            {
                return(new DeleteHotelLinenByIdResponse
                {
                    Error = new ErrorModel(ErrorType.NotFound)
                });
            }
            var mappedCommand = this.mapper.Map <HotelLinen>(request);
            var command       = new DeleteHotelLinenByIdCommand()
            {
                Parameter = mappedCommand
            };
            var deletedHotelLinen = await this.commandExecutor.Execute(command);

            var response = new DeleteHotelLinenByIdResponse()
            {
                Data = deletedHotelLinen
            };

            return(response);
        }