예제 #1
0
        private void SaveCrop(object cropInstance)
        {
            CropViewModel cropViewModel = cropInstance as CropViewModel;

            if (cropViewModel.Crop != null)
            {
                if (!cropViewModel.IsValid)
                {
                    Application.Current.MainPage.DisplayAlert("Предупреждение", "Задайте название культуры", "Ok");
                    return;
                }

                using (AppDbContext db = App.GetContext())
                {
                    if (cropViewModel.Crop.CropId == 0)
                    {
                        db.Entry(cropViewModel.Crop).State = EntityState.Added;
                    }
                    else
                    {
                        db.Crops.Update(cropViewModel.Crop);
                    }
                    db.SaveChanges();
                }
            }
            Back();
        }
예제 #2
0
        private void DeleteCrop(object cropInstance)
        {
            CropViewModel cropViewModel = cropInstance as CropViewModel;

            if (cropViewModel.Crop != null && cropViewModel.Crop.CropId != 0)
            {
                using (AppDbContext db = App.GetContext())
                {
                    db.Crops.Remove(cropViewModel.Crop);
                    db.SaveChanges();
                }
            }
            Back();
        }