private void SaveField(object fieldInstance) { FieldViewModel fieldViewModel = fieldInstance as FieldViewModel; if (fieldViewModel.Field != null) { if (!fieldViewModel.IsValid) { Application.Current.MainPage.DisplayAlert("Предупреждение", "Задайте название поля", "Ok"); return; } using (AppDbContext db = App.GetContext()) { if (fieldViewModel.Field.FieldId == 0) { db.Entry(fieldViewModel.Field).State = EntityState.Added; } else { db.Fields.Update(fieldViewModel.Field); } db.SaveChanges(); } } Back(); }
private void DeleteField(object fieldInstance) { FieldViewModel fieldViewModel = fieldInstance as FieldViewModel; if (fieldViewModel.Field != null && fieldViewModel.Field.FieldId != 0) { using (AppDbContext db = App.GetContext()) { db.Fields.Remove(fieldViewModel.Field); db.SaveChanges(); } } Back(); }