예제 #1
0
        public async Task <bool> AddAsync(DeptShowDto dto)
        {
            using (var tran = _databaseFixture.Db.BeginTransaction())
            {
                try
                {
                    dto.SysDept.CreateTime = DateTime.Now.ToTimeStamp();
                    await _databaseFixture.Db.SysDept.InsertAsync(dto.SysDept, tran);

                    //path
                    string path = "";
                    if (dto.SysDept.ParentId > 0)
                    {
                        var parentres = await _databaseFixture.Db.SysDept.FindAsync(m => m.DeptId == dto.SysDept.ParentId);

                        if (parentres != null)
                        {
                            path = parentres.Path;
                        }
                    }
                    dto.SysDept.Path = path.IsNullOrEmpty() ? dto.SysDept.DeptId.ToString() : path + ":" + dto.SysDept.DeptId;
                    await _databaseFixture.Db.SysDept.UpdateAsync(dto.SysDept, tran);

                    tran.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    _logJobs.ExceptionLog(dto.SysDept.CreateUserId, ex);
                    return(false);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 新增系统
        /// </summary>
        /// <param name="system"></param>
        /// <returns></returns>
        public async Task <bool> InsertAsync(SysSystem system)
        {
            try
            {
                system.SystemCode = Guid.NewGuid().ToString();
                system.CreateTime = DateTime.Now.ToTimeStamp();
                var res = await _databaseFixture.Db.SysSystem.InsertAsync(system);

                return(res);
            }
            catch (Exception e)
            {
                _logJobs.ExceptionLog(system.CreateUserId, e);
                return(false);
            }
        }
        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public async Task <bool> AddAsync(SysRole role)
        {
            try
            {
                role.CreateTime = DateTime.Now.ToTimeStamp();
                role.IsDel      = 0;
                await _databaseFixture.Db.SysRole.InsertAsync(role);

                return(true);
            }
            catch (Exception ex)
            {
                _logJobs.ExceptionLog(role.CreateUserId, ex);
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account">账号</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public async Task <ILoginResult <UserIdentity> > LoginAsync(string account, string password)
        {
            ILoginResult <UserIdentity> loginResult = new LoginResult <UserIdentity>();

            try
            {
                if (account.IsNullOrEmpty() || password.IsNullOrEmpty())
                {
                    loginResult.LoginStatus = LoginStatus.Error;
                    loginResult.Message     = "请输入用户名或密码";
                    return(loginResult);
                }
                string pwd = EncryptProvider.CreateSha1Code(password);
                account = account.TrimBlank();
                SysUser dbuser = await _databaseFixture.Db.SysUser.FindAsync(m => m.IsDel == 0 && m.Account == account && m.Password == pwd);

                loginResult.User = new UserIdentity
                {
                    UserId     = dbuser.UserId,
                    UserName   = dbuser.UserName,
                    HeadImg    = dbuser.HeadImg,
                    Sex        = UserSex.Unknown,
                    CreateTime = dbuser.CreateTime.ToDateTime()
                };
                if (dbuser == null)
                {
                    loginResult.Message     = "用户名或密码错误!";
                    loginResult.LoginStatus = LoginStatus.Error;
                }
                else
                {
                    _logJobs.LoginLog(dbuser.UserId, dbuser.UserName);
                    loginResult.LoginStatus = LoginStatus.Success;
                }
            }
            catch (Exception ex)
            {
                loginResult.Message     = ex.Message;
                loginResult.LoginStatus = LoginStatus.Exception;
                _logJobs.ExceptionLog(0, ex);
            }
            return(loginResult);
        }
예제 #5
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <bool> AddAsync(ResourceShowDto dto)
        {
            using (var tran = _databaseFixture.Db.BeginTransaction())
            {
                try
                {
                    #region 基本信息添加
                    dto.SysResource.CreateTime = DateTime.Now.ToTimeStamp();
                    dto.SysResource.IsButton   = 0;
                    await _databaseFixture.Db.SysResource.InsertAsync(dto.SysResource, tran);

                    //path
                    string path = "";
                    if (dto.SysResource.ParentId > 0)
                    {
                        var parentres = await _databaseFixture.Db.SysResource.FindAsync(m => m.ResourceId == dto.SysResource.ParentId);

                        if (parentres != null)
                        {
                            path = parentres.Path;
                        }
                    }
                    dto.SysResource.Path = path.IsNullOrEmpty() ? dto.SysResource.ResourceId.ToString() : path + ":" + dto.SysResource.ResourceId;
                    await _databaseFixture.Db.SysResource.UpdateAsync(dto.SysResource, tran);

                    #endregion

                    #region  钮添加

                    List <SysResource> list = new List <SysResource>();
                    var addbutton           = dto.ButtonDto.Where(m => m.ButtonType == m.ButtonModel).ToList();
                    foreach (var button in addbutton)
                    {
                        SysResource res = new SysResource()
                        {
                            IsButton     = 1,
                            CreateTime   = DateTime.Now.ToTimeStamp(),
                            SystemId     = dto.SysResource.SystemId,
                            ResourceName = button.Name,
                            ButtonType   = button.ButtonType,
                            ParentId     = dto.SysResource.ResourceId,
                            ButtonClass  = ((ButtonType)button.ButtonType).ToClass()
                        };
                        list.Add(res);
                    }
                    if (list.HasItems())
                    {
                        await _databaseFixture.Db.SysResource.BulkInsertAsync(list, tran);
                    }

                    #endregion

                    tran.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    _logJobs.ExceptionLog(dto.SysResource.CreateUserId, ex);
                    return(false);
                }
            }
        }