예제 #1
0
        public void TestCreate()
        {
            RequestJSON createrequestJSON = new RequestJSON
            {
                user = "******"
            };

            string actualres = _data.CreateUpdateAsync(createrequestJSON).Result;

            Assert.IsTrue(actualres.Contains("Guid sucessfully created"));
        }
예제 #2
0
        public void TestUpdate()
        {
            RequestJSON updaterequestJSON = new RequestJSON
            {
                expire = "1427822745",
                user   = "******"
            };

            string actualres = _data.CreateUpdateAsync(updaterequestJSON, "4C47514B4357535642485644544E5945").Result;

            Assert.IsTrue(actualres.Contains("Guid sucessfully created"));
        }
예제 #3
0
    public string CreateJsonMassage(string type)
    {
        RequestJSON requestJson = new RequestJSON();

        requestJson.id         = this.uniqueId;
        requestJson.type       = type;
        requestJson.playerName = this.playerName;
        requestJson.latitude   = this.latitude;
        requestJson.longitude  = this.longitude;
        requestJson.petName    = this.petName;
        requestJson.petPosX    = this.petPosX;
        requestJson.petPosY    = this.petPosY;

        return(JsonUtility.ToJson(requestJson));
    }
예제 #4
0
        static void Main(string[] args)
        {
            // Configuring Dependency Injection

            /*The first thing we do is configure the dependency injection container by creating a ServiceCollection,
             * adding our dependencies, and finally building an IServiceProvider*/
            var services = new ServiceCollection();

            services.AddSingleton <IData, Data>();
            services.AddSingleton <INetwork, Network>();

            /*The serviceProvider is our container we can use to resolve services in our application. */
            var serviceProvider = services.BuildServiceProvider();


            // Making Client Calls
            var client = serviceProvider.GetService <IData>();


            // Create
            RequestJSON createrequestJSON = new RequestJSON
            {
                user = "******"
            };

            Console.WriteLine(client.CreateUpdateAsync(createrequestJSON).Result); // parameter id is an optional field for CreateUpdateAsync method
            //and will be passed in only for during update'

            // Read
            Console.WriteLine(client.ReadAsync("4D4C4B484D4C4C564254574C50485949").Result);

            //Update
            RequestJSON updaterequestJSON = new RequestJSON
            {
                expire = "1427822745",
                user   = "******"
            };

            Console.WriteLine(client.CreateUpdateAsync(updaterequestJSON, "4C47514B4357535642485644544E5945").Result);


            // Delete
            client.DeleteAsync("4C47514B4357535642485644544E5945");

            Console.ReadKey();
        }
예제 #5
0
        public async Task <string> CreateUpdateAsync(RequestJSON createrequest, string id = "") // id is an optional parameter
        {
            string      result      = string.Empty;
            RequestJSON requestJSON = new RequestJSON
            {
                expire = createrequest.expire,
                user   = createrequest.user
            };


            string request     = JSON.Serialize(requestJSON);
            string endpointURL = "guid";

            if (!string.IsNullOrWhiteSpace(id))
            {
                endpointURL = "guid/" + id;
            }
            Dictionary <string, string> res = await _utils.PostRequestAsync(endpointURL, request).ConfigureAwait(false);

            result = ProcessResponse(res);

            return(result);
        }
예제 #6
0
        [HttpPost("{id?}")] // id is an optional parameter
        public async Task <IActionResult> Post([FromBody] RequestJSON requestJSON)
        {
            string expire = string.Empty;
            string guid   = string.Empty;

            if (RouteData.Values["id"] != null)
            {
                guid = RouteData.Values["id"].ToString();
            }
            else
            {
                guid = _utils.ComputeGuid();
            }
            if (!string.IsNullOrWhiteSpace(requestJSON.expire))
            {
                expire = requestJSON.expire;
            }
            else
            {
                expire = _utils.ComputeExpirationTime();
            }
            RequestJSON request = new RequestJSON
            {
                expire = expire,
                user   = requestJSON.user,
                guid   = guid
            };

            ResponseJSON res = await _data.CreateUpdateAsync(request);

            if (!string.IsNullOrWhiteSpace(res.status))
            {
                return(RedirectToAction("Error", "HandleError"));
            }
            return(Ok(new ApiOkResponse(res)));
        }
예제 #7
0
    public void ShowRequests(string[] requests)
    {
        Debug.Log("update frreq " + updateFriendRequests);

        Transform RequestsHolder = this.transform.Find("Holder").transform.Find("FriendRequestHolder").transform.Find("RequestsHolder");

        if (instantiateRequests)
        {
            for (int i = 0; i < requests.Length; i++)
            {
                //Instantiate
                GameObject requestObj = Instantiate(requestObject, RequestsHolder) as GameObject;
                requestObj.transform.parent = RequestsHolder;

                requestObj.name = "Request " + i;

                float requestObjY = requestObj.transform.position.y - 0.4f * i;
                ///////////SELSKO NAMESTVANE/////////////
                requestObj.transform.position = new Vector3(requestObj.transform.position.x, requestObjY, requestObj.transform.position.z);
                /////////////////////////////////////////
                /////Player.instance.GetComponent<Player>().showOCPlayerCard("kon");
                RequestJSON request = RequestJSON.CreateFromJSON(requests[i]);

                requestObj.GetComponent <ShowRequest>().request_id   = request._id;
                requestObj.GetComponent <ShowRequest>().requestOrder = i;
                requestObj.transform.Find("Canvas").transform.Find("Text").GetComponent <Text>().text = request.sender_username;
            }

            Debug.Log("Requests instantiated");
            instantiateRequests  = false;
            updateFriendRequests = false;

            NetworkManager.instance.GetComponent <NetworkManager>().GetRequestsCount();
        }
        else
        {
            if (updateFriendRequests)
            {
                NetworkManager.instance.GetComponent <NetworkManager>().GetRequestsCount();

                Debug.Log("UPDATE REQUESTS");
                int currentRequestsCount      = requests.Length;
                int instantiatedRequestsCount = RequestsHolder.childCount;

                if (currentRequestsCount > instantiatedRequestsCount) //We have new requests
                {
                    int dif = currentRequestsCount - instantiatedRequestsCount;
                    int newRequestNumber = 0;
                    for (int i = 0; i < dif; i++)
                    {
                        GameObject requestObj = Instantiate(requestObject, RequestsHolder) as GameObject;
                        requestObj.transform.parent = RequestsHolder;

                        float requestObjY = requestObj.transform.position.y - 0.4f * (instantiatedRequestsCount + i);
                        ///////////SELSKO NAMESTVANE/////////////
                        requestObj.transform.position = new Vector3(requestObj.transform.position.x, requestObjY, requestObj.transform.position.z);
                        /////////////////////////////////////////

                        newRequestNumber = instantiatedRequestsCount + i;
                        requestObj.name  = "Request " + newRequestNumber;
                    }
                }
                else if (currentRequestsCount < instantiatedRequestsCount) //Someone removed us from their friend list _)_
                {
                    int requestNumber = 0;
                    for (int i = instantiatedRequestsCount; i > currentRequestsCount; i--)
                    {
                        requestNumber = i - 1;
                        Destroy(RequestsHolder.transform.Find("Request " + requestNumber).gameObject);
                    }
                }

                int requestCounter = 0;
                foreach (Transform child in RequestsHolder)
                {
                    if (requestCounter < requests.Length)
                    {
                        RequestJSON request = RequestJSON.CreateFromJSON(requests[requestCounter]);
                        Debug.Log("name " + request.sender_username);
                        Debug.Log(requestCounter);
                        Debug.Log(RequestsHolder.childCount);

                        child.GetComponent <ShowRequest>().request_id   = request._id;
                        child.GetComponent <ShowRequest>().requestOrder = requestCounter;
                        child.transform.Find("Canvas").transform.Find("Text").GetComponent <Text>().text = request.sender_username;

                        requestCounter++;
                    }
                }

                updateFriendRequests = false;
            }
        }
    }
예제 #8
0
파일: Data.cs 프로젝트: bjonnala/testwebapi
        public async Task <ResponseJSON> CreateUpdateAsync(RequestJSON createrequest)
        {
            ResponseJSON response = new ResponseJSON();

            try
            {
                // Get record and update
                var uniqueid = await _testContext.Guid
                               .Where(p => p.UniqueId == createrequest.guid && p.User == createrequest.user)
                               .FirstOrDefaultAsync();

                if (uniqueid != null)
                {
                    if (!string.IsNullOrWhiteSpace(createrequest.expire))
                    {
                        uniqueid.Expires = createrequest.expire;
                    }
                    if (!string.IsNullOrWhiteSpace(createrequest.user))
                    {
                        uniqueid.User = createrequest.user;
                    }
                    await _testContext.SaveChangesAsync();

                    // Query the record back
                    var list = await _testContext.Guid
                               .Where(p => p.UniqueId == createrequest.guid)
                               .ToListAsync();

                    foreach (var item in list)
                    {
                        response.expire = item.Expires;
                        response.guid   = item.UniqueId;
                        response.user   = item.User;
                    }
                }
                else
                {
                    Models.Guid newguid = new Models.Guid
                    {
                        Expires  = createrequest.expire,
                        UniqueId = createrequest.guid,
                        User     = createrequest.user
                    };
                    _testContext.Add(newguid);
                    await _testContext.SaveChangesAsync();

                    var guids = await _testContext.Guid
                                .Where(p => p.UniqueId == createrequest.guid)
                                .ToListAsync();

                    foreach (var item in guids)
                    {
                        response.expire = item.Expires;
                        response.guid   = item.UniqueId;
                        response.user   = item.User;
                    }
                }
            }
            catch (Exception ex)
            {
                response.status = ex.Message;
            }
            return(response);
        }