112 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Learun.Util;
using Learun.Util.SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Learun.Application.AppMagager
{
/// <summary>
/// 版 本 PIT-ADMS V7.0.3 敏捷开发框架
/// Copyright (c) 2013-2018 Hexagon PPM
/// 创 建:超级管理员
/// 日 期2018-06-26 10:32
/// 描 述:我的常用移动应用
/// </summary>
public class MyFunctionService
{
#region
Repository<MyFunctionEntity> _myFunctionRepository => new Repository<MyFunctionEntity>();
#endregion
#region
private string fieldSql;
public MyFunctionService()
{
fieldSql = @"
t.F_Id,
t.F_UserId,
t.F_FunctionId,
t.F_Sort
";
}
#endregion
#region
/// <summary>
/// 获取列表数据
/// </summary>
/// <param name="userId">用户主键ID</param>
/// <returns></returns>
public IEnumerable<MyFunctionEntity> GetList(string userId)
{
try
{
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<MyFunctionEntity>(strSql.ToString(),new { userId });
return SqlSugarHelper.Db.SqlQueryable<MyFunctionEntity>(strSql.ToString()).AddParameters(new { userId }).ToList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region
/// <summary>
/// 保存实体数据(新增、修改)
/// <param name="keyValue">主键</param>
/// <summary>
/// <returns></returns>
public void SaveEntity(string userId,string strFunctionId)
{
//var db = this.BaseRepository().BeginTrans();
SqlSugarHelper.Db.BeginTran();
try
{
string[] functionIds = strFunctionId.Split(',');
_myFunctionRepository.Delete(t=>t.F_UserId.Equals(userId));
int num = 0;
foreach (var functionId in functionIds) {
MyFunctionEntity entity = new MyFunctionEntity();
entity.Create();
entity.F_UserId = userId;
entity.F_FunctionId = functionId;
entity.F_Sort = num;
_myFunctionRepository.Insert(entity);
num++;
}
//db.Commit();
SqlSugarHelper.Db.CommitTran();
}
catch (Exception ex)
{
//db.Rollback();
SqlSugarHelper.Db.RollbackTran();
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}