public void AddPackagesToCourse(int courseID, List <int> packageIDs) { //delete first //var lstToDelete = Entites.tblCoursePackages.Where(c => c.COURSE_ID == courseID).ToList(); //Entites.tblCoursePackages.RemoveRange(lstToDelete); //Entites.SaveChanges(); //adding foreach (var packageID in packageIDs) { Entites.tblCoursePackages.Add(new tblCoursePackage() { COURSE_ID = courseID, PACKAGE_ID = packageID }); } Entites.SaveChanges(); }
public void AddModulesToCourse(int courseID, List<int> moduleIDs) { //delete first var lstToDelete = Entites.tblCourseModules.Where(c => c.COURSE_ID == courseID).ToList(); Entites.tblCourseModules.RemoveRange(lstToDelete); Entites.SaveChanges(); //adding foreach (var moduleID in moduleIDs) { Entites.tblCourseModules.Add(new tblCourseModule() { COURSE_ID = courseID, MODULE_ID = moduleID }); } Entites.SaveChanges(); }
public string AddTopic(string name) { string error = string.Empty; try { Entites.tblTopics.Add(new tblTopic() { TOPIC_NAME = name }); Entites.SaveChanges(); } catch (Exception exc) { error = exc.ToString(); } return(error); }
public string AddModule(string name) { string error = string.Empty; try { Entites.tblModules.Add(new tblModule() { MODULE_NAME = name }); Entites.SaveChanges(); } catch (Exception exc) { error = exc.ToString(); } return(error); }
public int AddNewPackage(Models.Package package) { var newpackage = Entites.tblPackages.Add(new tblPackage() { PACKAGE_NAME = package.Name, PACKAGE_PRICE = package.Price, }); Entites.SaveChanges(); Entites.tblPackageModuleCounts.Add(new tblPackageModuleCount() { PACKAGE_ID = newpackage.PACKAGE_ID, MODULE_COUNT = package.ModuleCount }); Entites.SaveChanges(); return(newpackage.PACKAGE_ID); }
public void AddDefaultPackage(int courseID) { //var defaultPckgID = // Entites.tblPackages.Where(p => p.PACKAGE_NAME == "Full Package").SingleOrDefault().PACKAGE_ID; var fullPackageName = "Full Package"; var dnewPackage = new tblPackage(); dnewPackage.PACKAGE_NAME = fullPackageName; Entites.tblPackages.Add(dnewPackage); Entites.SaveChanges(); Entites.tblCoursePackages.Add(new tblCoursePackage() { PACKAGE_ID = dnewPackage.PACKAGE_ID, COURSE_ID = courseID }); Entites.SaveChanges(); }
public int AddCourse(string name) { int newCourseID = 0; string error = string.Empty; try { var newCourse = Entites.tblCourses.Add(new tblCourse() { COURSE_NAME = name, }); Entites.SaveChanges(); newCourseID = newCourse.COURSE_ID; } catch (Exception exc) { error = exc.ToString(); } return newCourseID; }
// GET: Home public ActionResult Index() { using (var aContext = new Entites()) { #region 乐观锁玩法 //var firstOrDefault = aContext.User.AsNoTracking().FirstOrDefault(); //firstOrDefault.Name = "小明"; //using (var bContext = new Entites()) //{ // var firstOrDefault2 = bContext.User.AsNoTracking().FirstOrDefault(); // firstOrDefault2.Name = "小红"; // bContext.Entry(firstOrDefault2).State = EntityState.Modified; // bContext.SaveChanges(); //} //try //{ // aContext.Entry(firstOrDefault).State = EntityState.Modified; // aContext.SaveChanges(); //} //catch (Exception exception) //{ // throw new Exception(exception.Message); //} #endregion #region 准备数据 Core.User.User user = new User() { Name = "小明", Address = new UserAddress() { City = "北京", DynamicAddress = "北京知春路" } }; user.Card = new UserCard() { IdCard = "19561816189161561" }; aContext.User.Add(user); Core.User.SuperUser superUser = new SuperUser() { Name = "超级小明", UserNum = "12346789", Address = new UserAddress() { City = "北京", DynamicAddress = "北京798艺术区" } }; aContext.User.Add(superUser); aContext.SaveChanges(); var firstuser = aContext.User.FirstOrDefault(); var superuser = aContext.SuperUser.FirstOrDefault(); #endregion } return(View()); }