public ActionResult ApplyForHostel(int id, int idd, Hostel model) { var student = db.Students.Where(c => c.StudentId == idd).SingleOrDefault(); var collection = db.Hostels.Where(c => c.HostelId == id).SingleOrDefault(); var HostelRel = new StudentHostelRelation { HostelId = id, StudentId = student.StudentId, }; db.StudentHostelRelations.Add(HostelRel); db.SaveChanges(); return(RedirectToAction("StudentsList3")); }
public ActionResult ApplyForHostel(int id, Hostel model) { var user = UserManager.FindById(User.Identity.GetUserId()); var student = db.Students.Where(c => c.UserId == user.Id).SingleOrDefault(); var collection = db.Hostels.Where(c => c.HostelId == id).SingleOrDefault(); if (db.StudentHostelRelations.Any(c => c.StudentId == student.StudentId)) { return(RedirectToAction("AppliedHostel")); } var HostelRel = new StudentHostelRelation { HostelId = id, StudentId = student.StudentId, }; db.StudentHostelRelations.Add(HostelRel); db.SaveChanges(); return(RedirectToAction("AppliedHostel")); }