Ejemplo n.º 1
0
        public async Task <IActionResult> GetSorting([FromBody] PostRequestBody postRequestBody)
        {
            try
            {
                var sortOrder     = postRequestBody.SortOrder != null && postRequestBody.SortOrder == "ASC" ? SortOrder.Ascending : SortOrder.Descending;
                var queryResponse = await _elasticClient.SearchAsync <object>(x => x.Index(IndexName)
                                                                              .Sort(ss => ss.Field(postRequestBody.SortField, sortOrder)));

                if (queryResponse.IsValid)
                {
                    var responseObject = new Entities.SearchResponse
                    {
                        RecordCount = queryResponse.HitsMetadata.Total.Value,
                        Records     = queryResponse.Documents
                    };
                    return(Ok(JsonConvert.SerializeObject(responseObject)));
                }
                else
                {
                    return(BadRequest(queryResponse.ServerError.Error));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetPagination([FromBody] PostRequestBody postRequestBody)
        {
            try
            {
                int from = 0;

                if (postRequestBody.PageIndex.HasValue)
                {
                    from = (postRequestBody.PageIndex.Value - 1) * postRequestBody.PageSize.Value;
                }

                var queryResponse = await _elasticClient.SearchAsync <object>(x => x.Index(IndexName)
                                                                              .From(from)
                                                                              .Size(postRequestBody.PageSize));

                if (queryResponse.IsValid)
                {
                    var responseObject = new Entities.SearchResponse
                    {
                        RecordCount = queryResponse.HitsMetadata.Total.Value,
                        Records     = queryResponse.Documents
                    };
                    return(Ok(JsonConvert.SerializeObject(responseObject)));
                }
                else
                {
                    return(BadRequest(queryResponse.ServerError.Error));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 3
0
        public IActionResult JoinLobby([FromBody] PostRequestBody body)
        {
            if (body.lobbyID != null && body.userID != null)
            {
                if (this.lobbyManager.JoinLobby(body.lobbyID, (int)body.userID))
                {
                    return(new ObjectResult(new { }));
                }

                return(NotFound());
            }

            return(BadRequest());
        }
Ejemplo n.º 4
0
        public IActionResult DeleteLobby([FromBody] PostRequestBody body)
        {
            if (body.lobbyID != null)
            {
                if (this.lobbyManager.DeleteLobby(body.lobbyID))
                {
                    return(new ObjectResult(new { }));
                }

                return(NotFound());
            }

            return(BadRequest());
        }
Ejemplo n.º 5
0
        public IActionResult CreateLobby([FromBody] PostRequestBody body)
        {
            if (body.userID != null)
            {
                string lid = this.lobbyManager.CreateLobby((int)body.userID);
                if (lid != null)
                {
                    return(new ObjectResult(new { lobbyID = lid }));
                }
                else
                {
                    return(NotFound());
                }
            }

            return(BadRequest());
        }
Ejemplo n.º 6
0
        public IActionResult Pay([FromBody] PostRequestBody body)
        {
            if (body.lobbyID != null)
            {
                bool?result = this.lobbyManager.Pay(body.lobbyID).Result;
                if (result == null)
                {
                    return(NotFound());
                }
                else if ((bool)result)
                {
                    return(new ObjectResult(new { }));
                }

                return(NoContent());
            }

            return(BadRequest());
        }
Ejemplo n.º 7
0
        public IActionResult LeaveLobby([FromBody] PostRequestBody body)
        {
            if (body.lobbyID != null && body.userID != null)
            {
                if (this.lobbyManager.LeaveLobby(body.lobbyID, (int)body.userID))
                {
                    if ((int)body.userID == lobbyManager.GetLobby(body.lobbyID).HostID)
                    {
                        return(this.DeleteLobby(body));
                    }

                    return(new ObjectResult(new { }));
                }

                return(NotFound());
            }

            return(BadRequest());
        }
Ejemplo n.º 8
0
        public IActionResult Set([FromBody] PostRequestBody body)
        {
            if (body.lobbyID != null)
            {
                if (body.userID != null)
                {
                    if (body.userPayAmount != null)
                    {
                        if (this.lobbyManager.SetUserPayAmount(body.lobbyID, (int)body.userID, (float)body.userPayAmount))
                        {
                            return(new ObjectResult(new { }));
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else if (body.verified != null)
                    {
                        if (this.lobbyManager.SetUserVerified(body.lobbyID, (int)body.userID, (bool)body.verified))
                        {
                            return(new ObjectResult(new { }));
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else if (body.receiptUrl != null)
                {
                    if (this.lobbyManager.SetReceiptUrl(body.lobbyID, body.receiptUrl))
                    {
                        return(new ObjectResult(new { }));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else if (body.totalPayAmount != null)
                {
                    if (this.lobbyManager.SetTotalPayAmount(body.lobbyID, (float)body.totalPayAmount))
                    {
                        return(new ObjectResult(new { }));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else if (body.hostConfirmed != null)
                {
                    if (this.lobbyManager.SetHostConfirmed(body.lobbyID, (bool)body.hostConfirmed))
                    {
                        return(new ObjectResult(new { }));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else if (body.merchantID != null)
                {
                    if (this.lobbyManager.SetMerchant(body.lobbyID, (int)body.merchantID))
                    {
                        return(new ObjectResult(new { }));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }

            return(BadRequest());
        }