Ejemplo n.º 1
0
 public CarOwnerViewModel()
 {
     carOwner              = new CarOwnerDTO();
     carOwner.Birthday     = DateTime.Now;
     NeedToSave            = true;
     this.PropertyChanged += CarOwnerViewModel_PropertyChanged;
 }
Ejemplo n.º 2
0
 public static void AddCarOwner(CarOwnerDTO carOwner)
 {
     try
     {
         var json    = System.Text.Json.JsonSerializer.Serialize(carOwner);
         var data    = new StringContent(json, Encoding.UTF8, "application/json");
         var request = httpClient.PostAsync($"CarOwner/{Source}", data);
         request.Wait();
         var responce = request.Result;
         if (!responce.IsSuccessStatusCode)
         {
             throw new Exception("Не удалось сохранить данные");
         }
     }
     catch (Exception e)
     {
         throw new Exception("Не удалось сохранить данные");
     }
 }
Ejemplo n.º 3
0
 public static void UpdateCarOwner(CarOwnerDTO carOwner, int id)
 {
     try
     {
         var json    = JsonConvert.SerializeObject(carOwner);
         var data    = new StringContent(json, Encoding.UTF8, "application/json");
         var request = httpClient.PutAsync($"CarOwner/{Source}/{id}", data);
         request.Wait();
         var responce = request.Result;
         if (!responce.IsSuccessStatusCode)
         {
             throw new Exception("Не удалось сохранить данные");
         }
     }
     catch (Exception e)
     {
         throw new Exception("Не удалось сохранить данные");
     }
 }
Ejemplo n.º 4
0
 public void Save()
 {
     if (NeedToSave)
     {
         int id = carOwner.ID;
         try
         {
             AutoServiceRequestsHelper.AddCarOwner(carOwner);
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
         if (id == 0)
         {
             var cos = AutoServiceRequestsHelper.GetCarOwners();
             var max = cos.Max(p => p.ID);
             carOwner = cos.First(p => p.ID == max);
             OnPropertyChanged(nameof(ID));
         }
         NeedToSave = false;
     }
 }
Ejemplo n.º 5
0
 public CarOwnerViewModel(CarOwnerDTO carOwner)
 {
     this.carOwner         = carOwner;
     NeedToSave            = false;
     this.PropertyChanged += CarOwnerViewModel_PropertyChanged;
 }