|
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
-
- namespace Learun.Application.CRM
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创 建:超级管理员
- /// 日 期:2017-07-11 09:43
- /// 描 述:客户管理
- /// </summary>
- public class CrmCustomerService : RepositoryFactory
- {
- #region 获取数据
- /// <summary>
- /// 获取列表
- /// </summary>
- /// <returns></returns>
- public IEnumerable<CrmCustomerEntity> GetList()
- {
- try
- {
- return this.BaseRepository().FindList<CrmCustomerEntity>();
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取列表
- /// </summary>
- /// <param name="pagination">分页</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns>返回分页列表</returns>
- public IEnumerable<CrmCustomerEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var expression = LinqExtensions.True<CrmCustomerEntity>();
- var queryParam = queryJson.ToJObject();
- //查询条件
- if (!queryParam["keyword"].IsEmpty())
- {
- string keyword = queryParam["keyword"].ToString();
- expression = expression.And(t => t.F_EnCode.Contains(keyword) || t.F_FullName.Contains(keyword) || t.F_Contact.Contains(keyword) || t.F_TraceUserName.Contains(keyword));
- }
- return this.BaseRepository().FindList(expression, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取实体
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <returns></returns>
- public CrmCustomerEntity GetEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository().FindEntity<CrmCustomerEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 验证数据
- /// <summary>
- /// 客户名称不能重复
- /// </summary>
- /// <param name="fullName">名称</param>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public bool ExistFullName(string fullName, string keyValue)
- {
- try
- {
- var expression = LinqExtensions.True<CrmCustomerEntity>();
- expression = expression.And(t => t.F_FullName == fullName);
- if (!string.IsNullOrEmpty(keyValue))
- {
- expression = expression.And(t => t.F_CustomerId != keyValue);
- }
- return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 提交数据
- /// <summary>
- /// 删除数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
- try
- {
- db.Delete<CrmCustomerEntity>(t => t.F_CustomerId.Equals(keyValue));
- db.Delete<CrmTrailRecordEntity>(t => t.F_ObjectId.Equals(keyValue));
- db.Delete<CrmCustomerContactEntity>(t => t.F_CustomerId.Equals(keyValue));
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 保存表单(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键值</param>
- /// <param name="entity">实体对象</param>
- /// <returns></returns>
- public void SaveEntity(string keyValue, CrmCustomerEntity entity)
- {
- try
- {
- if (!string.IsNullOrEmpty(keyValue))
- {
- entity.Modify(keyValue);
- this.BaseRepository().Update(entity);
- }
- else
- {
- IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
- try
- {
- entity.Create();
- db.Insert(entity);
- db.Commit();
- }
- catch (Exception)
- {
- db.Rollback();
- throw;
- }
- }
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
-
-
- }
- #endregion
- }
- }
|