예제 #1
0
        public async Task <OperationStatus <T> > CreateAsync <T>(T item)
        {
            var dto    = item as RoleDto;
            var result = await _roleManager.CreateAsync(new IdentityRole <Guid>(dto.Name));

            if (!result.Succeeded)
            {
                _operationHelper.InternalServerError <T>(_errorHelper.ErrorMessage(result));
            }
            await _context.SaveChangesAsync();

            return(_operationHelper.OK <T>("Role created successfully"));
        }
예제 #2
0
        public async Task <OperationStatus <T> > CreateAsync <T>(T dto)
        {
            var user = _mapper.Map <User>(dto);

            user.UserName = user.Email;
            var result = await _userManager.CreateAsync(user, _defaultPass);

            if (!result.Succeeded)
            {
                _operationHelper.InternalServerError <T>(_errorHelper.ErrorMessage(result));
            }
            await _context.SaveChangesAsync();

            return(_operationHelper.OK <T>("User created successfully"));
        }
예제 #3
0
        public async Task <OperationStatus <T> > CreateAsync <T>(T item)
        {
            if (!(item is EmployeeDto dto))
            {
                return(_operationHelper.BadRequest <T>("EmployeeDto is null"));
            }
            var employee = await _userManager.FindByIdAsync(dto.EmployeeId.ToString());

            employee.ManagerId = dto.UserId;
            var result = await _userManager.UpdateAsync(employee);

            if (!result.Succeeded)
            {
                _operationHelper.InternalServerError <T>(_errorHelper.ErrorMessage(result));
            }
            await _context.SaveChangesAsync();

            return(_operationHelper.OK <T>("Employee added successfully"));
        }