public ActionResult Create(Department department) { if (ModelState.IsValid) { db.Departments.Add(department); db.SaveChanges(); ViewBag.Message = department.Code + " has been saved into database."; return View(); } return View(department); }
public ActionResult ViewClassSchedualInformation(Department aDepartment) { ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code"); List<Course> courses = db.Courses.Where(c => c.DepartmentId == aDepartment.DepartmentId).ToList(); List<ClassRoomAllocation> classRoomAllocations = db.ClassRoomAllocations.ToList(); List<string> codes = new List<string>(); List<string> names = new List<string>(); List<string> scheduals = new List<string>(); foreach (Course course in courses) { string schedual = string.Empty; foreach (ClassRoomAllocation classRoomAllocation in classRoomAllocations) { int count = 0; if (classRoomAllocation.CourseId == course.CourseId) { if (count == 0) { schedual += "r.no: "; count++; } ClassRoom classRoom = (db.ClassRooms.Where(c => c.ClassRoomId == classRoomAllocation.ClassRoomId)).Single(); schedual += (classRoom.RoomNo + "," + classRoomAllocation.Day.Name + "," + classRoomAllocation.TimeFrom + "-" + classRoomAllocation.TimeTo+";"); } if (schedual == "r.no: ") schedual = string.Empty; } if (schedual != string.Empty) { codes.Add(course.Code); names.Add(course.Name); scheduals.Add(schedual); } } ViewBag.CourseCodes = codes; ViewBag.CourseNames = names; ViewBag.Scheduals = scheduals; return View(); }
public ActionResult Edit(Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(department); }