コード例 #1
0
ファイル: API_DBLogic.cs プロジェクト: Agupnik/BOT
        public async Task <System.Net.HttpStatusCode> AddReal(string realname, int userid)
        {
            UserCurrencyToChange curr = new UserCurrencyToChange();

            curr.real = realname;
            var json = JsonConvert.SerializeObject(curr);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            using var client = new HttpClient();
            var content = await client.PutAsync("https://crmonapi.azurewebsites.net/crypto/useredit/" + userid, data);

            System.Net.HttpStatusCode state = content.StatusCode;
            return(state);
        }
コード例 #2
0
ファイル: CryptoController.cs プロジェクト: Agupnik/API
        public async Task <ObjectResult> UserEdit([FromBody] UserCurrencyToChange item, string ids)
        {
            WebReq   req = new WebReq();
            UserList dBUserItemsDBFind = JsonConvert.DeserializeObject <UserList>(System.IO.File.ReadAllText(path));
            Commands comm = new Commands();

            comm.DBCheck(comm, dBUserItemsDBFind, ids);
            if (comm.Exist == false)
            {
                Response.StatusCode = 404;
                return(new ObjectResult(null));
            }
            if (dBUserItemsDBFind == null)
            {
                Response.StatusCode = 404;
            }
            //bool cont = false;
            //int comm.Index = 0;
            //for (int i = 0; i < dBUserItemsDBFind.users.Count; i++)
            //{
            //    if (dBUserItemsDBFind.users[i].Id == ids)
            //    {
            //        comm = i;
            //        cont = true;
            //        break;
            //    }
            //}
            //if (cont == false)
            //{
            //    Response.StatusCode = 404;
            //    return new ObjectResult(null);
            //}
            //if(item.real != null)
            //{
            //    item.real = comm.InputCheckReal(item.real);
            //}
            //if (item.crypto != null)
            //{
            //    item.crypto = comm.InputCheckCrypto(item.crypto);
            //}
            //if (item.crypto_to_change != null)
            //{
            //    item.crypto_to_change = comm.InputCheckCrypto(item.crypto_to_change);
            //}
            client = new CoinpaprikaAPI.Client();
            var coins = await client.GetCoinsAsync();

            string s  = JsonConvert.SerializeObject(coins);
            Value  st = JsonConvert.DeserializeObject <Value>(s);
            Dictionary <string, string> names = new Dictionary <string, string>();
            int lenght = st.value.Count;

            for (int i = 0; i < lenght; i++)
            {
                st.value[i].Name = st.value[i].Name.ToLower();
                names.Add(st.value[i].Id, st.value[i].Name);
            }
            string temp  = names.FirstOrDefault(x => x.Value == item.crypto_to_change).Key;
            string temp2 = names.FirstOrDefault(x => x.Value == item.crypto).Key;

            if (temp != null)
            {
                temp = temp.ToLower();
            }
            if (temp2 != null)
            {
                temp2 = temp2.ToLower();
            }
            item.crypto = temp;
            if (item.real != null)
            {
                item.real = item.real.ToLower();
            }
            string item2  = item.real;
            var    status = await req.RealCheck(item2);

            if (status == HttpStatusCode.BadRequest)
            {
                Response.StatusCode = 400;
                return(new ObjectResult(null));
            }
            if (item2 != null)
            {
                string[]      cur  = dBUserItemsDBFind.users[comm.Index].Real.Split(new char[] { ',' });
                List <string> list = new List <string>(cur);
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] == item2)
                    {
                        Response.StatusCode = 409;
                        return(new ObjectResult(null));
                    }
                }
                list.Add(item2);
                string output = string.Join(",", list);
                dBUserItemsDBFind.users[comm.Index].Real = output;
                await System.IO.File.WriteAllTextAsync(path, JsonConvert.SerializeObject(dBUserItemsDBFind, Formatting.Indented));

                if (temp == null || temp2 == null)
                {
                    return(new ObjectResult(null));
                }
            }
            if (temp != null && temp2 != null)
            {
                for (int i = 0; i < dBUserItemsDBFind.users[comm.Index].Currency.Count; i++)
                {
                    if (dBUserItemsDBFind.users[comm.Index].Currency[i].Crypto == temp)
                    {
                        if (temp == temp2)
                        {
                            Response.StatusCode = 409;
                            return(new ObjectResult(null));
                        }
                        for (int j = 0; j < dBUserItemsDBFind.users[comm.Index].Currency.Count; j++)
                        {
                            if (temp2 == dBUserItemsDBFind.users[comm.Index].Currency[j].Crypto)
                            {
                                Response.StatusCode = 409;
                                return(new ObjectResult(null));
                            }
                        }
                        if (temp != temp2)
                        {
                            dBUserItemsDBFind.users[comm.Index].Currency[i].Crypto = temp2;
                            await System.IO.File.WriteAllTextAsync(path, JsonConvert.SerializeObject(dBUserItemsDBFind, Formatting.Indented));

                            return(new ObjectResult(null));
                        }
                    }
                }
                Response.StatusCode = 404;
                return(new ObjectResult(null));
            }
            else
            {
                Response.StatusCode = 404;
                return(new ObjectResult(null));
            }
        }