Пример #1
0
        public async Task <OrgUnitResponseDTO> AddOrgUnitAsync(OrgUnitDTO orgUnitDTO, Guid userId)
        {
            using (var context = _contextFactory())
            {
                var company = await _userCompanyProvider.GetAsync(userId);

                var orgUnit = _mapper.Map(orgUnitDTO, _dbSetProxyProvider.Create(context.OrgUnits));

                orgUnit.TenantId  = company.TenantId;
                orgUnit.CompanyId = company.Id;

                context.OrgUnits.Add(orgUnit);

                await context.SaveChangesAsync();

                return(_mapper.Map <OrgUnitResponseDTO>(orgUnit));
            }
        }
Пример #2
0
        public async Task <EmployeeDTO> AddAsync(EmployeeDTO employeeDTO, Guid userId)
        {
            using (var context = _contextFactory())
                using (var rolesService = _rolesServiceFactory(context))
                    using (var userManager = _userManagerFactory())
                    {
                        var company = await _userCompanyProvider.GetAsync(userId);

                        var employee = _mapper.Map <EmployeeDTO, Employee>(employeeDTO);

                        employee = _prepareEmployeeForAddingProvider.Prepare(employee, company);

                        var user = _employeeUserTransformer.Transform(employee);

                        await userManager.CreateAsync(user);

                        context.Attach(user);

                        await rolesService.SetIsAdminStateAsync(user, employeeDTO.IsAdmin);

                        return(_mapper.Map <Employee, EmployeeDTO>(_employeeUserTransformer.Transform(user)));
                    }
        }