public async Task<TrainingForm> SaveAsync(TrainingForm model, ICollection<TrainingSubject> trainingSubjects) { if (model.Id == null || model.Id == Guid.Empty) { model.Id = Guid.NewGuid(); // TODO: USER_ID //model.CreatedByUserId = userId; model.CreatedOnDate = DateTime.Now; model.LastModifiedOnDate = DateTime.Now; await _dataContext.TrainingForms.AddAsync(model); } else { model.LastModifiedOnDate = DateTime.Now; // TODO: USER_ID // model.LastModifiedByUserId = actorId; _dataContext.TrainingForms.Update(model); var deleteTrainingSubjects = _dataContext.TrainingSubjects.Where(x => x.TrainingFormId == model.Id); _dataContext.TrainingSubjects.RemoveRange(deleteTrainingSubjects); } if (trainingSubjects != null && trainingSubjects.Count > 0) { trainingSubjects = trainingSubjects.Select(x => { x.Id = Guid.NewGuid(); x.TrainingFormId = model.Id; //x.CreatedByUserId = userId; x.CreatedOnDate = DateTime.Now; //x.LastModifiedByUserId = actorId; x.LastModifiedOnDate = DateTime.Now; return x; }).ToList(); await _dataContext.TrainingSubjects.AddRangeAsync(trainingSubjects); } await _dataContext.SaveChangesAsync(); InvalidCache(model.Id); //TODO: Xử lý loop bên trong dữ liệu model.TrainingSubjects = null; return model; }
public async Task<bool> DeleteManyAsync(Guid[] deleteIds) { foreach (var id in deleteIds) { var model = await GetById(id); if (model == null) { throw new ArgumentException($"Id {id} không tồn tại"); } var deleteTrainingForm = new TrainingForm() { Id = id }; _dataContext.TrainingForms.Attach(deleteTrainingForm); _dataContext.TrainingForms.Remove(deleteTrainingForm); } await _dataContext.SaveChangesAsync(); return true; }
private void InitializeComponent() { // setup the menus _ms = new MenuStrip(); _fileMenu = new ToolStripMenuItem("File"); _exitMenuItem = new ToolStripMenuItem("Exit", null, new EventHandler(this.ExitProgramHandler)); _editMenu = new ToolStripMenuItem("Edit"); _createEmployeeMenuItem = new ToolStripMenuItem("Create Employee...", null, new EventHandler(this.CreateEmployeeHandler)); _createTrainingMenuItem = new ToolStripMenuItem("Create Training...", null, new EventHandler(this.CreateTrainingHandler)); _editEmployeeMenuItem = new ToolStripMenuItem("Edit Employee...", null, new EventHandler(this.EditEmployeeHandler)); _editEmployeeMenuItem.Enabled = false; _editTrainingMenuItem = new ToolStripMenuItem("Edit Training...", null, new EventHandler(this.EditTrainingHandler)); _editTrainingMenuItem.Enabled = false; _deleteEmployeeMenuItem = new ToolStripMenuItem("Delete Employee...", null, new EventHandler(this.DeleteEmployeeHandler)); _deleteEmployeeMenuItem.Enabled = false; _deleteTrainingMenuItem = new ToolStripMenuItem("Delete Training...", null, new EventHandler(this.DeleteTrainingHandler)); _deleteTrainingMenuItem.Enabled = false; _fileMenu.DropDownItems.Add(_exitMenuItem); _ms.Items.Add(_fileMenu); _editMenu.DropDownItems.Add(_createEmployeeMenuItem); _editMenu.DropDownItems.Add(_createTrainingMenuItem); _editMenu.DropDownItems.Add("-"); _editMenu.DropDownItems.Add(_editEmployeeMenuItem); _editMenu.DropDownItems.Add(_editTrainingMenuItem); _editMenu.DropDownItems.Add("-"); _editMenu.DropDownItems.Add(_deleteEmployeeMenuItem); _editMenu.DropDownItems.Add(_deleteTrainingMenuItem); _ms.Items.Add(_editMenu); // create the table panel _tablePanel = new TableLayoutPanel(); _tablePanel.RowCount = 2; _tablePanel.ColumnCount = 2; _tablePanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; _tablePanel.Dock = DockStyle.Top; _tablePanel.Height = 400; // create and initialize the data grids _employeeGrid = new DataGridView(); _employeeGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; _employeeGrid.Height = 200; _employeeGrid.Width = 700; _employeeList = _employeeTraining.GetAllEmployees(); _employeeGrid.DataSource = _employeeList; _employeeGrid.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; _employeeGrid.Click += this.EmployeeGridClickedHandler; _employeeGrid.DataBindingComplete += this.EmployeeGridDataBindingCompleteHandler; _trainingGrid = new DataGridView(); _trainingGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; _trainingGrid.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; _trainingGrid.DataBindingComplete += this.TrainingGridDataBindingCompleteHandler; _trainingList = _employeeTraining.GetTrainingForEmployee(_employeeList[0].EmployeeID); _trainingGrid.DataSource = _trainingList; // create picture box _pictureBox = new PictureBox(); _pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; //add grids to table panel _tablePanel.Controls.Add(_employeeGrid); _tablePanel.Controls.Add(_pictureBox); _tablePanel.Controls.Add(_trainingGrid); _tablePanel.SetColumnSpan(_trainingGrid, 2); this.Controls.Add(_tablePanel); _ms.Dock = DockStyle.Top; this.MainMenuStrip = _ms; this.Controls.Add(_ms); this.Height = WINDOW_HEIGHT; this.Width = WINDOW_WIDTH; this.Text = WINDOW_TITLE; _employeeForm = new EmployeeForm(this); _employeeForm.Visible = false; _trainingForm = new TrainingForm(this); _trainingForm.Visible = false; }