public ActionResult AddOrEdit(CommentMain c, FormCollection formCollection) { using (BusinessDataBaseEntities db = new BusinessDataBaseEntities()) { if (c.CommentMainID == 0) { int EmpID = EmployeeDetail.EmployeeID; int ccID = 102; ccID = Convert.ToInt32(formCollection["CommentContent"]); db.CommentMains.Add(new CommentMain() { CommentName = c.CommentName, SendTime = DateTime.Now, EmployeeID = EmpID, CommentContentID = ccID, CommentMainID = c.CommentMainID, }); db.SaveChanges(); return(Json(new { success = true, message = "調查發布成功" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(c).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "調查修改成功" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Delete(int id) { using (BusinessDataBaseEntities db = new BusinessDataBaseEntities()) { CommentMain c = db.CommentMains.Where(x => x.CommentMainID == id).FirstOrDefault <CommentMain>(); db.CommentMains.Remove(c); db.SaveChanges(); return(Json(new { success = true, message = "刪除成功" }, JsonRequestBehavior.AllowGet)); } }
//[ValidateAntiForgeryToken] public ActionResult Create(CommentMain c, int cid, string cname, string [] array) { using (BusinessDataBaseEntities db = new BusinessDataBaseEntities()) { int ccID = 101; ccID = cid; ArrayList question = new ArrayList(); var dup = db.CommentQuestions.Where(x => x.CommentContentID == ccID)/*.GroupBy(x => new { x.CommentContentID })*/ .Select(p => p); int countQ = 0; countQ = dup.Count(); //foreach (var x in dup) //{ //} var q2 = from cq in db.CommentQuestions where cq.CommentContentID == ccID select new { cq.CommentQuestionID }; var q3 = q2.ToList(); if (c.CommentMainID == 0) { int EmpID = EmployeeDetail.EmployeeID; db.CommentMains.Add(new CommentMain() { CommentName = cname, SendTime = DateTime.Now, EmployeeID = EmpID, //發布者 CommentContentID = ccID, //CommentMainID = c.CommentMainID, }); db.SaveChanges(); var getid = (from cc in db.CommentMains select cc.CommentMainID).Max(); for (int j = 0; j < array.Count(); j++) { for (int i = 0; i < countQ; i++) { //for (int j = 0; j < array.Count(); j++) //{ // for (int i = 0; i < q3.Count; i++) // { // db.CommentChilds.Add(new CommentChild() // { // CommentMainID = c.CommentMainID, // EmployeeID = int.Parse(array[j]), //接收者 // CommentQuestionID = q3[i].CommentQuestionID, // }); db.CommentChilds.Add(new CommentChild() { CommentMainID = getid, EmployeeID = int.Parse(array[j]), //接收者 CommentQuestionID = q3[i].CommentQuestionID, }); db.SaveChanges(); } } return(Json(new { success = true, message = "調查發布成功" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(c).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "調查修改成功" }, JsonRequestBehavior.AllowGet)); } } }