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 }); } }
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"); }
public static Car ReadCarById(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 Car()); } else { CarWrapper carWrapper = JsonConvert.DeserializeObject <CarWrapper>(encodedResponse); Singleton.GetInstance().ActualCar = carWrapper; return(new Car() { CarId = carWrapper.Id, CarManufacturer = carWrapper.Manufacturer, CarModel = carWrapper.Model, CarFirstRegistrationDate = carWrapper.FirstRegistrationDate, CarActualMileage = carWrapper.ActualMileage, CarLicencePlate = carWrapper.LicencePlate, CarPurchaseDate = carWrapper.PurchaseDate, CarPurchaseMileage = carWrapper.PurchaseMileage, CarVin = carWrapper.Vin }); } }
public static Reminder ReadReminderById(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 Reminder()); } else { ReminderWrapper reminderWrapper = JsonConvert.DeserializeObject <ReminderWrapper>(encodedResponse); Singleton.GetInstance().ActualReminder = reminderWrapper; return(new Reminder() { ReminderId = reminderWrapper.Id, ReminderDate = reminderWrapper.Date, ReminderInfo = reminderWrapper.Info, ReminderIsChecked = reminderWrapper.IsChecked, ReminderMilleage = reminderWrapper.Milleage }); } }
private string UserOperation(string Login, string Password, string Uri) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("Login", Login); parameters.Add("Password", Password); RequestProvider requestProvider = new RequestProvider(Uri); requestProvider.Parameters = parameters; byte[] response = requestProvider.performPost(); return(Encoding.UTF8.GetString(response, 0, response.Length)); }
public static string UpdateExpense(Dictionary <string, string> paramDictionary) { RequestProvider requestProvider = new RequestProvider(updateUri); Dictionary <string, string> parameters = paramDictionary; requestProvider.Parameters = parameters; byte[] response = requestProvider.performPost(); string encodedResponse = Encoding.UTF8.GetString(response, 0, response.Length); if (errorsUpdate.Contains(encodedResponse)) { return(encodedResponse); } return(encodedResponse); }
public static string DeleteCarById(int id, ComboBox comboBoxCars) { RequestProvider requestProvider = new RequestProvider(deleteUri); requestProvider.Id = id; byte[] response = requestProvider.performGet(); string encodedResponse = Encoding.UTF8.GetString(response, 0, response.Length); if (errorsDelete.Contains(encodedResponse)) { return(encodedResponse); } else { CmbElement cmbElementDeleted = (CmbElement)comboBoxCars.SelectedItem; ObservableCollection <CmbElement> cmbList = (ObservableCollection <CmbElement>)comboBoxCars.ItemsSource; CmbElement cmbElementNext = cmbList.Single(i => i.Value == "<Create>"); comboBoxCars.SelectedItem = cmbElementNext; cmbList.Remove(cmbElementDeleted); comboBoxCars.ItemsSource = cmbList; return(encodedResponse); } }