private void OnEditClosing(object sender, DialogClosingEventArgs args) { if (Equals(args.Parameter, false)) { return; } if (Equals(args.Parameter, "Close")) { try { _context.Entry(SelectedTeacher).CurrentValues.SetValues(_context.Entry(SelectedTeacher).OriginalValues); LoadData(); } catch (Exception e) { Console.WriteLine(e); } return; } bool result = false; if (_isOkMessageOpen && Equals(args.Parameter, "Cancel")) { _isOkMessageOpen = false; args.Cancel(); args.Session.UpdateContent(_content); } if (Equals(args.Parameter, "Update")) { args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); Task.Run(() => { try { _context.Entry(SelectedTeacher).State = EntityState.Modified; _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } }).ContinueWith((t, _) => { if (!result) { args.Session.UpdateContent(new OkMessageDialog() { DataContext = result ? "Update Successfull" : "Update Failed" }); return; } LoadData(); SendUpdateMessage(); args.Session.Close(false); }, null, TaskScheduler.FromCurrentSynchronizationContext()); } if (Equals(args.Parameter, "Delete")) { _content = args.Session.Content; args.Cancel(); _isOkMessageOpen = true; args.Session.UpdateContent(new OkCancelMessageDialog() { DataContext = $"Are you sure you want to delete {SelectedTeacher.FullName}?" }); } if (Equals(args.Parameter, "Ok") && _isOkMessageOpen) { _isOkMessageOpen = false; args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); Task.Run(() => { try { _context.Teachers.Remove(SelectedTeacher); _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } }).ContinueWith((t, _) => { LoadData(); _isOkMessageOpen = false; SendUpdateMessage(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = result ? "Delete Successfull" : "Delete Failed" }); }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }
private void EditPartyListCEH(object sender, DialogClosingEventArgs args) { if (Equals(args.Parameter, false)) { return; } bool result = false; if (args.Parameter is TextBox) { args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); TextBox txtName = (TextBox)args.Parameter; string name = txtName.Text.Trim(); if (string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name)) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Null entry" }); return; } var duplicate = _context.PartyLists.FirstOrDefault(c => c.Name == name); if (duplicate != null) { args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Duplicate name" }); return; } Task.Run(() => { Thread.Sleep(1000); try { SelectedPartyList.Name = name; _context.Entry(SelectedPartyList).State = EntityState.Modified; _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e); result = false; } }).ContinueWith((t, _) => { if (result) { LoadData(); args.Session.Close(false); } else { args.Session.UpdateContent( new OkMessageDialog() { DataContext = "Edit Failed" }); } }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }
private async void DoAdd() { await DialogHost.Show(new FieldMessageDialog() { DataContext = "Add New Category" }, "CategoryDialog", delegate(object sender, DialogClosingEventArgs args) { bool result = false; if (Equals(args.Parameter, false)) { return; } if (args.Parameter is TextBox) { args.Session.UpdateContent(new PleaseWaitView()); TextBox txtName = (TextBox)args.Parameter; string name = txtName.Text.Trim(); var category = new Category() { Name = name }; if (string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name)) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Null entry" }); return; } var duplicate = _context.Categories.FirstOrDefault(c => c.Name == name); if (duplicate != null) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Duplicate Name" }); return; } Task.Run(() => { try { _context.Entry(category).State = EntityState.Added; _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } }).ContinueWith((t, _) => { if (!result) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Failed to add" }); } else { Categories.Add(category); } }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }); }
private void EditClosing(object o, DialogClosingEventArgs args) { if (Equals(args.Parameter, false)) { return; } if (Equals(args.Parameter, "Close")) { try { _context.Entry(SelectedBook).CurrentValues.SetValues(_context.Entry(SelectedBook).OriginalValues); } catch (Exception e) { Console.WriteLine(e); } return; } bool result = false; if (_isOkMessageOpen && Equals(args.Parameter, "Cancel")) { _isOkMessageOpen = false; args.Cancel(); args.Session.UpdateContent(_content); } if (Equals(args.Parameter, "Update")) { args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); Task.Run(() => { var bookList = _context.TeacherBorrowedBooks.Where(c => c.Book.Id == SelectedBook.Id).ToList(); int quantityBorrowed = 0; foreach (var book in bookList) { quantityBorrowed += book.QuantityBorrowed; } try { SelectedBook.AvailableQuantity = SelectedBook.Quantity - (quantityBorrowed + SelectedBook.Damaged + SelectedBook.Outdated); _context.Entry(SelectedBook).State = EntityState.Modified; _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } }).ContinueWith((t, _) => { if (!result) { //args.Session.UpdateContent(new OkMessageDialog() { DataContext = result ? "Update Successfull" : "Update Failed" }); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Update Successfull" }); return; } LoadData(); UpdateBooks(); args.Session.Close(false); }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }
private void AddPositionClosing(object sender, DialogClosingEventArgs args) { bool result = false; if (Equals(args.Parameter, false)) { return; } if (args.Parameter is TextBox) { args.Session.UpdateContent(new PleaseWaitView()); TextBox txtName = (TextBox)args.Parameter; string name = txtName.Text.Trim(); var newPosition = new CouncilPosition() { Position = name }; if (string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name)) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Null entry" }); return; } var duplicate = _context.CouncilPositions.FirstOrDefault(c => c.Position == name); if (duplicate != null) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Duplicate Name" }); return; } Task.Run(() => { Thread.Sleep(1000); try { _context.Entry(newPosition).State = EntityState.Added; _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } }).ContinueWith((t, _) => { if (!result) { args.Cancel(); args.Session.UpdateContent(new OkMessageDialog() { DataContext = "Failed to add" }); } else { PositionList.Add(newPosition); } }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }
private async void ViewStudentEdit() { if (SelectedStudent == null) { await DialogHost.Show(new OkMessageDialog() { DataContext = "Please select a student!" }); return; } await DialogHost.Show(new PleaseWaitView(), "RootDialog", delegate(object sender, DialogOpenedEventArgs args) { Task.Run(() => { //_oldRequirementStudents = Requirements; AddRequirementsToStudent(SelectedStudent); //Requirements = _context.RequirementStudents.AsNoTracking() // .Where(c => c.StudentId == SelectedStudent.Id) // .ToList(); Requirements = _context.RequirementStudents .Where(c => c.StudentId == SelectedStudent.Id) .ToList(); Thread.Sleep(1000); }).ContinueWith((t, _) => { //Requirements = SelectedStudent.RequirementStudents.ToList(); _oldRequirementStudents = Requirements; SelectedYearLevel = SelectedStudent.YearLevel; SelectedSection = SelectedStudent.Section; YearLevels = _context.YearLevels.ToObservableCollection(); GenderList = Enum.GetNames(typeof(EnumGender)).ToList(); args.Session.UpdateContent(new StudentEditView() { DataContext = this }); }, null, TaskScheduler.FromCurrentSynchronizationContext()); }, delegate(object sender, DialogClosingEventArgs args) { bool result = false; if (Equals(args.Parameter, false)) { return; } if (Equals(args.Parameter, "Close")) { try { _context.Entry(SelectedStudent).CurrentValues.SetValues(_context.Entry(SelectedStudent).OriginalValues); foreach (var requirement in Requirements) { _context.Entry(requirement).CurrentValues.SetValues(_context.Entry(requirement).OriginalValues); } } catch (Exception e) { Console.WriteLine(e); } Requirements = _oldRequirementStudents; return; } if (_isOkMessageOpen && Equals(args.Parameter, "Cancel")) { _isOkMessageOpen = false; args.Cancel(); args.Session.UpdateContent(_content); } if (Equals(args.Parameter, "Update")) { args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); Task.Run(() => { Student student = null; try { //using (var context = new MorenoContext()) //{ // foreach (var item in Requirements) // { // context.Entry(item).State = EntityState.Modified; // } // context.SaveChanges(); //} ////foreach (var requirement in Requirements) ////{ //// //_context.Entry(requirement).State = EntityState.Modified; //// _context.RequirementStudents.Attach(requirement); ////} ////_context.SaveChanges(); SelectedStudent.YearLevel = SelectedYearLevel; SelectedStudent.Section = SelectedSection; student = StudentList.FirstOrDefault(c => c == SelectedStudent); _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } return(student); }).ContinueWith((t, _) => { if (t.Result != null) { t.Result.RequirementStudents = Requirements; } LoadStudents(); var message = result ? "Update Successfull" : "Update Failed"; if (result) { LoadStudents(); } args.Session.UpdateContent(new OkMessageDialog() { DataContext = message }); }, null, TaskScheduler.FromCurrentSynchronizationContext()); } if (Equals(args.Parameter, "Delete")) { _content = args.Session.Content; args.Cancel(); _isOkMessageOpen = true; args.Session.UpdateContent(new OkCancelMessageDialog() { DataContext = $"Are you sure you want to delete {SelectedStudent.FullName}?" }); } if (Equals(args.Parameter, "Ok") && _isOkMessageOpen) { _isOkMessageOpen = false; args.Cancel(); args.Session.UpdateContent(new PleaseWaitView()); Task.Run(() => { try { _context.Students.Remove(SelectedStudent); _context.SaveChanges(); result = true; } catch (Exception e) { Console.WriteLine(e.Message); result = false; } }).ContinueWith((t, _) => { LoadStudents(); var message = result ? "Delete Successfull" : "Delete Failed"; _isOkMessageOpen = false; args.Session.UpdateContent(new OkMessageDialog() { DataContext = message }); }, null, TaskScheduler.FromCurrentSynchronizationContext()); } }); //Requirements = _context.RequirementStudents.AsNoTracking().Where(c => c.StudentId == SelectedStudent.Id) // .ToList(); //_oldRequirementStudents = Requirements; //await AddRequirementsToStudentAsync(SelectedStudent); //await DialogHost.Show(new StudentEditView() { DataContext = this }, "RootDialog", StudentEditClosingEventHandler); }