using Dapper;
using Learun.DataBase.Repository;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace Learun.Application.TwoDevelopment.PersonnelManagement
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2020-01-04 15:23
/// 描 述:社团会员
///
public class CommunityMemberService : RepositoryFactory
{
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
public IEnumerable GetPageList(Pagination pagination, string queryJson, string stuNo)
{
try
{
var strSql = new StringBuilder();
strSql.Append("SELECT t.* ");
strSql.Append(" FROM CommunityMember t ");
strSql.Append(" WHERE 1=1 ");
var queryParam = queryJson.ToJObject();
// 虚拟参数
var dp = new DynamicParameters(new { });
if (!queryParam["CommunityId"].IsEmpty())
{
dp.Add("CommunityId", queryParam["CommunityId"].ToString(), DbType.String);
strSql.Append(" AND t.CommunityId = @CommunityId ");
}
if (!queryParam["StuName"].IsEmpty())
{
dp.Add("StuName", "%" + queryParam["StuName"].ToString() + "%", DbType.String);
strSql.Append(" AND t.StuName like @StuName ");
}
if (!stuNo.IsEmpty())
{
dp.Add("StuNo", stuNo.ToString(), DbType.String);
strSql.Append(" AND t.StuNo = @StuNo ");
}
return this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), dp, pagination);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取页面显示列表数据
///
/// 查询参数
///
public IEnumerable GetList(string communityId)
{
try
{
var strSql = new StringBuilder();
var dp = new DynamicParameters(new { });
strSql.Append("SELECT t.* FROM CommunityMember t WHERE 1=1 ");
// 虚拟参数
if (!communityId.IsEmpty())
{
dp.Add("communityId", communityId.ToString(), DbType.String);
strSql.Append(" AND t.CommunityId = @communityId ");
}
return this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), dp);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 获取CommunityMember表实体数据
/// 主键
///
///
public CommunityMemberEntity GetCommunityMemberEntity(string keyValue)
{
try
{
return this.BaseRepository("CollegeMIS").FindEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
public void DeleteEntity(string keyValue)
{
try
{
this.BaseRepository("CollegeMIS").Delete(t => t.Id == keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
public void SaveEntity(string keyValue, CommunityMemberEntity entity)
{
try
{
var model = this.BaseRepository("CollegeMIS").FindEntity(x => x.CommunityId == entity.CommunityId && x.StuNo == entity.StuNo);
if (!string.IsNullOrEmpty(keyValue))
{
if (model == null || (model != null && model.Id == keyValue))
{
entity.Modify(keyValue);
this.BaseRepository("CollegeMIS").Update(entity);
}
}
else
{
if (model == null)
{
entity.Create();
this.BaseRepository("CollegeMIS").Insert(entity);
}
}
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowServiceException(ex);
}
}
}
#endregion
}
}