2017-04-15 3 views
0
내 프로젝트 시간 테이블 나는 현재이 기술을 배우고 대해 물어 것

그렇게 나에게ASP.Net MVC

이 이미지를 도와주세요 :

나는 각 필드에 대해이 표에서 원하는 데이터베이스에 추가 한 후 레이블 표시 :이 내 컨트롤러

입니다

0

using System.Data; 
using System.Data.Entity; 
using System.Linq; 
using System.Net; 
using System.Web.Mvc; 
using TimeTable2.Models; 
using System.Collections.Generic; 
using System; 

namespace TimeTable2.Controllers 
{ 
    public class TablesController : Controller 
    { 
     private table_systemEntities1 db = new table_systemEntities1(); 


     [HttpPost] 
     [ValidateAntiForgeryToken] 


     public ActionResult TheTables() 
     { 
      PopulateDepartmentsDropDownList(); 
      PopulateClassroomsDropDownList(); 
      PopulateCoursesDropDownList(); 
      PopulateTeachersDropDownList(); 
      PopulateFacultiesDropDownList(); 
      PopulateLevelsDropDownList(); 

      return View(); 
     } 
     [HttpPost] 
     [ValidateAntiForgeryToken] 

     public JsonResult TheTables([Bind(Include = "TabelsID,TeacherID,CourseID,LevelID,DepartmentID,ClassRoomID,TimesID,DaysID,Years,Semester,Measure")] Tabels tabels) 
     { 
      try 
      { 
       if (ModelState.IsValid) 
       { 
        db.Tabels.Add(tabels); 
        db.SaveChanges(); 
       } 
      } 
      catch (DataException /* dex */) 
      { 
       ModelState.AddModelError("", "Unable to save changes. Try again ."); 
      } 
      ViewBag.ClassRoomID = new SelectList(db.Class_Room, "ClassRoomID", "Name", tabels.ClassRoomID); 
      ViewBag.DaysID = new SelectList(db.Days, "DayID", "Name", tabels.DaysID); 
      ViewBag.LevelID = new SelectList(db.Level, "LevelID", "Name", tabels.LevelID); 
      ViewBag.TeacherID = new SelectList(db.Teacher, "TeacherID", "Name", tabels.TeacherID); 
      ViewBag.TimesID = new SelectList(db.Times, "TimesID", "Name", tabels.DaysID); 
      ViewBag.CourseID = new SelectList(db.Course, "CourseID", "Name", tabels.CourseID); 
      ViewBag.FacultyID = new SelectList(db.Faculty, "FacultyID", "Name", tabels.FacultyID); 
      ViewBag.DepartmentID = new SelectList(db.Department, "DepartmentID", "Name", tabels.DepartmentID); 
      ViewBag.LevelID = new SelectList(db.Level, "LevelID", "Name", tabels.LevelID); 


      return Json(tabels, JsonRequestBehavior.AllowGet); 

     } 

     public ActionResult DetailsofTable() 
     { 

      PopulateDepartmentsDropDownList(); 
      PopulateClassroomsDropDownList(); 
      PopulateCoursesDropDownList(); 
      PopulateTeachersDropDownList(); 
      PopulateFacultiesDropDownList(); 
      PopulateLevelsDropDownList(); 


      return View(); 
     } 
     public ActionResult CreateTheTable() 
     { 

      PopulateDepartmentsDropDownList(); 
      PopulateClassroomsDropDownList(); 
      PopulateCoursesDropDownList(); 
      PopulateTeachersDropDownList(); 
      PopulateFacultiesDropDownList(); 
      PopulateLevelsDropDownList(); 

      return View(); 
     } 
     public JsonResult GetDepartmentById(int ID) 
     { 
      db.Configuration.ProxyCreationEnabled = false; 
      return Json(db.Department.Where(p => p.FacultyID == ID), JsonRequestBehavior.AllowGet); 
     } 
     public JsonResult GetTeacherById(int ID) 
     { 
      db.Configuration.ProxyCreationEnabled = false; 
      return Json(db.Teacher_Course.Where(p => p.CourseID == ID), JsonRequestBehavior.AllowGet); 
     } 
     public JsonResult GetFacultyById(int ID) 
     { 
      db.Configuration.ProxyCreationEnabled = false; 
      return Json(db.Class_Room.Where(p => p.ClassRoomID == ID), JsonRequestBehavior.AllowGet); 
     } 
     public JsonResult GetCoursesById(int ID) 
     { 
      db.Configuration.ProxyCreationEnabled = false; 
      return Json(db.Teacher_Course.Where(p => p.DepartmentID == ID), JsonRequestBehavior.AllowGet); 
     } 

     private void PopulateDepartmentsDropDownList(object selectedDepartment = null) 
     { 
      var departmentsQuery = from d in db.Department 
            orderby d.Name 
            select d; 
      ViewBag.DepartmentID = new SelectList(departmentsQuery, "DepartmentID", "Name", selectedDepartment); 
     } 
     private void PopulateClassroomsDropDownList(object selectedClassRooms = null) 
     { 
      var classroomsQuery = from d in db.Class_Room 
            orderby d.Name 
            select d; 
      ViewBag.ClassRoomID = new SelectList(classroomsQuery, "ClassRoomID", "Name", selectedClassRooms); 
     } 
     private void PopulateCoursesDropDownList(object selectedCourses = null) 
     { 
      var coursesQuery = from d in db.Course 
            orderby d.Name 
            select d; 
      ViewBag.CourseID = new SelectList(coursesQuery, "CourseID", "Name", selectedCourses); 
     } 
     private void PopulateTeachersDropDownList(object selectedTeachers = null) 
     { 
      var teacherQuery = from d in db.Teacher 
            orderby d.Name 
            select d; 
      ViewBag.TeacherID = new SelectList(teacherQuery, "TeacherID", "Name", selectedTeachers); 
     } 
     private void PopulateFacultiesDropDownList(object selectedFaculties = null) 
     { 
      var facultyQuery = from d in db.Faculty 
           orderby d.Name 
           select d; 
      ViewBag.FacultyID = new SelectList(facultyQuery, "FacultyID", "Name", selectedFaculties); 
     } 
     private void PopulateLevelsDropDownList(object selectedLevels = null) 
     { 
      var levelQuery = from d in db.Level 
           orderby d.Name 
           select d; 
      ViewBag.LevelID = new SelectList(levelQuery, "LevelID", "Name", selectedLevels); 
     } 
     protected override void Dispose(bool disposing) 
     { 
      if (disposing) 
      { 
       db.Dispose(); 
      } 
      base.Dispose(disposing); 
     } 
    } 
} 

그래서 어떻게 내가보기 엔 당신이 EntityFramework를 사용하는 것이 좋습니다

미안 영어

답변

1

말할 수 같은 시간에 데이터베이스에서 하나 개 이상의 필드를 저장할 수 있습니다, 당신은 here에 대해 읽을 수 있습니다. 예제 사용법 here. 당신은 그것을 매우 빨리 설정할 수 있고 많은 가이드가 있습니다.

길을 걷는 방법을 잘 모르는 사람.

0

Entity Framework에서 여러 행을 삽입하려면 AddRange을 사용할 수 있습니다.

db.Tabels.AddRange(tabels); 

확인하시기 바랍니다 AddRange

는 희망이 도움이!