Пример #1
0
        public ActionResult Create(ClassesViewModels collection)
        {
            try
            {
                if (HelperClass.account != "Admin")
                {
                    return(RedirectToAction("Index", "Home"));
                }
                DB37Entities db = new DB37Entities();
                if (db.Classtbls.Any(t => t.Section.Equals(collection.Name)))
                {
                    ViewBag.warn = "Class Already Exist";
                    return(View());
                }

                Classtbl c = new Classtbl();
                c.Section = collection.Name;
                db.Classtbls.Add(c);
                db.SaveChanges();
                return(RedirectToAction("Index", "Class"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult DisapproveLeaveRequests(int id)
        {
            try
            {
                DB37Entities db = new DB37Entities();

                foreach (Leavestbl ltbl in db.Leavestbls)
                {
                    if (ltbl.ParentId == id)
                    {
                        db.Leavestbls.Remove(ltbl);
                        break;
                    }
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            //int pid = db.Leavestbls.Find(id).ParentId;

            //SendDisapprovalMail(db.Parentstbls.Find(id).MailAddress);

            //db.Leavestbls.Find(id).ApprovalStatusId = db.ApprovalStatustbls.Where(t1 => t1.Name.Equals("approved")).FirstOrDefault().Id;
            //int pid = db.Leavestbls.Find(id).ParentId;
            //SendApprovalMail(db.Parentstbls.Find(pid).MailAddress);
            //db.SaveChanges();


            return(RedirectToAction("ViewLeaveRequests", "LeaveRequests"));
        }
        public ActionResult Edit(int id, EventViewModel eventObj)
        {
            try
            {
                if (HelperClass.account != "Admin")
                {
                    return(RedirectToAction("Index", "Home"));
                }
                DB37Entities db = new DB37Entities();

                db.SchoolEventstbls.Find(id).Title            = eventObj.name;
                db.SchoolEventstbls.Find(id).EventDescription = eventObj.description;
                db.SchoolEventstbls.Find(id).Contact          = eventObj.contact;
                db.SchoolEventstbls.Find(id).EventDate        = eventObj.date;
                db.SchoolEventstbls.Find(id).StartTime        = eventObj.startTime;
                db.SchoolEventstbls.Find(id).EndTime          = eventObj.endTime;
                db.SchoolEventstbls.Find(id).Charges          = eventObj.charges;

                db.SaveChanges();

                return(RedirectToAction("Index", "Events"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(EventViewModel obj)
        {
            try
            {
                if (HelperClass.account != "Admin")
                {
                    return(RedirectToAction("Index", "Home"));
                }
                // TODO: Add insert logic here
                DB37Entities db = new DB37Entities();

                SchoolEventstbl e1 = new SchoolEventstbl();
                e1.Title            = obj.name;
                e1.EventDescription = obj.description;
                e1.EventDate        = obj.date;
                e1.StartTime        = obj.startTime;
                e1.EndTime          = obj.endTime;
                e1.Contact          = obj.contact;
                e1.Charges          = obj.charges;

                db.SchoolEventstbls.Add(e1);
                db.SaveChanges();


                return(RedirectToAction("Index", "Events"));
            }
            catch (Exception ex)
            {
                throw (ex);
                //return View();
            }
        }
Пример #5
0
        public ActionResult ApproveRegistrationRequests(int id, int sid)
        {
            if (HelperClass.account != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }

            DB37Entities db = new DB37Entities();

            //int sid = db.ParentStudenttbls.Where(t => t.ParentId.Equals(id)).FirstOrDefault().StudentId;

            int i = 1;

            foreach (Studentstbl stbl in db.Studentstbls)
            {
                if (stbl.RegistrationNumber == "SSS-" + i.ToString())
                {
                    i++;
                }
            }

            string userName = db.Studentstbls.Find(sid).Username;

            db.Parentstbls.Find(id).ApprovalStatusId     = 2;
            db.Studentstbls.Find(sid).ApprovalStatusId   = 2;
            db.Studentstbls.Find(sid).RegistrationNumber = "SSS-" + i.ToString();
            int check = SendApprovalMail(db.Parentstbls.Find(id).MailAddress, "SSS-" + i.ToString(), userName);

            if (check == 0)
            {
                foreach (ParentStudenttbl pstbl in db.ParentStudenttbls)
                {
                    if (pstbl.ParentId == id)
                    {
                        db.ParentStudenttbls.Remove(pstbl);
                    }
                }


                foreach (Studentstbl stbl in db.Studentstbls)
                {
                    if (stbl.Id == sid)
                    {
                        db.Studentstbls.Remove(stbl);
                    }
                }

                foreach (Parentstbl ptbl in db.Parentstbls)
                {
                    if (ptbl.Id == id)
                    {
                        db.Parentstbls.Remove(ptbl);
                    }
                }
            }
            db.SaveChanges();

            return(RedirectToAction("ViewRegistrationRequests", "RegistrationRequests"));
        }
        // GET: Subject/Delete/5
        public ActionResult Delete(int id)
        {
            if (HelperClass.account != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }
            DB37Entities db = new DB37Entities();

            db.Subjectstbls.Remove(db.Subjectstbls.Where(t => t.Id == id).FirstOrDefault());
            db.SaveChanges();
            return(RedirectToAction("Index", "Subject"));
        }
Пример #7
0
        // GET: Class/Delete/5
        public ActionResult Delete(int id)
        {
            if (HelperClass.account != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }
            DB37Entities db = new DB37Entities();

            db.Classtbls.Remove(db.Classtbls.Find(id));
            db.SaveChanges();
            return(RedirectToAction("Index", "Class"));
        }
Пример #8
0
        // GET: TimeTable/Delete/5
        public ActionResult Delete(string classname, string subjectname, string dayname, string time)
        {
            CultureInfo  culture   = new CultureInfo("en-US");
            DateTime     tempDate  = Convert.ToDateTime("01/01/0001 " + time, culture);
            DB37Entities db        = new DB37Entities();
            int          classid   = db.Classtbls.Where(t => t.Section == classname).FirstOrDefault().Id;
            int          subjectid = db.Subjectstbls.Where(t => t.Name == subjectname).FirstOrDefault().Id;

            db.TimeTabletbls.Remove(db.TimeTabletbls.Where(t => t.ClassId == classid && t.SubjectId == subjectid && t.WeeksDay == dayname && t.LectureTime == tempDate.TimeOfDay).FirstOrDefault());
            db.SaveChanges();
            return(RedirectToAction("Index", "TimeTable"));
        }
        public ActionResult ApproveLeaveRequests(int id)
        {
            DB37Entities db = new DB37Entities();
            int          p  = db.ApprovalStatustbls.Where(t1 => t1.Name.Equals("approved")).FirstOrDefault().Id;

            db.Leavestbls.Where(t2 => t2.ParentId.Equals(id)).FirstOrDefault().ApprovalStatusId = db.ApprovalStatustbls.Where(t1 => t1.Name.Equals("approved")).FirstOrDefault().Id;
            //int pid = db.Leavestbls.Find(id).ParentId;
            SendApprovalMail(db.Parentstbls.Find(id).MailAddress);
            db.SaveChanges();


            return(RedirectToAction("ViewLeaveRequests", "LeaveRequests"));
        }
        public ActionResult Create(SubjectViewModel sub, FormCollection form)
        {
            try
            {
                if (HelperClass.account != "Admin")
                {
                    return(RedirectToAction("Index", "Home"));
                }

                DB37Entities  db     = new DB37Entities();
                List <string> mylist = new List <string>();
                foreach (Classtbl c in db.Classtbls)
                {
                    mylist.Add(c.Section);
                }
                ViewBag.Options = mylist;
                string classname = form["Classlist"].ToString();

                int classid = db.Classtbls.Where(t => t.Section.Equals(classname)).FirstOrDefault().Id;

                if (db.Subjectstbls.Any(t => t.Name == sub.name) == false)
                {
                    Subjectstbl s = new Subjectstbl();
                    s.Name = sub.name;
                    db.Subjectstbls.Add(s);
                    db.SaveChanges();
                }
                DB37Entities db2       = new DB37Entities();
                int          subjectid = db2.Subjectstbls.Where(t => t.Name == sub.name).FirstOrDefault().Id;
                if (db2.ClassSubjecttbls.Any(t => t.ClassId == classid && t.SubjectId == subjectid))
                {
                    ViewBag.warn = "Class Already has this Subject";
                    return(View());
                }

                ClassSubjecttbl cs = new ClassSubjecttbl();
                cs.SubjectId = subjectid;
                cs.ClassId   = classid;
                db2.ClassSubjecttbls.Add(cs);
                db2.SaveChanges();
                return(RedirectToAction("Index", "Subject"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult InactiveStudents(int id)
        {
            if (HelperClass.account != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }
            DB37Entities db = new DB37Entities();
            int          inactivestatusid = db.ActiveStatustbls.Where(t1 => t1.Name == "Inactive").FirstOrDefault().Id;

            db.Studentstbls.Where(t => t.Id == id).FirstOrDefault().ActiveStatusId = inactivestatusid;
            StudentLefttbl st = new StudentLefttbl();

            st.StudentId = id;
            st.DateLeft  = DateTime.Now.Date;
            db.StudentLefttbls.Add(st);
            db.SaveChanges();
            return(RedirectToAction("ViewActiveStudents", "StudentsLeft"));
        }
        public ActionResult Create(ApplyForLeaveViewModel Obj)
        {
            try
            {
                if (HelperClass.account != "Parent")
                {
                    return(RedirectToAction("Index", "Home"));
                }
                ApplyForLeaveViewModel a = new ApplyForLeaveViewModel();
                if (a.invalidRegistrationNumber(Obj.regNo))
                {
                    ViewBag.warn = "Invalid Registration Number (SSS-X)";
                    return(View());
                }
                // TODO: Add insert logic here

                DB37Entities db = new DB37Entities();
                if (db.Parentstbls.Any(t1 => t1.MailAddress.Equals(Obj.parentEmail)) && db.Studentstbls.Any(t2 => t2.RegistrationNumber.Equals(Obj.regNo)))
                {
                    Leavestbl l = new Leavestbl();
                    l.ParentId         = db.Parentstbls.Where(t3 => t3.MailAddress.Equals(Obj.parentEmail)).FirstOrDefault().Id;
                    l.StudentId        = db.Studentstbls.Where(t4 => t4.RegistrationNumber.Equals(Obj.regNo)).FirstOrDefault().Id;
                    l.LeaveDescription = Obj.description;
                    l.DateFrom         = Obj.from;
                    l.DateEnd          = Obj.to;
                    l.ApprovalStatusId = db.ApprovalStatustbls.Where(t5 => t5.Name.Equals("pending")).FirstOrDefault().Id;
                    db.Leavestbls.Add(l);
                    db.SaveChanges();
                }
                else
                {
                    ViewBag.warn = "Invalid Credentials";
                    return(View());
                }


                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Пример #13
0
        public ActionResult Edit(int id, ClassesViewModels collection)
        {
            try
            {
                // TODO: Add update logic here

                if (HelperClass.account != "Admin")
                {
                    return(RedirectToAction("Index", "Home"));
                }
                DB37Entities db = new DB37Entities();
                db.Classtbls.Find(id).Section = collection.Name;
                db.SaveChanges();
                return(RedirectToAction("Index", "Class"));
            }
            catch
            {
                return(View());
            }
        }
 public ActionResult Edit(int id, SubjectViewModel collection)
 {
     try
     {
         if (HelperClass.account != "Admin")
         {
             return(RedirectToAction("Index", "Home"));
         }
         DB37Entities db = new DB37Entities();
         if (db.Subjectstbls.Any(t => t.Name == collection.name))
         {
             ViewBag.warn = "Subject with this name already Exist";
             return(View());
         }
         // TODO: Add update logic here
         db.Subjectstbls.Where(t => t.Id == id).FirstOrDefault().Name = collection.name;
         db.SaveChanges();
         return(RedirectToAction("Index", "Subject"));
     }
     catch
     {
         return(View());
     }
 }
Пример #15
0
        public ActionResult DisapproveApproveRegistrationRequests(int id, int sid)
        {
            if (HelperClass.account != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }
            DB37Entities db = new DB37Entities();

            //int sid = db.ParentStudenttbls.Where(t => t.ParentId.Equals(id)).FirstOrDefault().StudentId;

            int check = SendDisapprovalMail(db.Parentstbls.Find(id).MailAddress);

            if (check == 0)
            {
                foreach (ParentStudenttbl pstbl in db.ParentStudenttbls)
                {
                    if (pstbl.ParentId == id)
                    {
                        db.ParentStudenttbls.Remove(pstbl);
                    }
                }


                foreach (Studentstbl stbl in db.Studentstbls)
                {
                    if (stbl.Id == sid)
                    {
                        db.Studentstbls.Remove(stbl);
                    }
                }

                foreach (Parentstbl ptbl in db.Parentstbls)
                {
                    if (ptbl.Id == id)
                    {
                        db.Parentstbls.Remove(ptbl);
                    }
                }
            }
            else
            {
                foreach (ParentStudenttbl pstbl in db.ParentStudenttbls)
                {
                    if (pstbl.ParentId == id)
                    {
                        db.ParentStudenttbls.Remove(pstbl);
                    }
                }


                foreach (Studentstbl stbl in db.Studentstbls)
                {
                    if (stbl.Id == sid)
                    {
                        db.Studentstbls.Remove(stbl);
                    }
                }

                foreach (Parentstbl ptbl in db.Parentstbls)
                {
                    if (ptbl.Id == id)
                    {
                        db.Parentstbls.Remove(ptbl);
                    }
                }
                db.SaveChanges();
            }

            return(RedirectToAction("ViewRegistrationRequests", "RegistrationRequests"));
        }
        public ActionResult StudentRegistration(StudentRegistrationViewModels s, FormCollection form)
        {
            string        classname = form["Classlist"].ToString();
            int           classid;
            DB37Entities  db      = new DB37Entities();
            List <string> classes = new List <string>();

            foreach (Classtbl c in db.Classtbls)
            {
                classes.Add(c.Section);
            }
            ViewBag.Options = classes;
            classid         = db.Classtbls.Where(t => t.Section == classname).FirstOrDefault().Id;
            if (HelperClass.account != "Parent" && ParentRegistrationViewModels.p.Email == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Parentstbl parent = new Parentstbl();

            if (HelperClass.account != "Parent")
            {
                parent.FirstName = ParentRegistrationViewModels.p.FirstName;

                parent.LastName = ParentRegistrationViewModels.p.LastName;

                parent.PhoneNumber = ParentRegistrationViewModels.p.PhoneNumber;

                parent.MailAddress = ParentRegistrationViewModels.p.Email;

                parent.CNIC = ParentRegistrationViewModels.p.CNIC;

                parent.PrntPassword     = ParentRegistrationViewModels.p.PrntPassword;
                parent.ApprovalStatusId = db.ApprovalStatustbls.Where(t => t.Name.Equals("pending")).FirstOrDefault().Id;
                db.Parentstbls.Add(parent);
            }

            Studentstbl student = new Studentstbl();

            student.FirstName          = s.FirstName;
            student.LastName           = s.LastName;
            student.ActiveStatusId     = db.ActiveStatustbls.Where(t => t.Name.Equals("Active")).FirstOrDefault().Id;
            student.ApprovalStatusId   = db.ApprovalStatustbls.Where(t => t.Name.Equals("pending")).FirstOrDefault().Id;
            student.Username           = s.Username;
            student.StdPassword        = s.StdPassword;
            student.CNIC               = s.CNIC;
            student.RegistrationNumber = "-1";
            db.Studentstbls.Add(student);



            db.SaveChanges();

            DB37Entities db2 = new DB37Entities();


            ParentStudenttbl pstbl = new ParentStudenttbl();

            pstbl.StudentId = db2.Studentstbls.Where(t => t.Username == student.Username).FirstOrDefault().Id;
            if (HelperClass.parentid != -1)
            {
                pstbl.ParentId = HelperClass.parentid;
            }
            else
            {
                pstbl.ParentId = db2.Parentstbls.Where(t => t.MailAddress == parent.MailAddress).FirstOrDefault().Id;
            }
            db2.ParentStudenttbls.Add(pstbl);
            StudentClasstbl s1 = new StudentClasstbl();

            s1.StudentId = pstbl.StudentId;
            s1.ClassId   = classid;
            db2.StudentClasstbls.Add(s1);
            db2.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
Пример #17
0
        public ActionResult Create(FormCollection form, string sub, AssessmentViewModel obj)
        {
            try
            {
                DB37Entities db = new DB37Entities();

                List <string> termList = new List <string>();
                foreach (Termstbl ttbl in db.Termstbls)
                {
                    termList.Add(ttbl.Name);
                }
                ViewBag.Options1 = termList;

                List <string> classList = new List <string>();
                foreach (Classtbl ctbl in db.Classtbls)
                {
                    classList.Add(ctbl.Section);
                }
                ViewBag.Options = classList;

                List <string> subjectList = new List <string>();
                foreach (Subjectstbl stbl in db.Subjectstbls)
                {
                    subjectList.Add(stbl.Name);
                }
                if (AssessmentViewModel.flag == false)
                {
                }


                // TODO: Add insert logic here
                if (sub == "show")
                {
                    AssessmentViewModel.totalMarks = Convert.ToInt32(form["total"]);

                    selectedClass = form["Classlist"].ToString();
                    if (form["Classlist"].ToString() == null)
                    {
                        ViewBag.warn = "Select subjects before clicking show";
                        return(View());
                    }
                    AssessmentViewModel.classId = db.Classtbls.Where(t1 => t1.Section.Equals(selectedClass)).FirstOrDefault().Id;
                    if (form["subjectList"].ToString() == null)
                    {
                        ViewBag.warn = "Select subjects before clicking show";
                        return(View());
                    }

                    selectedSubject = form["subjectList"].ToString();
                    AssessmentViewModel.subjectId = db.Subjectstbls.Where(t2 => t2.Name.Equals(selectedSubject)).FirstOrDefault().Id;

                    selectedTerm = form["Termlist"].ToString();
                    AssessmentViewModel.termId = db.Termstbls.Where(t4 => t4.Name.Equals(selectedTerm)).FirstOrDefault().Id;
                    AssessmentViewModel.assessmentList.Clear();
                    AssessmentViewModel.flag = true;



                    foreach (StudentClasstbl sctbl in db.StudentClasstbls)
                    {
                        if (sctbl.ClassId == AssessmentViewModel.classId)
                        {
                            AssessmentViewModel assessment = new AssessmentViewModel();
                            assessment.studentId = sctbl.StudentId;
                            assessment.regNo     = db.Studentstbls.Where(t3 => t3.Id.Equals(sctbl.StudentId)).FirstOrDefault().RegistrationNumber;
                            AssessmentViewModel.assessmentList.Add(assessment);
                        }
                    }
                    //ViewBag.myModel = AssessmentViewModel.assessmentList;
                    return(View(AssessmentViewModel.assessmentList));
                }
                else
                {
                    string[] keys  = form.AllKeys;
                    var      added = form[keys[3]].Split(',');
                    var      p     = added[0];


                    AssessmentViewModel a = new AssessmentViewModel();
                    int count             = 0;

                    foreach (AssessmentViewModel a1 in AssessmentViewModel.assessmentList)
                    {
                        if (db.Markingstbls.Any(t6 => t6.ClassId == AssessmentViewModel.classId && t6.SubjectId == AssessmentViewModel.subjectId && t6.StudentId == a1.studentId && t6.TermId == AssessmentViewModel.termId))
                        {
                            db.Markingstbls.Where(t7 => t7.ClassId == AssessmentViewModel.classId && t7.SubjectId == AssessmentViewModel.subjectId && t7.StudentId == a1.studentId && t7.TermId == AssessmentViewModel.termId).FirstOrDefault().ObtainedMarks = Convert.ToInt32(added[count]);
                        }
                        else
                        {
                            Markingstbl mtbl = new Markingstbl();
                            mtbl.ClassId       = AssessmentViewModel.classId;
                            mtbl.SubjectId     = AssessmentViewModel.subjectId;
                            mtbl.StudentId     = a1.studentId;
                            mtbl.TotalMarks    = AssessmentViewModel.totalMarks;
                            mtbl.ObtainedMarks = Convert.ToInt32(added[count]);
                            mtbl.TermId        = AssessmentViewModel.termId;
                            db.Markingstbls.Add(mtbl);
                        }
                        count++;
                    }
                    db.SaveChanges();

                    return(RedirectToAction("Create"));
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public ActionResult AddAttendance(FormCollection form)
        {
            if (HelperClass.account != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }

            List <Attendance> list = new List <Attendance>();

            DB37Entities  db          = new DB37Entities();
            List <string> myclasslist = new List <string>();

            foreach (Classtbl c in db.Classtbls)
            {
                myclasslist.Add(c.Section);
            }
            ViewBag.Options = myclasslist;
            List <string> mystatus = new List <string>();

            foreach (AttendanceStatustbl a in db.AttendanceStatustbls)
            {
                mystatus.Add(a.Name);
            }
            ViewBag.status = mystatus;
            int    id        = Attendance.check;
            string classname = form["Classlist"].ToString();

            ViewBag.Classname = classname;
            int classid = db.Classtbls.Where(t => t.Section.Equals(classname)).FirstOrDefault().Id;

            if (id == 0)
            {
                Attendance.studentlist.Clear();
                foreach (StudentClasstbl s in db.StudentClasstbls)
                {
                    int studentactivestatusid = db.Studentstbls.Where(t => t.Id == s.StudentId).FirstOrDefault().ActiveStatusId;
                    if (s.ClassId == classid && studentactivestatusid == db.ActiveStatustbls.Where(t1 => t1.Name == "Active").FirstOrDefault().Id)
                    {
                        Attendance a = new Attendance();
                        a.regNo      = db.Studentstbls.Where(t => t.Id == s.StudentId).FirstOrDefault().RegistrationNumber;
                        a.statuslist = new List <SelectListItem> {
                            new SelectListItem {
                                Value = db.AttendanceStatustbls.Where(t => t.Name == "Present").FirstOrDefault().Id.ToString(), Text = "Present"
                            },


                            new SelectListItem {
                                Value = db.AttendanceStatustbls.Where(t => t.Name == "Absent").FirstOrDefault().Id.ToString(), Text = "Absent"
                            },

                            new SelectListItem {
                                Value = db.AttendanceStatustbls.Where(t => t.Name == "Leave").FirstOrDefault().Id.ToString(), Text = "Leave"
                            },
                        };
                        Attendance.studentlist.Add(a.regNo);
                        list.Add(a);
                    }
                }

                return(View(list));
            }
            else
            {
                string[] keys  = form.AllKeys;
                var      added = form[keys[3]].Split(',');
                int      i     = 0;
                string   date  = form["date"].ToString();
                classname = form["Classlist"].ToString();
                classid   = db.Classtbls.Where(t => t.Section == classname).FirstOrDefault().Id;
                DateTime adate = Convert.ToDateTime(date);
                foreach (AttendanceMarkingtbl amt in db.AttendanceMarkingtbls)
                {
                    DateTime amtl = amt.AttendanceDate;
                    if (amtl.Date == adate.Date)
                    {
                        foreach (StudentClasstbl c in db.StudentClasstbls)
                        {
                            if (c.ClassId == classid && db.AttendanceMarkingtbls.Any(t1 => t1.StudentId == c.StudentId))
                            {
                                Attendance.studentlist.Clear();
                                ViewBag.warn = "Attendance of class at this date is already marked";
                                foreach (StudentClasstbl s in db.StudentClasstbls)
                                {
                                    int studentactivestatusid = db.Studentstbls.Where(t => t.Id == s.StudentId).FirstOrDefault().ActiveStatusId;

                                    if (s.ClassId == classid && studentactivestatusid == db.ActiveStatustbls.Where(t1 => t1.Name == "Active").FirstOrDefault().Id)
                                    {
                                        Attendance a = new Attendance();
                                        a.regNo      = db.Studentstbls.Where(t => t.Id == s.StudentId).FirstOrDefault().RegistrationNumber;
                                        a.statuslist = new List <SelectListItem> {
                                            new SelectListItem {
                                                Value = db.AttendanceStatustbls.Where(t => t.Name == "Present").FirstOrDefault().Id.ToString(), Text = "Present"
                                            },



                                            new SelectListItem {
                                                Value = db.AttendanceStatustbls.Where(t => t.Name == "Absent").FirstOrDefault().Id.ToString(), Text = "Absent"
                                            },


                                            new SelectListItem {
                                                Value = db.AttendanceStatustbls.Where(t => t.Name == "Leave").FirstOrDefault().Id.ToString(), Text = "Leave"
                                            },
                                        };
                                        Attendance.studentlist.Add(a.regNo);
                                        list.Add(a);
                                    }
                                }
                                return(View(list));
                            }
                        }
                    }
                }
                i = 0;
                foreach (string regnumber in Attendance.studentlist)
                {
                    var p                    = added[i];
                    int studentid            = db.Studentstbls.Where(t => t.RegistrationNumber == regnumber).FirstOrDefault().Id;
                    int attendanceid         = Convert.ToInt32(p);
                    AttendanceMarkingtbl atm = new AttendanceMarkingtbl();
                    atm.StudentId          = studentid;
                    atm.AttendanceStatusId = attendanceid;
                    atm.AttendanceDate     = adate.Date;
                    db.AttendanceMarkingtbls.Add(atm);
                    i = i + 1;
                }
                db.SaveChanges();
                return(RedirectToAction("AddAttendance", "Attendance"));
            }
        }
Пример #19
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                // TODO: Add insert logic here

                DB37Entities  db        = new DB37Entities();
                List <string> classlist = new List <string>();
                List <string> days      = new List <string>();
                List <string> time      = new List <string>();
                string        temp;

                foreach (Classtbl c in db.Classtbls)
                {
                    temp = c.Section;
                    classlist.Add(temp);
                }


                // List of Days
                temp = "Monday";
                days.Add(temp);
                temp = "Tuesday";
                days.Add(temp);
                temp = "Wednesday";
                days.Add(temp);
                temp = "Thursday";
                days.Add(temp);
                temp = "Friday";
                days.Add(temp);

                temp = "08:00:00 AM";
                time.Add(temp);
                temp = "09:00:00 AM";
                time.Add(temp);
                temp = "10:00:00 AM";
                time.Add(temp);
                temp = "11:00:00 AM";
                time.Add(temp);
                temp = "12:00:00 AM";
                time.Add(temp);


                ViewBag.Options = classlist;
                ViewBag.Days    = days;
                ViewBag.Time    = time;



                string classname   = form["Classlist"].ToString();
                string subjectname = form["subjectList"].ToString();
                string dayname     = form["daylist"].ToString();
                string timename    = form["timelist"].ToString();

                int         classid   = db.Classtbls.Where(t => t.Section == classname).FirstOrDefault().Id;
                int         subjectid = db.Subjectstbls.Where(t => t.Name == subjectname).FirstOrDefault().Id;
                CultureInfo culture   = new CultureInfo("en-US");
                DateTime    tempDate  = Convert.ToDateTime("01/01/0001 " + timename, culture);

                if (db.TimeTabletbls.Any(t => t.LectureTime.ToString() == tempDate.TimeOfDay.ToString() && t.WeeksDay == dayname && t.ClassId == classid))
                {
                    ViewBag.warn = "Lecture is already assigned at this time";
                    return(View());
                }

                TimeTabletbl t1 = new TimeTabletbl();
                t1.ClassId     = classid;
                t1.SubjectId   = subjectid;
                t1.WeeksDay    = dayname;
                t1.LectureTime = tempDate.TimeOfDay;

                db.TimeTabletbls.Add(t1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }