Пример #1
0
        protected void rpDepartments_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem != null)
            {
                CompanyDepartment companyDepartment = (CompanyDepartment)e.Item.DataItem;
                var departmentId = companyDepartment.fk_department;

                var departmentEmployees = _context.DepartmenEmployee.Where(x => x.fk_department == departmentId).ToList();
                var rpEmployees         = (Repeater)e.Item.FindControl("rpEmployees");
                rpEmployees.DataSource = departmentEmployees;
                rpEmployees.DataBind();
            }
        }
Пример #2
0
        protected void btnSaveDepartment_OnClick(object sender, EventArgs e)
        {
            var departmentName = txtDepartment.Text;

            var department = new Department();

            department.name = departmentName;

            _context.Department.Add(department);
            _context.SaveChanges();

            var newDepartment     = _context.Department.FirstOrDefault(x => x.Id == department.Id);
            var companyDepartment = new CompanyDepartment();

            companyDepartment.fk_company    = Convert.ToInt32(ddlCompanies.SelectedValue);
            companyDepartment.fk_department = newDepartment.Id;
            _context.CompanyDepartment.Add(companyDepartment);
            _context.SaveChanges();

            LoadDropdownControls();
            rpDepartments.DataBind();
            upCompanyDetails.Update();
        }