public ActionResult Edit([Bind(Include = "Id,DepartmentId,CourseId,RoomId,DayId,StartTime,EndTime,RoomStatus")] ClassRoomAllocation classroomallocation) { if (ModelState.IsValid) { db.Entry(classroomallocation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(db.Courses, "Id", "CourseCode", classroomallocation.CourseId); ViewBag.DayId = new SelectList(db.Days, "Id", "Name", classroomallocation.DayId); ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", classroomallocation.DepartmentId); ViewBag.RoomId = new SelectList(db.Rooms, "Id", "Name", classroomallocation.RoomId); return(View(classroomallocation)); }
public ActionResult Edit([Bind(Include = "Id,DepartmentId,CourseId,RoomNoId,DayNameId,From,To")] AllocateClassroom allocateClassroom) { if (ModelState.IsValid) { db.Entry(allocateClassroom).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(db.Courses, "Id", "Code", allocateClassroom.CourseId); ViewBag.DayNameId = new SelectList(db.DayNames, "Id", "Name", allocateClassroom.DayNameId); ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Code", allocateClassroom.DepartmentId); ViewBag.RoomNoId = new SelectList(db.RoomNos, "Id", "RoomNumber", allocateClassroom.RoomNoId); return(View(allocateClassroom)); }
public ActionResult Edit([Bind(Include = "AllocateClassRoomId,DepartmentId,CourseId,RoomId,DayId,StartTime,EndTime")] AllocateClassRoom allocateclassroom) { if (ModelState.IsValid) { db.Entry(allocateclassroom).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Code", allocateclassroom.CourseId); ViewBag.DayId = new SelectList(db.Days, "DayId", "TimeDay", allocateclassroom.DayId); ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", allocateclassroom.DepartmentId); ViewBag.RoomId = new SelectList(db.Rooms, "RoomId", "RoomNo", allocateclassroom.RoomId); return(View(allocateclassroom)); }
public ActionResult Edit(User model) { User UserAccess = new User(); if (UserAccess.Type == "Admin") { if (ModelState.IsValid) { User user = new User(); user = db.Users.Where(x => x.UserId == model.UserId).FirstOrDefault(); user.Address = model.Address; user.BatchId = model.BatchId; user.BatchName = model.BatchName; user.DepartmentId = model.DepartmentId; user.DepartmentName = model.DepartmentName; user.Email = model.Email; user.EPNumber = model.EPNumber; user.FacultyId = model.FacultyId; user.FacultyName = model.FacultyName; user.FirstName = model.FirstName; user.LastName = model.LastName; user.PhoneNumber = model.PhoneNumber; user.UniversityCard = model.UniversityCard; user.UserId = model.UserId; user.UserName = model.UserName; user.UserPassword = model.UserPassword; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("UserList", "User")); } } return(View()); }
public JsonResult UnAssignCourses(int noOfCourses) { var listOfCourseId = db.Courses.Where(c => c.CourseStatus == 1).Select(c => c.CourseId); using (var ctx = new UniversityDbContext()) { foreach (var acourseId in listOfCourseId) { Course selectedCors = new Course(); selectedCors = ctx.Courses.Where(id => id.CourseId == acourseId).Single(); selectedCors.CourseStatus = 0; ctx.Entry(selectedCors).State = EntityState.Modified; ctx.SaveChanges(); } } return(Json(true)); }
static void Main(string[] args) { UniversityDbContext db = new UniversityDbContext(); var departments = db.Departments.ToList(); foreach (var department in departments) { Console.WriteLine("Name: " + department.Name + " Code: " + department.Code); db.Entry(department) .Collection(c => c.Students) .Query() .Where(c => c.IsActive) .Load(); if (department.Students != null && department.Students.Any()) { foreach (var student in department.Students) { Console.WriteLine("\t\t " + student.Name); } } else { Console.WriteLine("\t\t No Student Found!"); } } var students = db.Students.Include(c => c.Department).ToList(); Console.ReadKey(); }
static void Main(string[] args) { //Student student = new Student() //{ // Name = "A", // RegNo="001" //}; //Department department = new Department() //{ // Name = "Computer Science", // Code = "CSE" //}; //department.Students.Add(student); //UniversityDbContext db = new UniversityDbContext(); //db.Departments.Add(department); //bool isSave = db.SaveChanges() > 0; //if (isSave) //{ // Console.WriteLine("SuccessFul!"); //} UniversityDbContext db = new UniversityDbContext(); // var departments = db.Departments.Include("Students").ToList(); //var departments = db.Departments.Include(c=>c.Students).ToList(); var departments = db.Departments.ToList(); foreach (var dept in departments) { Console.WriteLine(dept.Code + " - " + dept.Name); // db.Entry(dept).Collection(c => c.Students).Load(); db.Entry(dept) .Collection(c => c.Students) .Query() .Where(c => c.IsActive) .Load(); if (dept.Students != null && dept.Students.Any()) { foreach (var student in dept.Students) { Console.WriteLine("\t\t Name: " + student.Name); } } else { Console.WriteLine("\t\t No Student Found!"); } } Console.ReadKey(); }
public async Task UpdateAsync(TEntity entity) { _context.Entry(entity).State = EntityState.Modified; await _context.SaveChangesAsync(); }