コード例 #1
0
        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();
            }
        }
コード例 #2
0
        /// <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();
                }
            }
        }
コード例 #3
0
        /// <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();
                }
            }
        }
コード例 #4
0
        /// <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();
                }
            }
        }
コード例 #5
0
ファイル: Delete.cs プロジェクト: ss-group/CleanArchitecture
            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);
            }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
 public DepartmentController()
 {
     _dbDepartment = new DbDepartment();
 }
コード例 #9
0
 public DepartmentController(IConfiguration configuration)
 {
     this._configuration = configuration;
     db_department       = new DbDepartment(_configuration);
 }