Esempio n. 1
0
            public async Task <ResponseModel <string> > Handle(AuthenticateUserCommand request, CancellationToken cancellationToken)
            {
                var commandResult = _authService.Authenticate(request.User);

                if (commandResult == null)
                {
                    return(await Task.FromResult(ResponseModel <string> .Create(ResponseCode.InvalidUser)));
                }
                return(await Task.FromResult(ResponseModel <string> .Create(ResponseCode.Success, commandResult)));
            }
Esempio n. 2
0
            public async Task <ResponseModel <ProductViewDTO> > Handle(GetProductByIdQuery request, CancellationToken cancellationToken)
            {
                var queryResult = _mapper.Map <ProductViewDTO>(await _context.Products.AsNoTracking().FirstOrDefaultAsync(x => x.Id == request.Id));

                if (queryResult == null)
                {
                    ResponseModel <ProductViewDTO> .Create(ResponseCode.DoesNotExist, queryResult);
                }
                return(ResponseModel <ProductViewDTO> .Create(ResponseCode.Success, queryResult));
            }
Esempio n. 3
0
 async Task InvokeAsync(HttpContext context)
 {
     try
     {
         await _request(context);
     }
     catch (DbUpdateConcurrencyException concurencyException)
     {
         string message  = "The product availability you want to update has already been changed by another user.";
         var    response = ResponseModel <object> .Create(ResponseType.Error, null, message);
         await InvokeException(context, HttpStatusCode.OK, response);
     }
     catch (Exception exception)
     {
         var response = GenerateResponse(exception);
         await InvokeException(context, HttpStatusCode.InternalServerError, response);
     }
 }
        public ResponseModel <object> PostNewLocation([FromBody] NewLocationRequest newLocationRequest)
        {
            if (!ModelState.IsValid)
            {
                return(ResponseModel <object> .Create(null, ProcessStatusCodes.BadRequest, new FriendlyMessageModel()
                {
                    Title = "Bad Request", Description = "Please check your request"
                }));
            }


            int    xCoordinate = newLocationRequest.xCoordinate;
            int    yCoordinate = newLocationRequest.yCoordinate;
            string direction   = newLocationRequest.direction.ToString();

            newLocationRequest.moves.ForEach(x =>
            {
                if (x == MoveEnum.M)
                {
                    _locationService.MoveForward(ref xCoordinate, ref yCoordinate, ref direction);
                }
                else if (x == MoveEnum.R)
                {
                    direction = _locationService.MoveLeftOrRight(direction, MoveEnum.R.ToString());
                }
                else if (x == MoveEnum.L)
                {
                    direction = _locationService.MoveLeftOrRight(direction, MoveEnum.L.ToString());
                }
            });

            var newLocationResponse = new NewLocationResponse();

            newLocationResponse.direction   = direction;
            newLocationResponse.xCoordinate = xCoordinate;
            newLocationResponse.yCoordinate = yCoordinate;



            return(ResponseModel <object> .Create(newLocationResponse, ProcessStatusCodes.Success, new FriendlyMessageModel()
            {
                Title = "Success", Description = "New location calculated"
            }));
        }
        public async Task Invoke(HttpContext context, IProxyHttpClient client, ProxyRequest proxyRequest)
        {
            var request  = context.Request;
            var response = context.Response;

            var requestMessage = await proxyRequest.Create(request);

            if (request.Headers.ContainsKey(Headers.SHOW_PROXY_REQUEST))
            {
                response.StatusCode = 200;
                var requestModel = await RequestModel.Create(requestMessage);

                await response.WriteAsync(JsonConvert.SerializeObject(requestModel, Formatting.Indented));

                return;
            }

            var proxyResponse = await client.SendAsync(requestMessage);

            if (request.Headers.ContainsKey(Headers.SHOW_PROXY_RESPONSE))
            {
                response.StatusCode = 200;
                var requestModel = await RequestModel.Create(requestMessage);

                var responseModel = await ResponseModel.Create(proxyResponse);

                await response.WriteAsync(JsonConvert.SerializeObject(new
                {
                    Request  = requestModel,
                    Response = responseModel
                }, Formatting.Indented));

                return;
            }

            await response.Write(proxyResponse);
        }
Esempio n. 6
0
 private ResponseModel <object> GenerateResponse(Exception ex)
 {
     return(ResponseModel <object> .Create(ResponseType.Error, ex.StackTrace, ex.Message));
 }
Esempio n. 7
0
            public async Task <ResponseModel <List <ProductListItemDTO> > > Handle(GetProductsQuery request, CancellationToken cancellationToken)
            {
                var queryResult = await _mapper.ProjectTo <ProductListItemDTO>(_context.Products.AsNoTracking()).ToListAsync(cancellationToken);

                return(ResponseModel <List <ProductListItemDTO> > .Create(ResponseCode.Success, queryResult));
            }