using learun.iapplication;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace learun.application
{
///
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2020.04.07
/// 描 述:我的常用移动应用
///
public class MyFunctionService : ServiceBase
{
#region 构造函数和属性
private readonly string fieldSql;
///
///
///
public MyFunctionService()
{
fieldSql = @"
t.F_Id,
t.F_UserId,
t.F_FunctionId,
t.F_Sort
";
}
#endregion 构造函数和属性
#region 获取数据
///
/// 获取列表数据
///
/// 用户主键ID
///
public Task> GetList(string userId)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(fieldSql);
strSql.Append(" FROM LR_App_MyFunction t where t.F_UserId = @userId Order by t.F_Sort ");
return this.BaseRepository().FindList(strSql.ToString(), new { userId });
}
#endregion 获取数据
#region 提交数据
///
/// 保存数据
///
/// 用户id
/// 功能id
///
public async Task SaveEntity(string userId, string strFunctionId)
{
var db = this.BaseRepository().BeginTrans();
try
{
string[] functionIds = strFunctionId.Split(',');
await db.DeleteAny(new { F_UserId = userId });
int num = 0;
foreach (var functionId in functionIds)
{
MyFunctionEntity entity = new MyFunctionEntity
{
F_Id = Guid.NewGuid().ToString(),
F_UserId = userId,
F_FunctionId = functionId,
F_Sort = num
};
await db.Insert(entity);
num++;
}
db.Commit();
}
catch (Exception)
{
db.Rollback();
throw;
}
}
#endregion 提交数据
}
}