// GET: Departments public async Task<ActionResult> Index() { var departments = await _gaService.GetGaDepartments(); foreach (var department in departments) { var currentDeptpartment = await _departmentService.GetDepartmentByIdAsync(department.DeptCode); if (currentDeptpartment == null) { var addDepartment = new Department() { DepartmentID = department.DeptCode, Name = department.DeptCode, ParentID = "Root", Description = "Dept " + department.DeptName, Sort = await _departmentService.MaxSortAsync() }; try { await _departmentService.CreateAsync(addDepartment); } catch (Exception ex) { throw new Exception(ex.Message); } } } return View(await _departmentService.GetDepartmentsAsync()); }
public async Task UpdateAsync(Department department) { if(department != null) { _applicationDbContext.Entry(department).State = EntityState.Modified; await _applicationDbContext.SaveChangesAsync(); } }
public async Task CreateAsync(Department department) { if(department != null) { _applicationDbContext.Departments.Add(department); await _applicationDbContext.SaveChangesAsync(); } }