public ActionResult Add(int cId, string bookName, string bookId, string bookAuthor, string Price, string Publisher, int Edition, string Reason, int bookCheck = 0) { //确定书籍书否存在,不存在则添加 T_TB_Books book = db.T_TB_Books.Find(bookId); if (bookId != null && book == null) { book = new T_TB_Books(); book.Id = bookId; book.Name = bookName; book.Author = bookAuthor; book.Price = Convert.ToDecimal(Price); book.Publisher = Publisher; book.Edition = Edition; db.T_TB_Books.Add(book); } //向教材选定表添加 T_TB_Choose choose = new T_TB_Choose(); choose.BookId = bookId; choose.TeachingTaskId = cId; choose.Reason = Reason; choose.State = 2; db.T_TB_Choose.Add(choose); //修改教学任务状态为已经填写 T_TB_TeachingTask task = db.T_TB_TeachingTask.Find(cId); task.State = 4; //添加老师预定书 if (bookCheck == 1) { T_TB_TeaYuding temp = new T_TB_TeaYuding(); temp.TeaId = (string)Session["Id"]; temp.BookId = bookId; temp.TaskId = cId; db.T_TB_TeaYuding.Add(temp); } db.SaveChanges(); return(RedirectToAction("GetLIst")); }
public ActionResult SaveEdit(int cId, string bookName, string bookId, string bookAuthor, string Price, string Publisher, int Edition, string Reason, int bookCheck = 0) { //确定书籍书否存在,不存在则添加,存在则修改信息 T_TB_Books book = db.T_TB_Books.Find(bookId); if (book == null) { book = new T_TB_Books(); book.Id = bookId; book.Name = bookName; book.Author = bookAuthor; book.Price = Convert.ToDecimal(Price); book.Publisher = Publisher; book.Edition = Edition; db.T_TB_Books.Add(book); } else { book.Name = bookName; book.Author = bookAuthor; book.Price = Convert.ToDecimal(Price); book.Publisher = Publisher; book.Edition = Edition; } //向教材选定表修改 T_TB_Choose choose = db.T_TB_Choose.Where(m => m.TeachingTaskId == cId).First(); choose.BookId = bookId; choose.Reason = Reason; //无库存、不通过状态编辑后,状态改变 choose.State = 2; //添加老师预定书修改 if (bookCheck == 0) { string teaId = (string)Session["Id"]; var query = db.T_TB_TeaYuding.Where(m => m.TeaId == teaId && m.TaskId == cId); if (query.Count() != 0) { db.T_TB_TeaYuding.Remove(query.First()); } } else if (bookCheck == 1) { string teaId = (string)Session["Id"]; var query = db.T_TB_TeaYuding.Where(m => m.TeaId == teaId && m.TaskId == cId); if (query.Count() == 0) { T_TB_TeaYuding temp = new T_TB_TeaYuding(); temp.TeaId = (string)Session["Id"]; temp.BookId = bookId; temp.TaskId = cId; db.T_TB_TeaYuding.Add(temp); } else { T_TB_TeaYuding temp = query.First(); temp.BookId = bookId; } } db.SaveChanges(); return(RedirectToAction("GetLIst")); }