public void AddEmployee(string surName, string firstName, string patronymic, DateTime dateOfBirth, string docSeries, string docNumber, string Position, DbDepartment currentDep) { var employee = new DbEmployee(); employee.DepartmentID = currentDep.ID; employee.SurName = surName; employee.FirstName = firstName; employee.DateOfBirth = dateOfBirth; employee.Position = Position; if (!string.IsNullOrEmpty(patronymic)) { employee.Patronymic = patronymic; } if (!string.IsNullOrEmpty(docSeries)) { employee.DocSeries = docSeries; } if (!string.IsNullOrEmpty(docNumber)) { employee.DocNumber = docNumber; } using (var context = new Context()) { context.DbEmployees.Add(employee); context.SaveChanges(); } }
/// <summary> /// This method demonstrates how to undo the changes in Entity level using DbContext. /// </summary> public static void UndoChangesInEntity() { using (DbMySchool school = new DbMySchool()) { DbDepartment department = school.DbDepartments.FirstOrDefault(); IQueryable <DbCourse> courses = from c in school.DbCourses where c.DepartmentID == department.DepartmentID select c; Console.WriteLine("Before changes:"); foreach (DbCourse course in courses) { course.ShowDbCourse(); } // Change the courses. Console.WriteLine("After changes:"); foreach (DbCourse course in courses) { course.Title += "-Modified"; course.ShowDbCourse(); } Console.WriteLine("After Undo the First Course Entity:"); // Undo one course. You can see only the changes of the first course are undone. school.UndoDbEntity(courses.FirstOrDefault()); foreach (DbCourse course in courses) { course.ShowDbCourse(); } } }
/// <summary> /// This method demonstrates how to undo the changes in Entities level using DbContext. /// </summary> public static void UndoChangesInEntities() { using (DbMySchool school = new DbMySchool()) { DbDepartment department = school.DbDepartments.FirstOrDefault(); IQueryable <DbCourse> courses = from c in school.DbCourses where c.DepartmentID == department.DepartmentID select c; Console.WriteLine("Before changes:"); foreach (DbCourse course in courses) { course.ShowDbCourse(); } // Change the department and the related courses. Console.WriteLine("After changes:"); department.Name += "-Modified"; foreach (DbCourse course in courses) { course.Title += "-Modified"; course.ShowDbCourse(); } Console.WriteLine("After Undo Course Entities:"); // Undo the DbCourse type Entities. We will see the changes of the department // are not undone. school.UndoDbEntities <DbCourse>(); foreach (DbCourse course in courses) { course.ShowDbCourse(); } } }
/// <summary> /// This method demonstrates how to undo the changes in Property level using DbContext. /// </summary> public static void UndoChangesInProperty() { using (DbMySchool school = new DbMySchool()) { DbCourse course = school.DbCourses.FirstOrDefault(); DbDepartment department = school.DbDepartments.FirstOrDefault(); if (course != null) { Console.WriteLine("Before changes:"); course.ShowDbCourse(); Console.WriteLine("After changes:"); // Change the course Properties. course.Title += "-Modified"; course.Department = department; course.ShowDbCourse(); Console.WriteLine("After Undo Course Entity's Title Property:"); // Undo the change in the Entity Property level. UndoDbEntityProperty // method will undo the Title property of the course, but the change of the // Department Property will not be undone. school.UndoDbEntityProperty(course, "Title"); course.ShowDbCourse(); } } }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var department = new DbDepartment { DepartmentCode = request.DepartmentCode, RowVersion = request.RowVersion }; _context.Set <DbDepartment>().Attach(department); _context.Set <DbDepartment>().Remove(department); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public Department(Guid id) { this.id = id; InitializeComponent(); InitializeDepartmentTree(); department = departmentRepository.GetDepartment(id); NameTextLabel.Text = department.Name; CodeTextLabel.Text = department.Code; EmployeesTable.DataSource = employeeRepository.GetDepartmentEmployee(id); }
private void InitializeDepartmentTree() { department = departmentRepository .GetAllDepartments() .FirstOrDefault(p => p.ParentDepartmentID == null); MainDepartmentNameLabel.Text = department.Name; MainDepartmentCodeLabel.Text = department.Code; MainDepEmpTable.DataSource = employeeRepository.GetDepartmentEmployee(department.ID); foreach (var department in department.SubDepartments) { var nodes = DepartemntsTree.Nodes.Add(department.ID.ToString(), department.Name); if (department.SubDepartments.Any()) { AddNodes(department.SubDepartments.ToList(), nodes); } } }
public DepartmentController() { _dbDepartment = new DbDepartment(); }
public DepartmentController(IConfiguration configuration) { this._configuration = configuration; db_department = new DbDepartment(_configuration); }