public List <string> SendRequest(int ma) { var user = (from u in db.AppUsers join c in db.tbl_CV on u.Ma_CV equals c.Ma_CV select new { FullName = u.FullName, UserName = u.UserName, Display = c.Display, Ma_CV = c.Ma_CV, Ma_BP = u.Ma_BP, Ma_TO = u.Ma_TO, }); var tbl = db.tbl_Daily.Find(ma); var Sender = user.Where(m => m.UserName == HttpContext.Current.User.Identity.Name).FirstOrDefault(); List <string> Received; if (Sender.Display > 2) { Received = user.Where(m => m.Ma_BP == Sender.Ma_BP && m.Display > 3).Select(m => m.UserName).ToList(); tbl.Status_Autho2 = true; tbl.Status_Autho3 = true; } else { Received = user.Where(m => m.Display > 2 && m.Ma_TO == Sender.Ma_TO).Select(m => m.UserName).ToList(); tbl.Status_Autho1 = true; } List <tbl_Notifications> messenges = new List <tbl_Notifications>(); for (var i = 0; i < Received.Count(); i++) { messenges.Add(new tbl_Notifications { SendId = Sender.UserName, ReceiveId = Received[i], Status = true, Date = DateTime.Now, Url = "/Daily/Dailys/Detail?ma=" + ma.ToString(), Notification = "Nhật ký công việc ngày " + tbl.Date.ToString("dd/MM/yyyy") + " " + user.Where(m => m.UserName == tbl.UserName).FirstOrDefault().FullName, }); } db.tbl_Notifications.AddRange(messenges); db.SaveChanges(); return(Received); }