143 lines
5.4 KiB
C#
143 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Base;
|
|
using WX.CRM.Model.Entity;
|
|
namespace WX.CRM.BLL.Base
|
|
{
|
|
public class BAS_DAILYMEMU_BL : IBAS_DAILYMEMU, IBAS_DAILYMEMU_Q
|
|
{
|
|
#region 添加
|
|
/// <summary>
|
|
/// 添加
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public bool Create(ref ValidationErrors errors, string menuIds, decimal userId)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
SEQUENCES_BL sequences = new SEQUENCES_BL();
|
|
decimal[] MenuIdList = OperationUtil.ConvertToDecimal(menuIds.Split(','));
|
|
decimal[] hasMenuList = db.BAS_DAILYMEMU.Where(m => m.INNERUSERID == userId && MenuIdList.Contains(m.MENUID)).Select(m => m.MENUID).ToArray();
|
|
decimal[] MenuIdList2 = MenuIdList.Where(m => !hasMenuList.Contains(m)).ToArray();
|
|
decimal? max = db.BAS_DAILYMEMU.Where(m => m.INNERUSERID == userId).Max(m => m.SORTID);
|
|
max = max == null ? 0 : max;
|
|
foreach (decimal memuId in MenuIdList2)//添加没有数据
|
|
{
|
|
max++;
|
|
BAS_DAILYMEMU entry = new BAS_DAILYMEMU();
|
|
entry.INNERUSERID = userId;
|
|
entry.MENUID = memuId;
|
|
entry.SORTID = max;
|
|
entry.CTIME = DateTime.Now;
|
|
entry.CREATEUSER = userId;
|
|
entry.PKID = sequences.Seq_base_get();
|
|
db.BAS_DAILYMEMU.Add(entry);
|
|
}
|
|
List<BAS_DAILYMEMU> dailyMemu = db.BAS_DAILYMEMU.Where(m => m.INNERUSERID == userId && !MenuIdList.Contains(m.MENUID)).ToList();//移除 取消选中的 菜单记录
|
|
foreach (BAS_DAILYMEMU item in dailyMemu)
|
|
{
|
|
db.BAS_DAILYMEMU.Remove(item);
|
|
}
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 排序
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="errors">错误信息</param>
|
|
/// <param name="SortIds">格式:pkid,sorid;pkid,sorid</param>
|
|
/// <returns></returns>
|
|
public bool Sort(ref ValidationErrors errors, string SortIds)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
string[] Sorts = SortIds.Split(';');
|
|
foreach (string item in Sorts)
|
|
{
|
|
decimal[] ids = OperationUtil.ConvertToDecimal(item.Split(','));
|
|
decimal pkid = ids[0];
|
|
WX.CRM.Model.Entity.BAS_DAILYMEMU entry = db.BAS_DAILYMEMU.FirstOrDefault(m => m.PKID == pkid);
|
|
if (entry != null)
|
|
entry.SORTID = ids[1];
|
|
}
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public bool Delete(ref ValidationErrors errors, decimal id)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
WX.CRM.Model.Entity.BAS_DAILYMEMU entry = db.BAS_DAILYMEMU.FirstOrDefault(m => m.PKID == id);
|
|
if (entry == null)
|
|
{
|
|
errors.Add("数据已经被删除!");
|
|
return false;
|
|
}
|
|
db.BAS_DAILYMEMU.Remove(entry);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
#endregion
|
|
|
|
#region 获取单条信息
|
|
/// <summary>
|
|
/// 获取实体
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public WX.CRM.Model.Entity.BAS_DAILYMEMU GetModel(decimal id)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
WX.CRM.Model.Entity.BAS_DAILYMEMU entry = db.BAS_DAILYMEMU.FirstOrDefault(m => m.PKID == id);
|
|
return entry;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取分页数据列表
|
|
public List<WX.CRM.Model.Entity.BAS_DAILYMEMU> GetList(decimal userId)
|
|
{
|
|
using (var db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
var queryData = db.BAS_DAILYMEMU.Where(m => m.INNERUSERID == userId).AsQueryable();
|
|
queryData = queryData.OrderBy(m => m.SORTID);
|
|
return queryData.ToList();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|