Exemple #1
0
 /// <summary>
 /// Updating a model
 /// </summary>
 /// <param name="model"></param>
 public void UpdateModel(T model, bool local = false)
 {
     if (!local)
     {
         _apirsDatabase.Entry(model).State = System.Data.Entity.EntityState.Modified;
     }
     else
     {
         _apirsLocalDatabase.Update(model);
     }
 }
 // Commit changes from the new object form
 // or edits made to the existing object form.
 public void Update()
 {
     using (var db = new ApirsDatabase())
     {
         try
         {
             if (SelectedDrilling.drillIdPk == 0)
             {
                 try
                 {
                     db.tblDrillings.Add(SelectedDrilling);
                     db.SaveChanges();
                     TryClose();
                 }
                 catch
                 {
                     ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Object can't be added. Please check every field again.");
                     return;
                 }
             }
             else
             {
                 tblDrilling result = db.tblDrillings.Where(drill => drill.drillName == SelectedDrilling.drillName).First();
                 if (result != null)
                 {
                     db.Entry <tblDrilling>(result).CurrentValues.SetValues(SelectedDrilling);
                     db.SaveChanges();
                 }
             }
         }
         catch (SqlException ex)
         {
             ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Please provide valid input parameters");
         }
         catch (Exception e)
         {
             ((ShellViewModel)IoC.Get <IShell>()).ShowInformation("Something went wrong");
         }
         finally
         {
         }
     }
 }