public JsonResult GetExchangesToExchange(string Login) { List <ListExchangesData> exchangesDatas = new List <ListExchangesData>(); using (ServerDatabaseContext databaseContext = new ServerDatabaseContext()) { UserTable user = databaseContext.UserTables.Where(u => u.Login == Login).FirstOrDefault(); List <DatabaseExchangeTable> exchanges = databaseContext.DatabaseExchangeTables.ToList(); if (exchanges != null) { foreach (var elem in exchanges) { if ((elem.UserCreatorId == user.UserId && !elem.IsCreatorDone) || (elem.UserSenderId == user.UserId && (!elem.IsSenderDone || elem.IsSenderAccept == null))) { ListExchangesData data = new ListExchangesData { ExchangeId = elem.DatabaseExchangeId, IsCreatorDone = elem.IsCreatorDone, IsIAmCreator = false, IsOneWay = elem.IsOneWay, IsSenderAccept = elem.IsSenderAccept, IsSenderDone = elem.IsSenderDone, LoginCreatorOrSender = "" }; if (user.UserId == elem.UserCreatorId) { data.IsIAmCreator = true; UserTable userTo = databaseContext.UserTables.First(u => u.UserId == elem.UserSenderId); data.LoginCreatorOrSender = userTo.Login; } else { UserTable userTo = databaseContext.UserTables.First(u => u.UserId == elem.UserCreatorId); data.LoginCreatorOrSender = userTo.Login; } exchangesDatas.Add(data); } } } } ExchangesDataArray array = new ExchangesDataArray(exchangesDatas.ToArray()); return(Json(array, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Вернуть список доступных обменов с сервера /// </summary> /// <returns></returns> public static ExchangesDataArray GetExchanges() { if (!IsServer || !User.IsConnectToServer) { return(null); } ExchangesDataArray array = new ExchangesDataArray(); using (var client = new HttpClient()) { //Формирование строки запроса string query = ProgramSettings.AdressServer + "Server/GetExchangesToExchange?"; query += "Login=" + _login; //Выполнение запроса HttpResponseMessage message = client.GetAsync(query).Result; string resp = message.Content.ReadAsStringAsync().Result; array = JsonConvert.DeserializeObject <ExchangesDataArray>(resp); } return(array); }