public async Task <int> Delete(OrganizationDeleteDto input) { var count = 0; var query = JIT_t_OrganizationUnit.GetAll().Where(p => p.Id == input.Id) .Include(p => p.Children); var entity = await query.SingleOrDefaultAsync(p => true); var ORByID = JIT_t_OrganizationUnit.GetAll().SingleOrDefault(p => p.Id == entity.ParentId); var EmployeeByID = EmployeeApp.GetOneselfAndJunior(new int[] { input.Id }); List <Entities.Employee> EmployeeList = new EditableList <Entities.Employee>(); if (EmployeeByID != null) { EmployeeList = EmployeeApp._ERepository.GetAll() .Where(p => p.IsDeleted == false && EmployeeByID.Contains(p.FDepartment)).ToList(); } if (entity != null) { foreach (var e in EmployeeList) { if (ORByID != null) { e.FDepartment = ORByID.Id; } else { e.FDepartment = EmployeeApp._ERepository.GetAll().FirstOrDefault(p => p.Id == entity.ParentId && p.IsDeleted == false).Id; } EmployeeApp._ERepository.Update(e); } entity.IsDeleted = true; entity.DeletionTime = DateTime.Now; entity.DeleterUserId = this.AbpSession.UserId.HasValue ? this.AbpSession.UserId.Value : 0; count++; foreach (var c in entity.Children) { c.IsDeleted = true; c.DeletionTime = DateTime.Now; c.DeleterUserId = this.AbpSession.UserId.HasValue ? this.AbpSession.UserId.Value : 0; count++; } await JIT_t_OrganizationUnit.UpdateAsync(entity); } return(count); }
public async Task <t_OrganizationUnit> Update(OrganizationCreateInput input) { var entity = input.MapTo <t_OrganizationUnit>(); entity.Id = input.Id; entity.TenantId = this.AbpSession.TenantId.HasValue ? this.AbpSession.TenantId.Value : 0; entity.IsDeleted = false; entity.LastModificationTime = DateTime.Now; entity.LastModifierUserId = this.AbpSession.UserId.HasValue ? this.AbpSession.UserId.Value : 0; entity.CreationTime = input.CreationTime; entity.CreatorUserId = input.CreatorUserId; return(await JIT_t_OrganizationUnit.UpdateAsync(entity));; }