Exemplo n.º 1
0
        public SuperAdminModel AddSuperAdmin(AddAdminDto dto)
        {
            return(ProtectedExecute <AddAdminDto, SuperAdminModel>(adminDto =>
            {
                CheckActiveSuperAdmin(adminDto.SuperAdminSession);

                if (AccountRepo.Get(adminDto.AccountId.GetValueOrDefault()) == null)
                {
                    throw new NotFoundException("Account");
                }

                if (IsSuperAdmin(adminDto.AccountId.GetValueOrDefault()))
                {
                    throw new ConflictException("super-admin account");
                }

                AdminModel admin = AdminRepo.GetByAccountId(adminDto.AccountId.GetValueOrDefault());

                if (admin == null)
                {
                    AdminModel adminModel = Mapper.Map <AddAdminDto, AdminModel>(adminDto);
                    admin = AdminRepo.Create(adminModel);
                }

                SuperAdminModel model = Mapper.Map <AdminModel, SuperAdminModel>(admin);
                return SuperAdminRepo.Create(model);
            }, dto));
        }
Exemplo n.º 2
0
 public HttpResponseMessage AddSuperAdmin([FromBody] AddAdminDto adminDto)
 {
     return(Request.ExecuteProtectedAndWrapResult <AddAdminDto, SuperAdminModel>(
                dto => AdminService.AddSuperAdmin(dto),
                ModelState, adminDto
                ));
 }
        public async Task <IActionResult> CreateAdmin([FromBody] AddAdminDto model)
        {
            var res = await _manager.AddAdmin(model);

            if (!res)
            {
                return(UnprocessableEntity());
            }

            return(CreatedAtAction(nameof(CreateAdmin), model));
        }
        public async Task <IActionResult> CreateUser(AddAdminDto addAdminDto)
        {
            addAdminDto.CallbackUrl = (Request.Scheme + "://" + Request.Host + "/resetpassword/");

            var user = _mapper.Map <User>(addAdminDto);

            user = await _adminService.CreateUser(user, addAdminDto.Role, addAdminDto.CallbackUrl);

            var userToReturn = _mapper.Map <UserForDetailedDto>(user);

            userToReturn = _adminService.AddRoleToUser(userToReturn);

            return(CreatedAtRoute("Get", new { id = userToReturn.Id }, userToReturn));
        }
Exemplo n.º 5
0
        public async Task <ResponseModel> AddAdminAccount(AddAdminDto dto)
        {
            if (await this.DbContext.TAccount.FindAsync(new { Name = dto.Model.UserName }) != null)
            {
                dto.Result.ResultCode = (int)AccountResultCode.UserNameExisted;
                dto.Result.Message    = "该用户名存在";
                return(dto.Result);
            }

            //插入TAccount
            var account = new TAccount
            {
                Name     = dto.Model.UserName,
                Password = dto.Model.Password,
                Type     = dto.Model.AccountType,
                Emai     = dto.Model.Email,
            };

            account.SetCreator(1);
            account.SetUpdater(1);
            await this.DbContext.AddOneAsync(account);

            var amax = await this.GetAdminMaxJobNumber();

            var cmax = await this.GetCustomerMaxJobNumber();

            //插入TAdmin
            var admin = new TAdmin
            {
                AccountId = account.Id,
                JobNumber = JobNumberUtils.GetJobNumber(amax, cmax),
            };

            admin.SetCreator(1);
            admin.SetUpdater(1);
            await this.DbContext.AddOneAsync(admin);

            if (await this.DbContext.SaveChangesAsync() <= 0)
            {
                dto.Result.Message = "数据保存失败";
                return(dto.Result);
            }
            dto.Result.ResultCode = (int)ResultCode.Successful;
            return(dto.Result);
        }
Exemplo n.º 6
0
 public async Task <bool> AddAdmin(AddAdminDto model)
 {
     return(await _service.Add(_mapping.Map <Admin>(model)));
 }