void _DelHomeworks(Homework item) { var data2 = from a in noteCatDB.NoteCats.ToList() where a.NoteNo == item.NoteNo select a; var data3 = from a in noteClassDB.NoteClasses.ToList() where a.NoteId == item.NoteNo select a; var data4 = from a in commentDB.Comments.ToList() where a.ParentNo == item.NoteNo select a; foreach (var item2 in data2) { noteCatDB.NoteCats.Remove(item2); } foreach (var item2 in data3) { noteClassDB.NoteClasses.Remove(item2); } foreach (var item2 in data4) { commentDB.Comments.Remove(item2); } _context.Homework.Remove(item); _context.SaveChanges(); noteCatDB.SaveChanges(); noteClassDB.SaveChanges(); commentDB.SaveChanges(); }
public ActionResult Create([Bind(Include = "NoteNo,Subject,T_Name,Contents,Title,Date")] Homework homework, string[] checkbox, string[] checkbox2) { try { if (!Authen.Certification(Session["UserClass"].ToString(), Authen.UserClass.Teacher)) { return(RedirectToAction("PermitionEr", "Error")); } if (ModelState.IsValid) { homework.T_Name = Session["UserName"].ToString(); db.Homework.Add(homework); db.SaveChanges(); for (int i = 0; i < checkbox.Length; i++) { db3.NoteCat.Add(new NoteCat() { NoteNo = homework.NoteNo, CatAttribute = checkbox[i] }); Noti(checkbox[i], homework); } for (int i = 0; i < checkbox2.Length; i++) { db5.NoteClass.Add(new NoteClass { NoteId = homework.NoteNo, NoteClasses = int.Parse(checkbox2[i]) }); } db5.SaveChanges(); db3.SaveChanges(); } return(Redirect("~/homework")); } catch (FirebaseException e) { return(Redirect("~/Error/CustomEr/" + e.Message)); } catch { return(RedirectToAction("LoginEr", "Error")); } }
public ActionResult Create([Bind(Include = "NoteNo,Subject,T_Name,Contents,Title,Date")] Homework homework, string[] checkbox) { try { if (!Authen.Certification(Session["UserClass"].ToString(), Authen.UserClass.Teacher)) { return(RedirectToAction("PermitionEr", "Error")); } if (ModelState.IsValid) { homework.T_Name = Session["UserName"].ToString(); db.Homework.Add(homework); db.SaveChanges(); for (int i = 0; i < checkbox.Length; i++) { db3.NoteCat.Add(new NoteCat() { NoteNo = homework.NoteNo, CatAttribute = checkbox[i] }); } db3.SaveChanges(); /*Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); * IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse("110.10.38.94"), 1503); * client.Connect(iPEndPoint); * return RedirectToAction("Index");*/ } return(Redirect("~/homework")); } catch { return(RedirectToAction("LoginEr", "Error")); } }