private void SaveFacilityTank(object facilityTankInstance) { FacilityTankViewModel facilityTankViewModel = facilityTankInstance as FacilityTankViewModel; if (facilityTankViewModel.FacilityTank != null) { if (!facilityTankViewModel.IsValid) { Application.Current.MainPage.DisplayAlert("Предупреждение", "Задайте название емкости", "Ok"); return; } using (AppDbContext db = App.GetContext()) { if (facilityTankViewModel.FacilityTank.FacilityTankId == 0) { db.Entry(facilityTankViewModel.FacilityTank).State = EntityState.Added; } else { db.FacilityTanks.Update(facilityTankViewModel.FacilityTank); } db.SaveChanges(); } } Back(); }
private void DeleteFacilityTank(object facilityTankInstance) { FacilityTankViewModel facilityTankViewModel = facilityTankInstance as FacilityTankViewModel; if (facilityTankViewModel.FacilityTank.FacilityTankId != 0) { using (AppDbContext db = App.GetContext()) { db.FacilityTanks.Remove(facilityTankViewModel.FacilityTank); db.SaveChanges(); } } Back(); }