Exemplo n.º 1
0
        public async Task RemoveWallpaperAsync(Int32 userId, Int32 wallpaperId)
        {
            Check.IfNullOrZero(userId);
            Check.IfNullOrZero(wallpaperId);

            await Task.Run(() =>
            {
                using var mapper = EntityMapper.CreateMapper();
                try
                {
                    #region 前置条件验证
                    {
                        var result = mapper.Query <Config>().Where(a => a.UserId == userId && a.WallpaperId == wallpaperId).Count();
                        if (result > 0)
                        {
                            throw new BusinessException("当前壁纸正在使用中,不能删除");
                        }
                    }
                    #endregion

                    #region 移除壁纸
                    {
                        var wallpaper = new Wallpaper();
                        wallpaper.Remove();
                        var result = mapper.Update(wallpaper, wa => wa.Id == wallpaperId && wa.UserId == userId);
                        if (!result)
                        {
                            throw new BusinessException("移除壁纸失败");
                        }
                    }
                    #endregion
                }
                catch (System.Exception)
                {
                    throw;
                }
            });
        }