Example #1
0
        public ActionResult AddAllAttendance(string searchButton, string batch,
                                             string part, IEnumerable <ViewModelAttendance> VM1, string subjectID,
                                             string totalMarks, Nullable <DateTime> date)
        {
            string         t_id             = Session["ID"].ToString();
            List <Subject> tsubj            = TeacherModel.getRelatedSubjects(t_id);
            List <Batch>   batchesInTeacher = TeacherModel.getRelatedStudentBatches(t_id);

            ViewBag.Batches         = batchesInTeacher;
            ViewBag.RelatedSubjects = tsubj;

            if (searchButton != null)
            {
                if ((part != null && part != "") &&
                    (batch != null && batch != "Please select") &&
                    (subjectID != null && subjectID != "Please select"))
                {
                    Guid subj = Guid.Parse(subjectID);
                    TempData["Batch"]     = batch;
                    TempData["Part"]      = part;
                    TempData["SubjectID"] = subj;

                    TempData["TeacherUploadAttendance"] = "Batch: " + batch +
                                                          ", Degree Program: " + r.Batches.Where(s => s.BatchName == batch)
                                                          .Select(s => s.Degree_Program.Degree_ProgramName).FirstOrDefault()
                                                          + ", Section: " + r.Batches.Where(s => s.BatchName == batch)
                                                          .Select(s => s.Section.SectionName).FirstOrDefault() + ", Part: " + part +
                                                          ", Subject: " +
                                                          r.Subjects.Where(s => s.SubjectID == subj)
                                                          .Select(s => s.SubjectName).FirstOrDefault();

                    IEnumerable <ViewModelAttendance> VM2 = TeacherModel.getListofStudentsAttendanceAccordingToBatch(batch, part, subjectID);
                    if (VM2 == null)
                    {
                        ViewBag.Message = "No Records Found";
                        return(View(VM2));
                    }
                    else
                    {
                        ViewBag.RelatedSubjects = tsubj;
                        ViewBag.Message         = null;
                        return(View(VM2));
                    }
                }
                else
                {
                    ViewBag.Message = "Plz Select All the Fields";
                    return(View());
                }
            }
            else
            {
                if (VM1 != null)
                {
                    Guid subj   = new Guid();
                    int  partID = 0;
                    int  total  = 0;
                    if (Guid.TryParse(TempData["SubjectID"].ToString(), out subj) &&
                        int.TryParse(TempData["Part"].ToString(), out partID) &&
                        int.TryParse(totalMarks, out total))
                    {
                        string result = TeacherModel.AddAllAttendanceRecord(TempData["Batch"].ToString(), date, partID, subj, VM1, total);

                        if (result == "OK")
                        {
                            ViewBag.Message = "Successfully Record Added";
                            return(View());
                        }
                        else
                        {
                            ViewBag.Message = result;
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.Message = "Unable To Upload Attendance!";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Message = "No Student Was found To Upload Attendance!";
                    return(View());
                }
            }
        }