public async Task <OrganizationUnitDto> UpdateOrganizationUnit(OrganizationUnitOutput input) { var organizationUnits = input.OrganizationUnit; var organizationUnit = await _organizationRepository.GetAsync(organizationUnits.Id); var parent = _organizationRepository.GetAll().Where(o => o.Id == organizationUnits.ParentId).FirstOrDefault(); if (parent != null) { var temp = parent.Number + "," + parent.Id.ToString(); organizationUnit.Number = temp; } else { organizationUnit.Number = "0"; } organizationUnit.DisplayName = organizationUnits.DisplayName; organizationUnit.Leader = organizationUnits.Leader; organizationUnit.IsShop = organizationUnits.IsShop; organizationUnit.Status = organizationUnits.Status; await _organizationUnitManager.UpdateAsync(organizationUnit); return(await CreateOrganizationUnitDto(organizationUnit)); }
// public async Task<OrganizationUnitDto> CreateOrganizationUnit(CreateOrganizationUnitInput input) public async Task <OrganizationUnitDto> CreateOrganizationUnit(OrganizationUnitOutput input) { #region 111 //var organizationUnit = new OrganizationUnit(AbpSession.TenantId, input.DisplayName, input.ParentId); //await _organizationUnitManager.CreateAsync(organizationUnit); //await CurrentUnitOfWork.SaveChangesAsync(); ///============================================================ //return ObjectMapper.Map<OrganizationUnitDto>(organizationUnit); //var parent = _organizationRepository.GetAll().Where(o => o.Id == input.ParentId).FirstOrDefault(); //var organization = new Organization() //{ // TenantId = AbpSession.TenantId, // DisplayName = input.DisplayName, // ParentId = input.ParentId, // Leader = input.Leader, // IsShop = input.IsShop, // Status = input.Status //}; //if (parent != null) //{ // var temp = parent.Number + "," + parent.Id.ToString(); // organization.Number = temp; //} //else //{ // organization.Number = "0"; //} //await _organizationUnitManager.CreateAsync(organization); //await CurrentUnitOfWork.SaveChangesAsync(); // return ObjectMapper.Map<OrganizationUnitDto>(organization); //=============================== #endregion var OrganizationUnit = input.OrganizationUnit; var parent = _organizationRepository.GetAll().Where(o => o.Id == OrganizationUnit.ParentId).FirstOrDefault(); var organization = new Organization() { TenantId = AbpSession.TenantId, DisplayName = OrganizationUnit.DisplayName, ParentId = OrganizationUnit.ParentId, Leader = OrganizationUnit.Leader, IsShop = OrganizationUnit.IsShop, Status = OrganizationUnit.Status }; if (parent != null) { var temp = parent.Number + "," + parent.Id.ToString(); organization.Number = temp; } else { organization.Number = "0"; } // var data = _organizationUnitManager.CreateAsync(organization); await _organizationUnitManager.CreateAsync(organization); await CurrentUnitOfWork.SaveChangesAsync(); var data = _organizationUnitRepository.GetAll().Where(t => (t.DisplayName == input.OrganizationUnit.DisplayName)).FirstOrDefault(); int id = Convert.ToInt32(data.Id); return(OrganizationUnit); }