示例#1
0
        public static Expense ReadExpenseById(int id)
        {
            RequestProvider requestProvider = new RequestProvider(readUri);

            requestProvider.Id = id;
            byte[] response        = requestProvider.performGet();
            string encodedResponse = Encoding.UTF8.GetString(response, 0, response.Length);

            if (errorsRead.Contains(encodedResponse))
            {
                MainWindow.ShowErrorInfo(encodedResponse);
                return(new Expense());
            }
            else
            {
                ExpenseWrapper expenseWrapper         = JsonConvert.DeserializeObject <ExpenseWrapper>(encodedResponse);
                Singleton.GetInstance().ActualExpense = expenseWrapper;
                return(new Expense()
                {
                    ExpenseId = expenseWrapper.Id,
                    ExpenseDate = expenseWrapper.Date,
                    ExpensePlace = expenseWrapper.Place,
                    ExpenseInfo = expenseWrapper.Info,
                    ExpenseMileage = expenseWrapper.Mileage,
                    ExpensePrice = (double)expenseWrapper.Price,
                    ExpenseTypeInfo = expenseWrapper.TypeInfo
                });
            }
        }
示例#2
0
        public static string CreateExpense(ComboBox comboBoxExpenses, Dictionary <string, string> paramDictionary, ref int counter)
        {
            RequestProvider requestProvider = new RequestProvider(createUri);

            requestProvider.Parameters = paramDictionary;
            byte[] response        = requestProvider.performPost();
            string encodedResponse = Encoding.UTF8.GetString(response, 0, response.Length);

            if (errorsCreate.Contains(encodedResponse))
            {
                return(encodedResponse);
            }
            ExpenseWrapper expenseWrapper = JsonConvert.DeserializeObject <ExpenseWrapper>(encodedResponse);

            Singleton.GetInstance().ActualCar.ExpenseList.Add(expenseWrapper.Id);
            ObservableCollection <CmbElement> cmbList = (ObservableCollection <CmbElement>)comboBoxExpenses.ItemsSource;
            CmbElement cmbElementActual = new CmbElement {
                Id = counter++, Value = expenseWrapper.Id.ToString()
            };

            cmbList.Add(cmbElementActual);
            comboBoxExpenses.ItemsSource  = cmbList;
            comboBoxExpenses.SelectedItem = cmbElementActual;
            return("Correct");
        }