private int Assist(List <Teacher> TeacherNotInSamedept, List <Teacher> TeacherAssignedInTheSameDate, List <Exam> ExaminRoom, Session session, Room room)
 {
     foreach (var Teacher in TeacherNotInSamedept.OrderByDescending(t => t.Duties))
     {
         if (Teacher.TeacherRooms.Where(t => t.Session.Id == session.Id).Count() == 0 && Teacher.TeacherRooms.Where(t => t.Room.Id == room.Id).Count() == 0 && Teacher.TeacherPriority == 1)
         {
             //  if (!(TeacherAssignedInTheSameDate.Contains(Teacher)))
             // {
             int Count = Teacher.TeacherRooms.Count();
             if (Count < Teacher.Duties)
             {
                 TeacherRoom Tr1 = new TeacherRoom();
                 foreach (var exam in ExaminRoom)
                 {
                     Teacher.Exams.Add(exam);
                 }
                 Tr1.Session_Id = session.Id;
                 Tr1.Room_Id    = room.Id;
                 Tr1.Teacher_Id = Teacher.Id;
                 Teacher.TeacherRooms.Add(Tr1);
                 db.SaveChanges();
                 TeacherAssignedInTheSameDate.Add(Teacher);
                 return(0);
             }
             // }
         }
     }
     foreach (var Teacher in TeacherNotInSamedept.OrderByDescending(t => t.Duties))
     {
         if (Teacher.TeacherRooms.Where(t => t.Session.Id == session.Id).Count() == 0 && Teacher.TeacherPriority == 1)
         {
             //  if (!(TeacherAssignedInTheSameDate.Contains(Teacher)))
             // {
             int Count = Teacher.TeacherRooms.Count();
             if (Count < Teacher.Duties)
             {
                 TeacherRoom Tr1 = new TeacherRoom();
                 foreach (var exam in ExaminRoom)
                 {
                     Teacher.Exams.Add(exam);
                 }
                 Tr1.Session_Id = session.Id;
                 Tr1.Room_Id    = room.Id;
                 Tr1.Teacher_Id = Teacher.Id;
                 Teacher.TeacherRooms.Add(Tr1);
                 db.SaveChanges();
                 TeacherAssignedInTheSameDate.Add(Teacher);
                 return(0);
             }
             // }
         }
     }
     return(1);
 }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,Name,Sem,DepartmentId")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", student.DepartmentId);
            return(View(student));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,Name,Experience,Designation_Id,TeacherPriority,Department_Id")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                db.Teachers.Add(teacher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Department_Id  = new SelectList(db.Departments, "Id", "Name", teacher.Department_Id);
            ViewBag.Designation_Id = new SelectList(db.Designations, "Id", "Name", teacher.Designation_Id);
            return(View(teacher));
        }
Beispiel #4
0
 private void UpdateRoomStudents(Session session, Room room, Exam exam1, List <Student> stud1, int capacity)
 {
     for (int i = 0; i < capacity; i++)
     {
         RoomStudent temp = new RoomStudent
         {
             Exam    = exam1,
             Session = session,
             Student = stud1.First(),
             Room    = room
         };
         room.RoomStudents.Add(temp);
         if (room.Exams.Contains(exam1) == false)
         {
             room.Exams.Add(exam1);
         }
         db.SaveChanges();
         stud1.Remove(stud1.First());
     }
 }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] Stream stream)
        {
            try
            {
                int id = db.Streams.Max(x => x.Id);
                stream.Id = id + 1;
            }
            catch (InvalidOperationException)

            {
                stream.Id = 1;
            }
            if (ModelState.IsValid)
            {
                db.Streams.Add(stream);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(stream));
        }
Beispiel #6
0
        public ActionResult Create([Bind(Include = "No,Block,Capacity,Department_Id,RoomStatus")] Room room)
        {
            try
            {
                int id = db.Rooms.Max(x => x.Id);
                room.Id = id + 1;
            }
            catch (InvalidOperationException)
            {
                room.Id = 1;
            }
            if (ModelState.IsValid)
            {
                room.RoomStatus = 1;
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Department_Id = new SelectList(db.Departments, "Id", "Name", room.Department_Id);
            return(View(room));
        }
        public ActionResult Create([Bind(Include = "Id,Name,StreamId")] Department department)
        {
            try
            {
                int id = db.Departments.Max(x => x.Id);
                department.Id = id + 1;
            }
            catch (InvalidOperationException)

            {
                department.Id = 1;
            }
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StreamId = new SelectList(db.Streams, "Id", "Name", department.StreamId);
            return(View(department));
        }
Beispiel #8
0
        public ActionResult Create(string Name)
        {
            Session session = new Session();

            try
            {
                int id = db.Sessions.Max(x => x.Id);
                session.Id = id + 1;
            }
            catch (InvalidOperationException)
            {
                session.Id = 0;
            }
            session.Name = Name;
            if (ModelState.IsValid)
            {
                db.Sessions.Add(session);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(session));
        }
 public ActionResult Create([Bind(Include = "Code,ExamTime,Name,Date,Id")] Exam exam)
 {
     if (ModelState.IsValid)
     {
         string sessionNew = SessionHelper.CreateSession(exam);
         var    session    = db.Sessions.Where(s => s.Name == sessionNew).FirstOrDefault <Session>();
         if (session == null)
         {
             var createSession = new SessionHelper();
             createSession.AddSession(sessionNew);
             var newSession = db.Sessions.Where(s => s.Name == sessionNew).FirstOrDefault <Session>();
             exam.SessionId = newSession.Id;
         }
         else
         {
             exam.SessionId = session.Id;
         }
         db.Exams.Add(exam);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id = new SelectList(db.Departments, "Id", "Name", exam.Id);
     return(View(exam));
 }
        public Session AddSession(string Name)
        {
            Session session = new Session();

            try
            {
                int id = db.Sessions.Max(x => x.Id);
                session.Id = id + 1;
            }
            catch (InvalidOperationException)
            {
                session.Id = 0;
            }
            session.Name = Name;
            db.Sessions.Add(session);
            db.SaveChanges();
            return(session);
        }
        public JsonResult UploadExcel(Student students, HttpPostedFileBase FileUpload)
        {
            List <string> data = new List <string>();

            if (FileUpload != null)
            {
                // tdata.ExecuteCommand("truncate table OtherCompanyAssets");
                if (FileUpload.ContentType == "application/vnd.ms-excel" || FileUpload.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
                {
                    string filename   = FileUpload.FileName;
                    string targetpath = Server.MapPath("~/Doc/");
                    FileUpload.SaveAs(targetpath + filename);
                    string pathToExcelFile  = targetpath + filename;
                    var    connectionString = "";
                    if (filename.EndsWith(".xls"))
                    {
                        connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", pathToExcelFile);
                    }
                    else if (filename.EndsWith(".xlsx"))
                    {
                        connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", pathToExcelFile);
                    }

                    var adapter  = new OleDbDataAdapter("SELECT * FROM [Student$]", connectionString);
                    var adapter1 = new OleDbDataAdapter("SELECT * FROM [Room$]", connectionString);
                    var adapter2 = new OleDbDataAdapter("SELECT * FROM [Teacher$]", connectionString);
                    var ds       = new DataSet();
                    var ds1      = new DataSet();
                    var ds2      = new DataSet();

                    adapter.Fill(ds, "ExcelTable");
                    adapter1.Fill(ds1, "ExcelTable");
                    adapter2.Fill(ds2, "ExcelTable");

                    DataTable dtable  = ds.Tables["ExcelTable"];
                    DataTable dtable1 = ds1.Tables["ExcelTable"];
                    DataTable dtable2 = ds2.Tables["ExcelTable"];


                    string sheetName  = "Student";
                    string sheetName1 = "Room";
                    string sheetName2 = "Teacher";

                    var excelFile = new ExcelQueryFactory(pathToExcelFile);
                    var stud      = from a in excelFile.Worksheet <Student>(sheetName) select a;

                    foreach (var a in stud)
                    {
                        try
                        {
                            if (a.Name != "" && a.Id != "" && a.Sem != null && a.DepartmentId != null)
                            {
                                Student TU = new Student();
                                TU.Name         = a.Name;
                                TU.Id           = a.Id;
                                TU.Sem          = a.Sem;
                                TU.DepartmentId = a.DepartmentId;
                                db.Students.Add(TU);
                                db.SaveChanges();
                            }
                            else
                            {
                                data.Add("<ul>");
                                if (a.Name == "" || a.Name == null)
                                {
                                    data.Add("<li> name is required</li>");
                                }
                                if (a.Id == "" || a.Id == null)
                                {
                                    data.Add("<li> Id is required</li>");
                                }
                                if (a.Sem == null)
                                {
                                    data.Add("<li>Sem is required</li>");
                                }

                                data.Add("</ul>");
                                data.ToArray();
                                return(Json(data, JsonRequestBehavior.AllowGet));
                            }
                        }

                        catch (DbEntityValidationException ex)
                        {
                            foreach (var entityValidationErrors in ex.EntityValidationErrors)
                            {
                                foreach (var validationError in entityValidationErrors.ValidationErrors)
                                {
                                    Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                                }
                            }
                        }
                    }
                    var rooms = from b in excelFile.Worksheet <Room>(sheetName1) select b;

                    foreach (var b in rooms)
                    {
                        try
                        {
                            if (b.No != null && b.Block != "" && b.Department_Id != null && b.Capacity != null)
                            {
                                Room TU = new Room();
                                TU.Id            = b.Id;
                                TU.No            = b.No;
                                TU.Department_Id = b.Department_Id;
                                TU.Capacity      = b.Capacity;
                                TU.Block         = b.Block;
                                TU.RoomStatus    = b.RoomStatus;
                                db.Rooms.Add(TU);
                                db.SaveChanges();
                            }
                            else
                            {
                                data.Add("<ul>");
                                if (b.No == null)
                                {
                                    data.Add("<li> Number is required</li>");
                                }
                                if (b.Department_Id == null)
                                {
                                    data.Add("<li> deptId is required</li>");
                                }
                                if (b.Capacity == null)
                                {
                                    data.Add("<li>capacity is required</li>");
                                }
                                if (b.Block == "" || b.Block == null)
                                {
                                    data.Add("<li>Block is required</li>");
                                }

                                data.Add("</ul>");
                                data.ToArray();
                                return(Json(data, JsonRequestBehavior.AllowGet));
                            }
                        }

                        catch (DbEntityValidationException ex)
                        {
                            foreach (var entityValidationErrors in ex.EntityValidationErrors)
                            {
                                foreach (var validationError in entityValidationErrors.ValidationErrors)
                                {
                                    Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                                }
                            }
                        }
                    }

                    var teachers = from c in excelFile.Worksheet <Teacher>(sheetName2) select c;

                    foreach (var c in teachers)
                    {
                        try
                        {
                            if (c.Id != null && c.Name != "" && c.Duties != null && c.Designation_Id != null)
                            {
                                Teacher TU = new Teacher();
                                TU.Id              = c.Id;
                                TU.Name            = c.Name;
                                TU.Department_Id   = c.Department_Id;
                                TU.Designation_Id  = c.Designation_Id;
                                TU.Duties          = c.Duties;
                                TU.TeacherPriority = c.TeacherPriority;
                                db.Teachers.Add(TU);
                                db.SaveChanges();
                            }
                            else
                            {
                                data.Add("<ul>");
                                if (c.Id == null)
                                {
                                    data.Add("<li> ID is required</li>");
                                }
                                if (c.Name == null || c.Name == "")
                                {
                                    data.Add("<li> name is required</li>");
                                }
                                if (c.Designation_Id == null)
                                {
                                    data.Add("<li>designationid  is required</li>");
                                }
                                if (c.Duties == null)
                                {
                                    data.Add("<li>Experience is required</li>");
                                }


                                data.Add("</ul>");
                                data.ToArray();
                                return(Json(data, JsonRequestBehavior.AllowGet));
                            }
                        }

                        catch (DbEntityValidationException ex)
                        {
                            foreach (var entityValidationErrors in ex.EntityValidationErrors)
                            {
                                foreach (var validationError in entityValidationErrors.ValidationErrors)
                                {
                                    Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                                }
                            }
                        }
                    }
                    //deleting excel file from folder
                    if ((System.IO.File.Exists(pathToExcelFile)))
                    {
                        System.IO.File.Delete(pathToExcelFile);
                    }
                    return(Json("success", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //alert message for invalid file format
                    data.Add("<ul>");
                    data.Add("<li>Only Excel file format is allowed</li>");
                    data.Add("</ul>");
                    data.ToArray();
                    return(Json(data, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                data.Add("<ul>");
                if (FileUpload == null)
                {
                    data.Add("<li>Please choose Excel file</li>");
                }
                data.Add("</ul>");
                data.ToArray();
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }