private void DeleteAssignment(object assignmentInstance) { AssignmentViewModel assignmentViewModel = assignmentInstance as AssignmentViewModel; if (assignmentViewModel.Assignment != null && assignmentViewModel.Assignment.AssignmentId != 0) { using (AppDbContext db = App.GetContext()) { db.Assignments.Remove(assignmentViewModel.Assignment); db.SaveChanges(); } } Back(); }
private void SaveAssignment(object assignmentInstance) { AssignmentViewModel assignmentViewModel = assignmentInstance as AssignmentViewModel; if (assignmentViewModel.Assignment != null) { if (!assignmentViewModel.IsValid) { Application.Current.MainPage.DisplayAlert("Предупреждение", "Задайте название задания, выберите рецепт и введите норму вылива", "Ok"); return; } if (assignmentViewModel.Size != null) { if (String.IsNullOrEmpty(assignmentViewModel.Unit)) { Application.Current.MainPage.DisplayAlert("Предупреждение", "Задайте ед. изм. размера задания", "Ok"); return; } } using (AppDbContext db = App.GetContext()) { if (assignmentViewModel.Assignment.AssignmentId == 0) { db.Entry(assignmentViewModel.Assignment).State = EntityState.Added; } else { db.Assignments.Update(assignmentViewModel.Assignment); } db.SaveChanges(); } } Back(); }