龙空技术网

NET+EF+MVC中使用Contains方法

娱乐一分哥 242

前言:

而今兄弟们对“mvc中使用log4net”大约比较着重,同学们都需要剖析一些“mvc中使用log4net”的相关资讯。那么小编同时在网摘上网罗了一些关于“mvc中使用log4net””的相关内容,希望咱们能喜欢,大家一起来了解一下吧!

NET+EF+MVC开发时,比如数组里存储了一些ID的值,需要从数据库里查询数组里这些值存在的数据列表,看一下EF语句如何写(teacherlist.Contains(a.TeachersID)),下面给一个实例,以供参考:

public int KinderNoticeAddPost(gpt_KinderNotice model, decimal[] classid, decimal[] teacherlist)

{

#region 获取登录数据

decimal KindergartenID = loginModel.KindergartenID;

decimal TrialID = loginModel.TrialID;

int AccountLevel = loginModel.AccountLevel;

decimal adminUserid = loginModel.TeachersID;

string adminname = loginModel.Name;

#endregion 获取登录数据

int res = 0;

if (model != null)

{

if (model.NoticeType == 1)

{

model.Noticeobject = 1;

}

else if (model.NoticeType == 0)

{

model.ClassIdList = "";

model.ClassNameList = "";

}

TransactionOptions transactionOption = new TransactionOptions();

//设置事务隔离级别

transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;

// 设置事务超时时间为60秒

transactionOption.Timeout = new TimeSpan(0, 1, 30);

using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, transactionOption)) //需要事务回滚的地方外面套一层using (TransactionScope sc = new TransactionScope()){}

{

try

{

decimal KinderNoticeID = WisdomStarts.Common.Utils.GenerateIntID();

model.KinderNoticeID = KinderNoticeID;

model.KindergartenID = KindergartenID;

model.TrialID = TrialID;

model.NoticeTime = DateTime.Now;

model.adminUserid = adminUserid;

model.adminname = adminname;

model.IsDel = 0;

ef.gpt_KinderNotice.Add(model);

res = ef.SaveChanges();

if (res > 0)

{

#region NoticeType0通知,1是公告, 生成明细 Noticeobject:2通知所有教师,3通知所有家长,4园区全部通知

if (model.NoticeType == 0 && (model.Noticeobject == 2 || model.Noticeobject == 4))

{

if (teacherlist!=null && teacherlist.Length > 0)

{

List<gpt_KinderNotice_IsRead> readlist = new List<gpt_KinderNotice_IsRead>();

#region 通知教师和园长

List<gpt_Teachers> teacherlist1 = ef.gpt_Teachers.Where(a => a.AccountStatus == 0 && a.TrialID == TrialID && a.KindergartenID == KindergartenID && teacherlist.Contains(a.TeachersID)).AsNoTracking().ToList();

foreach (var item in teacherlist1)

{

//ReturnPushInfo m = new ReturnPushInfo();

M_android_content m = new M_android_content();

m.KinderNoticeID = KinderNoticeID.ToString();

m.TeachersID = item.TeachersID.ToString();

m.KindergartenID = model.KindergartenID.ToString();

m.TrialID = model.TrialID.ToString();

if (item.AccountLevel == 1)

{

m.parapagetype = ((int)WisdomStarts.Common.Enums.EnumClass.DirectorPageAction.园区通知).ToString();

}

else

{

m.parapagetype = ((int)WisdomStarts.Common.Enums.EnumClass.TeacherPageAction.园区通知).ToString();

}

string title = "园区通知";

string subtitle = "园区通知";

string text = "您有一条园区通知,请注意查收!";

if (item.AccountLevel == 1)

{

// new WisdomStars.Bll.Common.UMeng().PushDirector(m, (int)WisdomStarts.Common.Enums.EnumClass.DirectorPageAction.园区通知, item.client, item.mobiletoken, title, subtitle, text);

PushDirector(m, (int)WisdomStarts.Common.Enums.EnumClass.DirectorPageAction.园区通知, item.client, item.mobiletoken, title, subtitle, text);

}

else

{

//new WisdomStars.Bll.Common.UMeng().PushTeacher(m, (int)WisdomStarts.Common.Enums.EnumClass.TeacherPageAction.园区通知, item.client, item.mobiletoken, title, subtitle, text);

PushTeacher(m, (int)WisdomStarts.Common.Enums.EnumClass.TeacherPageAction.园区通知, item.client, item.mobiletoken, title, subtitle, text);

}

decimal KN_IsReadID = WisdomStarts.Common.Utils.GenerateIntID();

gpt_KinderNotice_IsRead Readmodel = new gpt_KinderNotice_IsRead();

Readmodel.KN_IsReadID = KN_IsReadID;

Readmodel.KinderNoticeID = model.KinderNoticeID;

Readmodel.NewEnrolmentID = 0;

Readmodel.visitorid = item.TeachersID;

Readmodel.visitortype = 1; //0:家长 1:教师

Readmodel.visitorName = item.Name + "老师";

Readmodel.IsRead = 0;

readlist.Add(Readmodel);

}

ef.BulkInsert(readlist);

#endregion

}

}

if (model.NoticeType != 2)

{

if (classid!=null && classid.Length > 0)

{

for (var i = 0; i < classid.Length; i++)

{

string classid_value = DNTRequest.GetString("classid_" + classid[i]);

if (!string.IsNullOrEmpty(classid_value))

{

string[] babystringarray = classid_value.Split(',');

//转换方法-继续简写

decimal[] babyarray = Array.ConvertAll(babystringarray, decimal.Parse);

List<gpt_KinderNotice_IsRead> readlist2 = new List<gpt_KinderNotice_IsRead>();

#region 通知家长

List<V_Kinder_NewEnrolment_ParentLogin> babylist = ef.V_Kinder_NewEnrolment_ParentLogin.Where(a => a.Cadetstatus == 1 && a.TrialID == TrialID && a.KindergartenID == KindergartenID && babyarray.Contains(a.NewEnrolmentID)).AsNoTracking().ToList();

foreach (var item in babylist)

{

M_android_content m = new M_android_content();

m.KinderNoticeID = KinderNoticeID.ToString();

m.NewEnrolmentID = item.NewEnrolmentID.ToString();

m.ParentloginID = item.ParentloginID.ToString();

m.Kinder_Class_ID = item.Kinder_Class_ID.ToString();

m.KindergartenID = model.KindergartenID.ToString();

m.TrialID = model.TrialID.ToString();

m.parapagetype = ((int)WisdomStarts.Common.Enums.EnumClass.ParentPageAction.园区通知).ToString();

string title = "园区通知";

string subtitle = "园区通知";

string text = "您有一条园区通知,请注意查收!";

PushParent(m, (int)WisdomStarts.Common.Enums.EnumClass.ParentPageAction.园区通知, item.client, item.mobiletoken, title, subtitle, text);

decimal KN_IsReadID = WisdomStarts.Common.Utils.GenerateIntID();

gpt_KinderNotice_IsRead Readmodel = new gpt_KinderNotice_IsRead();

Readmodel.KN_IsReadID = KN_IsReadID;

Readmodel.KinderNoticeID = model.KinderNoticeID;

Readmodel.NewEnrolmentID = item.NewEnrolmentID;

Readmodel.visitorid = item.ParentloginID;

Readmodel.visitortype = 0; //0:家长 1:教师

Readmodel.visitorName = WisdomStarts.Common.Utils.GetParentName(item.GuardianType, item.BabyName);

Readmodel.IsRead = 0;

readlist2.Add(Readmodel);

}

#endregion

ef.BulkInsert(readlist2);

}

}

}

}

#endregion

ef.BulkSaveChanges();

trans.Complete();

}

}

catch (Exception ee)

{

WisdomStarts.Common.Log.NetLog.WriteTextLog("发布通知", ee.ToString());

res = 0;

trans.Dispose();

}

}

}

return res;

}

标签: #mvc中使用log4net