예제 #1
0
        /// <summary>
        /// 管理员更新
        /// </summary>
        /// <param name="adminDto"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task <AdminDto> UpdateAdmin(AdminDto adminDto)
        {
            var admin = await _adminRepository.Entities.FirstOrDefaultAsync(u => u.Id == adminDto.Id);

            if (admin == null)
            {
                throw Oops.Oh(AdminErrorCodes.a1002);
            }
            var newAdminEntity = adminDto.Adapt(admin);
            var newAdmin       = await newAdminEntity.UpdateExcludeAsync(u => u.CreateTime);

            return(newAdminEntity.Adapt <AdminDto>());
        }
예제 #2
0
        /// <summary>
        /// 管理员注册
        /// </summary>
        /// <param name="adminDto"></param>
        /// <returns></returns>
        public async Task <AdminDto> CreateAdmin(AdminDto adminDto)
        {
            var admin = await _adminRepository.Entities.FirstOrDefaultAsync(u => u.Username.Equals(adminDto.Username));

            if (admin != null)
            {
                throw Oops.Oh(AdminErrorCodes.a1003);
            }
            // adminDto.CreateTime = TimeUtil.GetTimeStampNow();
            var regAdmin = await _adminRepository.InsertNowAsync(adminDto.Adapt <TbAdmin>());

            return(regAdmin.Entity.Adapt <AdminDto>());
        }