private void UpdateClassStudent() { App.last_action = "Update"; //Sync DisplayedProduct's ID with Name MyClass cc = (MyClass)ClassTable.SingleOrDefault(c => c.ID == (DisplayedProduct.ClassId ?? 0)); DisplayedProduct.ClassName = cc.ClassName; DisplayedProduct.StudentName = StudentTable.SingleOrDefault(s => s.ID == (DisplayedProduct.StudentId ?? 0)).FullName; //GetClassStudents() has Grouping, DisplayedProduct does the same DisplayedProduct.Grouping = cc.ClassName + " " + cc.Semester + " " + cc.Dayofweek + " " + cc.Timeofweek; if (!stat.ChkProductForUpdate(DisplayedProduct)) { return; } if (!App.StoreDB.UpdateProduct(DisplayedProduct)) { stat.Status = App.StoreDB.errorMessage; return; } log.Info("In UpdateClassStudent: " + $"Record updated for {DisplayedProduct.ClassName} {DisplayedProduct.StudentName}"); App.Messenger.NotifyColleagues("UpdateProduct", DisplayedProduct); MainWindowViewModel.Instance.StatusBar = $"DB Updated for {DisplayedProduct.ClassName} {DisplayedProduct.StudentName}"; } //UpdateProduct()
private void AddProduct() { App.last_action = "Add"; if (DisplayedProduct.ClassId == null) { stat.Status = "Please pick up a Class"; return; } if (DisplayedProduct.StudentId == null) { stat.Status = "Please pick up a Student"; return; } //Sync DisplayedProduct's ID with Name MyClass cc = (MyClass)ClassTable.SingleOrDefault(c => c.ID == (DisplayedProduct.ClassId ?? 0)); DisplayedProduct.ClassName = cc.ClassName; DisplayedProduct.StudentName = StudentTable.SingleOrDefault(s => s.ID == (DisplayedProduct.StudentId ?? 0)).FullName; //GetClassStudents() has Grouping, DisplayedProduct does the same DisplayedProduct.Grouping = cc.ClassName + " " + cc.Semester + " " + cc.Dayofweek + " " + cc.Timeofweek; DisplayedProduct.UpdateDateTime = DateTime.Now; //DisplayedProduct.InvoiceNumber if (!stat.ChkClassStudentForAdd(DisplayedProduct)) { return; } if (CSViewModel.Instance.DataItems.Contains(DisplayedProduct)) { stat.Status = $"{DisplayedProduct.StudentName} exists in class {DisplayedProduct.ClassName}"; MainWindowViewModel.Instance.StatusBar = $"{DisplayedProduct.StudentName} exists in class {DisplayedProduct.ClassName}"; return; } if (!App.StoreDB.AddProduct(DisplayedProduct)) { stat.Status = App.StoreDB.errorMessage; MainWindowViewModel.Instance.StatusBar = App.StoreDB.errorMessage; return; } App.Messenger.NotifyColleagues("AddProduct", DisplayedProduct); MainWindowViewModel.Instance.StatusBar = $"Record Added for {DisplayedProduct.Grouping} {DisplayedProduct.StudentName}"; log.Info("In AddProduct: " + $"Record Added for {DisplayedProduct.Grouping} {DisplayedProduct.StudentName}"); //This is necessary to create a brand-new instance for DisplayedProduct ClearClassStudentDisplay(); } //AddProduct()