public bool AddTask(List <int> listTask, int id) { try { WebDatabaseEntities database = new WebDatabaseEntities(); foreach (var i in listTask) { // check Intership đã có task truyên vào hay chưa var listT = database.IntershipWithTask.Where(x => x.InternshipID == id).ToList(); IntershipWithTask model = new IntershipWithTask(); if (listT == null) { model = null; } else { model = listT.SingleOrDefault(c => c.TaskID == i); } if (model == null) { IntershipWithTask addTask = new IntershipWithTask(); var count = database.IntershipWithTask.Count(); addTask.ID = count + 1; addTask.InternshipID = id; addTask.TaskID = i; var sort = database.IntershipWithTask.Where(x => x.InternshipID == id).Count(); addTask.Sort = sort + 1; database.IntershipWithTask.Add(addTask); database.SaveChanges(); } } return(true); } catch { return(false); } }
public bool AddTask(List <int> listTask, int id) { try { foreach (var i in listTask) { IntershipWithTask addTask = new IntershipWithTask(); var count = database.IntershipWithTask.Count(); addTask.ID = count + 1; addTask.InternshipID = id; addTask.TaskID = i; var sort = database.IntershipWithTask.Where(x => x.InternshipID == id).Count(); addTask.SORT = sort + 1; database.IntershipWithTask.Add(addTask); database.SaveChanges(); } return(true); } catch { return(false); } }