예제 #1
0
        public object GetRequestData([FromQuery] TokenQueryModel tokenInfo, [FromQuery] RequestIdentityModel requestIdentity)
        {
            var userContext = tokenRepository.ValidateToken(userRepository, tokenInfo.Token);
            var request     = requestRepository.Select(requestIdentity.RequestId);

            return(RequestModel.Create(request));
        }
예제 #2
0
        public object FillRequest([FromQuery] TokenQueryModel tokenInfo, [FromQuery] RequestIdentityModel requestIdentity)
        {
            var userContext = tokenRepository.ValidateToken(userRepository, tokenInfo.Token);

            if (requestRepository.FillRequest(requestIdentity.RequestId))
            {
                return(RequestModel.Create(requestRepository.Select(requestIdentity.RequestId)));
            }

            throw new BasicControllerException("Failed to fill request", "failed to fill request");
        }
예제 #3
0
        public JsonResult Create(RequestModel model)
        {
            try
            {
                RequestModel requestRepo = new RequestModel();
                var          auth        = AuthorizationGateway.GetAuthorizedInfo();
                model.StatusID = RequestStatus.AWAITING;
                model.UserID   = auth.ID;
                var result = requestRepo.Create(model, auth);

                var context = GlobalHost.ConnectionManager.GetHubContext <PushNotificationHub>();

                context.Clients.Group("Providers").sendRequestToProviders(result);

                return(Json(new { Result = "OK", Record = result }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #4
0
        public object CreateRequest([FromQuery] TokenQueryModel tokenInfo, [FromQuery] GroupIdentityModel groupIdentity, [FromQuery] RequestQueryModel requestInfo)
        {
            var userContext = tokenRepository.ValidateToken(userRepository, tokenInfo.Token);

            if (!groupRepository.IsMember(userContext.user.Uuid, groupIdentity.GroupId))
            {
                throw new AuthorizationException($"User {userContext.user.Uuid} isn't group member", "not a group member");
            }

            if (requestInfo.Type == 0 || !Enum.IsDefined(typeof(RequestType), requestInfo.Type))
            {
                throw new BasicControllerException("Request type not defined.", "invalid request type", statusCode: System.Net.HttpStatusCode.UnprocessableEntity);
            }

            var type    = (RequestType)requestInfo.Type;
            var request = default(Request);

            switch (type)
            {
            case RequestType.Lives:
                request = new Request()
                {
                    Type   = (byte)RequestType.Lives,
                    Amount = 5,
                    Filled = 0,
                    Sender = userContext.user.Uuid
                };
                break;

            default:
                throw new BasicControllerException($"Handler for {type} reuqest type not implemented.", "server error", statusCode: System.Net.HttpStatusCode.InternalServerError);
            }

            requestRepository.Insert(request);
            messageRepository.Send(userContext.user.Uuid, groupIdentity.GroupId, String.Empty, (byte)AttachmentType.Request, request.Id);
            chatManager.NotifyNewMessageAsync(groupIdentity.GroupId);

            return(RequestModel.Create(request));
        }
        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);
        }