public JsonResult Upload(HttpPostedFileBase file, long?student_Id)
        {
            //long nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id"));
            long    nStudent_Id         = Convert.ToInt64(student_Id);
            Student studentToBeModified = new Student();

            byte[] bytes;
            try
            {
                if (file != null)
                {
                    using (BinaryReader br = new BinaryReader(file.InputStream))
                    {
                        bytes = br.ReadBytes(file.ContentLength);
                    }


                    using (var dbcontext = new SchoolERPDBContext())
                    {
                        studentToBeModified       = dbcontext.Student.Find(nStudent_Id);
                        studentToBeModified.Photo = bytes;
                        dbcontext.Entry(studentToBeModified).CurrentValues.SetValues(studentToBeModified);
                        dbcontext.SaveChanges();
                    }
                }
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet));
            }

            //return null;
        }
        public JsonResult Upload(HttpPostedFileBase file)

        {
            long       nAssignment_Id         = Convert.ToInt32(TempData.Peek("Assignment_Id"));
            Assignment assignmentToBeModified = new Assignment();

            byte[] bytes;
            try
            {
                if (file != null)
                {
                    using (BinaryReader br = new BinaryReader(file.InputStream))
                    {
                        bytes = br.ReadBytes(file.ContentLength);
                    }


                    using (var dbcontext = new SchoolERPDBContext())
                    {
                        assignmentToBeModified       = dbcontext.Assignment.Find(nAssignment_Id);
                        assignmentToBeModified.Photo = bytes;
                        dbcontext.Entry(assignmentToBeModified).CurrentValues.SetValues(assignmentToBeModified);
                        dbcontext.SaveChanges();
                    }
                }
                return(Json("Assignment Successfully Added", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet));
            }

            return(null);
        }
        public async Task <ActionResult> Delete(int id)
        {
            using (var dbcontext = new SchoolERPDBContext())
            {
                Class cls = await dbcontext.Class.FindAsync(id);

                if (cls != null)
                {
                    cls.Is_Deleted = true;
                    dbcontext.Entry(cls).CurrentValues.SetValues(cls);
                    dbcontext.Entry(cls).State = EntityState.Modified;
                    await dbcontext.SaveChangesAsync();
                }
            }

            return(RedirectToAction("ClassList"));
        }
        public async Task <ActionResult> Delete(int id)
        {
            using (var dbcontext = new SchoolERPDBContext())
            {
                User_Role userRole = await dbcontext.User_Roles.FindAsync(id);

                if (userRole != null)
                {
                    userRole.Is_Deleted = true;
                    dbcontext.Entry(userRole).CurrentValues.SetValues(userRole);
                    dbcontext.Entry(userRole).State = EntityState.Modified;
                    await dbcontext.SaveChangesAsync();
                }
            }

            return(RedirectToAction("RoleList"));
        }
        public async Task <ActionResult> Delete(int id)
        {
            using (var dbcontext = new SchoolERPDBContext())
            {
                Exam exam = await dbcontext.Exam.FindAsync(id);

                if (exam != null)
                {
                    exam.Is_Deleted = true;
                    dbcontext.Entry(exam).CurrentValues.SetValues(exam);
                    dbcontext.Entry(exam).State = EntityState.Modified;
                    await dbcontext.SaveChangesAsync();
                }
            }

            return(RedirectToAction("ExamList"));
        }
        public ActionResult EditAndSaveStudentOtherDetails(Student_Other_Details Student_Other_Detail)
        {
            long nStudent_Id = Convert.ToInt64(Student_Other_Detail.Student_Id);
            Student_Other_Details student_OtherDetails_ToBeEdited = new Student_Other_Details();
            string sReturn_Text = string.Empty;

            try
            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    //var id = dbcontext.Student_Other_Details.Where(x => x.Student_Id == nStudent_Id).FirstOrDefault().StudentDetail_Id;
                    if (dbcontext.Student_Other_Details.Where(x => x.Student_Id == nStudent_Id).Count() == 1)
                    {
                        var studen_OtherDetailsTotEdit = dbcontext.Student_Other_Details.Find(Student_Other_Detail.StudentDetail_Id);

                        studen_OtherDetailsTotEdit.Identification_Mark1     = Student_Other_Detail.Identification_Mark1;
                        studen_OtherDetailsTotEdit.Identification_Mark2     = Student_Other_Detail.Identification_Mark2;
                        studen_OtherDetailsTotEdit.Is_Allergic              = Student_Other_Detail.Is_Allergic;
                        studen_OtherDetailsTotEdit.Allergy_Details          = Student_Other_Detail.Allergy_Details;
                        studen_OtherDetailsTotEdit.Father_Occupation_Id     = Student_Other_Detail.Father_Occupation_Id;
                        studen_OtherDetailsTotEdit.Father_Designation       = Student_Other_Detail.Father_Designation;
                        studen_OtherDetailsTotEdit.Father_Company_Name      = Student_Other_Detail.Father_Company_Name;
                        studen_OtherDetailsTotEdit.Father_Office_Address    = Student_Other_Detail.Father_Office_Address;
                        studen_OtherDetailsTotEdit.Father_Annual_Income     = Student_Other_Detail.Father_Annual_Income;
                        studen_OtherDetailsTotEdit.Mother_Occupation_Id     = Student_Other_Detail.Mother_Occupation_Id;
                        studen_OtherDetailsTotEdit.Mother_Designation       = Student_Other_Detail.Mother_Designation;
                        studen_OtherDetailsTotEdit.Mother_Company_Name      = Student_Other_Detail.Mother_Company_Name;
                        studen_OtherDetailsTotEdit.Mother_Office_Address    = Student_Other_Detail.Mother_Office_Address;
                        studen_OtherDetailsTotEdit.Mother_Annual_Income     = Student_Other_Detail.Mother_Annual_Income;
                        studen_OtherDetailsTotEdit.Medical_History_Details  = Student_Other_Detail.Medical_History_Details;
                        studen_OtherDetailsTotEdit.Second_Language_Opted_Id = Student_Other_Detail.Second_Language_Opted_Id;
                        studen_OtherDetailsTotEdit.Updated_On = DateTime.Now;


                        dbcontext.Entry(studen_OtherDetailsTotEdit).State = EntityState.Modified;
                        dbcontext.SaveChanges();
                    }
                    else
                    {
                        Student_Other_Detail.Created_On = DateTime.Now;
                        Student_Other_Detail.Created_By = 5;
                        dbcontext.Student_Other_Details.Add(Student_Other_Detail);
                        dbcontext.SaveChanges();
                    }

                    TempData["Student_Id"] = nStudent_Id;
                    TempData.Keep("Student_Id");
                    sReturn_Text = "OK";
                }
            }
            catch (Exception ex)
            {
                sReturn_Text = ex.InnerException.Message.ToString();
            }

            return(Json(sReturn_Text, JsonRequestBehavior.AllowGet));
            //	return View();
        }
        public ActionResult Delete(long id)
        {
            using (var dbcontext = new SchoolERPDBContext())
            {
                var studenToBeDeleted = dbcontext.Student.Find(id);
                studenToBeDeleted.Is_Deleted = true;
                studenToBeDeleted.Is_Active  = true;
                studenToBeDeleted.Updated_By = 5;
                studenToBeDeleted.Updated_On = DateTime.Now;

                dbcontext.Entry(studenToBeDeleted).State = EntityState.Modified;
                dbcontext.SaveChanges();
            }
            return(RedirectToAction("StudentList"));
        }
        public ActionResult Delete(long Id)
        {
            using (var dbcontext = new SchoolERPDBContext())
            {
                var hostelRoomToBeDeleted = dbcontext.Hostel_Room.Find(Id);
                hostelRoomToBeDeleted.Is_Deleted = true;
                hostelRoomToBeDeleted.Is_Active  = false;
                hostelRoomToBeDeleted.Updated_By = 5;
                hostelRoomToBeDeleted.Updated_On = DateTime.Now;

                dbcontext.Entry(hostelRoomToBeDeleted).State = EntityState.Modified;
                dbcontext.SaveChanges();
            }
            return(RedirectToAction("HostelRoomList"));
            //return View();
        }
        public JsonResult DeleteStudentSiblingDetail(string id)
        {
            int idTobemodified = Convert.ToInt16(id);
            List <Student_SiblingList_ViewModel> modifiedStudentSiblingDetails = new List <Student_SiblingList_ViewModel>();

            using (var dbcontext = new SchoolERPDBContext())
            {
                var studentSiblingDetailTobedeleted = dbcontext.Student_Sibling_Detail.Find(idTobemodified);
                studentSiblingDetailTobedeleted.Is_Deleted = true;
                studentSiblingDetailTobedeleted.Updated_On = DateTime.Now;
                studentSiblingDetailTobedeleted.Updated_By = 5;
                dbcontext.Entry(studentSiblingDetailTobedeleted).CurrentValues.SetValues(studentSiblingDetailTobedeleted);
                dbcontext.SaveChanges();
            }
            modifiedStudentSiblingDetails = getStudenSiblingDetail();
            return(Json(new { items = modifiedStudentSiblingDetails }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult UploadStudentDocuments(HttpPostedFileBase file1, HttpPostedFileBase file2, HttpPostedFileBase file3, HttpPostedFileBase file4, HttpPostedFileBase file5, HttpPostedFileBase file6)
        {
            //long nStudent_Id =
            //	long nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id"));
            long             nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id"));;
            Student_Document StudentDocumentToBeAddededOrUpdated = new Student_Document();

            HttpPostedFileBase[] fileBaseArr = new HttpPostedFileBase[6];



            //byte[] bytes1, bytes2 , bytes3, bytes4, bytes5, bytes6;

            try
            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (file1 != null)
                    {
                        StudentDocumentToBeAddededOrUpdated.document1 = ConvertFiletoBYteStream(file1);
                    }
                    else
                    {
                    }
                    if (file2 != null)
                    {
                        StudentDocumentToBeAddededOrUpdated.document2 = ConvertFiletoBYteStream(file2);
                    }
                    if (file3 != null)
                    {
                        StudentDocumentToBeAddededOrUpdated.document3 = ConvertFiletoBYteStream(file3);
                    }
                    if (file4 != null)
                    {
                        StudentDocumentToBeAddededOrUpdated.document4 = ConvertFiletoBYteStream(file4);
                    }
                    if (file5 != null)
                    {
                        StudentDocumentToBeAddededOrUpdated.document5 = ConvertFiletoBYteStream(file5);
                    }
                    if (file6 != null)
                    {
                        StudentDocumentToBeAddededOrUpdated.document6 = ConvertFiletoBYteStream(file6);
                    }

                    if (dbcontext.Student_Document.Where(x => x.Student_Id == nStudent_Id).ToList().Count() > 0)
                    {
                        var studentDocumentId      = dbcontext.Student_Document.Where(x => x.Student_Id == nStudent_Id).FirstOrDefault().Id;
                        var studentDocToBeModified = dbcontext.Student_Document.Find(studentDocumentId);
                        studentDocToBeModified.document1 = StudentDocumentToBeAddededOrUpdated.document1 == null ? studentDocToBeModified.document1 : StudentDocumentToBeAddededOrUpdated.document1;
                        studentDocToBeModified.document2 = StudentDocumentToBeAddededOrUpdated.document2 == null ? studentDocToBeModified.document2 : StudentDocumentToBeAddededOrUpdated.document2;
                        studentDocToBeModified.document3 = StudentDocumentToBeAddededOrUpdated.document3 == null ? studentDocToBeModified.document3 : StudentDocumentToBeAddededOrUpdated.document3;
                        studentDocToBeModified.document4 = StudentDocumentToBeAddededOrUpdated.document4 == null ? studentDocToBeModified.document4 : StudentDocumentToBeAddededOrUpdated.document4;
                        studentDocToBeModified.document5 = StudentDocumentToBeAddededOrUpdated.document5 == null ? studentDocToBeModified.document5 : StudentDocumentToBeAddededOrUpdated.document5;
                        studentDocToBeModified.document6 = StudentDocumentToBeAddededOrUpdated.document6 == null ? studentDocToBeModified.document6 : StudentDocumentToBeAddededOrUpdated.document6;

                        dbcontext.Entry(studentDocToBeModified).CurrentValues.SetValues(studentDocToBeModified);
                        dbcontext.SaveChanges();
                    }
                    else
                    {
                        StudentDocumentToBeAddededOrUpdated.Student_Id = nStudent_Id;
                        dbcontext.Student_Document.Add(StudentDocumentToBeAddededOrUpdated);
                        dbcontext.SaveChanges();
                    }

                    //
                }



                return(Json("Student Documents Successfully Uploaded", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult EditStudent(Student student)
        {
            string sReturnText = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {
                    using (var dbcontext = new SchoolERPDBContext())
                    {
                        Student studentToBeUpdated = dbcontext.Student.Find(student.Student_Id);

                        studentToBeUpdated.First_Name       = student.First_Name;
                        studentToBeUpdated.Last_Name        = student.Last_Name;
                        studentToBeUpdated.Middle_Name      = student.Middle_Name;
                        studentToBeUpdated.Father_Name      = student.Father_Name;
                        studentToBeUpdated.Mother_Name      = student.Mother_Name;
                        studentToBeUpdated.Aadhar_No        = student.Aadhar_No;
                        studentToBeUpdated.Address_Line1    = student.Address_Line1;
                        studentToBeUpdated.Address_Line2    = student.Address_Line2;
                        studentToBeUpdated.Blood_Group_Id   = student.Blood_Group_Id;
                        studentToBeUpdated.Email_Id         = student.Email_Id;
                        studentToBeUpdated.DOB              = student.DOB;
                        studentToBeUpdated.Enrollment_Date  = student.Enrollment_Date;
                        studentToBeUpdated.City_Id          = student.City_Id;
                        studentToBeUpdated.State_Id         = student.State_Id;
                        studentToBeUpdated.Country_Id       = student.Country_Id;
                        studentToBeUpdated.Blood_Group_Id   = student.Blood_Group_Id;
                        studentToBeUpdated.Is_HostelStudent = student.Is_HostelStudent;
                        studentToBeUpdated.Phone_No1        = student.Phone_No1;
                        studentToBeUpdated.Phone_No2        = student.Phone_No2;
                        studentToBeUpdated.Section_Id       = student.Section_Id;
                        studentToBeUpdated.Class_Id         = student.Class_Id;
                        studentToBeUpdated.Gender_Id        = student.Gender_Id;
                        studentToBeUpdated.Pincode          = student.Pincode;
                        studentToBeUpdated.Updated_On       = DateTime.Now;
                        studentToBeUpdated.Updated_By       = 5;


                        if (student.Email_Id.Trim() != studentToBeUpdated.Email_Id.Trim())
                        {
                            if (!CheckIfEmailAlreadyExists(student.Email_Id, true, false))
                            {
                                dbcontext.Entry(studentToBeUpdated).State = EntityState.Modified;
                                dbcontext.SaveChanges();
                                sReturnText = "OK";
                            }
                            else
                            {
                                sReturnText = "Email Already Exists";
                            }
                        }
                        else
                        {
                            dbcontext.Entry(studentToBeUpdated).State = EntityState.Modified;
                            dbcontext.SaveChanges();
                            sReturnText = "OK";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sReturnText = ex.InnerException.Message.ToString();
            }

            return(Json(sReturnText, JsonRequestBehavior.AllowGet));
        }
Beispiel #12
0
        public JsonResult SaveMarksForClass(List <string[]> myData)
        {
            Mark   newmarkToBeAdded = new Mark();
            string sReturnText      = string.Empty;
            int    nUser_Id;

            int[] nSubjectIdArr = (int[])TempData.Peek("SubjectId_For_Marks");

            nStudentIdArr = (long[])TempData.Peek("StudentIdArr_For_Marks");

            using (var dbcontext = new SchoolERPDBContext())
            {
                //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
                nUser_Id = 4;
            }
            int nCount = myData.ToList().Count;

            int nLoopCount = 0;

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        for (int iMarkDetailLoopCount = 1; iMarkDetailLoopCount < myData.ToList().Count(); iMarkDetailLoopCount++)
                        {
                            Mark newMarkDetail = new Mark();
                            newMarkDetail.Class_Id      = Convert.ToInt16(TempData.Peek("Class_Id_For_Marks"));
                            newMarkDetail.Section_Id    = Convert.ToInt16(TempData.Peek("Section_Id_For_Marks"));
                            newMarkDetail.Student_Id    = nStudentIdArr[iMarkDetailLoopCount - 1];
                            newMarkDetail.Is_Active     = true;
                            newMarkDetail.Is_Deleted    = false;
                            newMarkDetail.Exam_Id       = Convert.ToInt16(TempData.Peek("Exam_Id_For_Marks"));
                            newMarkDetail.Created_By    = 4;
                            newMarkDetail.Created_On    = DateTime.Now;
                            newMarkDetail.Academic_Year = Convert.ToInt16(TempData.Peek("Year_For_Marks"));
                            for (int nSubjectCount = 0; nSubjectCount < nSubjectIdArr.Count(); nSubjectCount++)
                            {
                                newMarkDetail.GetType().GetProperty("Subject_Id" + (nSubjectCount + 1)).SetValue(newMarkDetail, nSubjectIdArr[nSubjectCount], null);
                                newMarkDetail.GetType().GetProperty("Mark" + (nSubjectCount + 1)).SetValue(newMarkDetail, myData[iMarkDetailLoopCount][nSubjectCount + 2] == "" ? 0 : Convert.ToInt16(myData[iMarkDetailLoopCount][nSubjectCount + 2]), null);
                                //newMarkDetail.GetType().GetProperty("Total").SetValue(newMarkDetail, myData[iMarkDetailLoopCount][12] == "" ? 0 : Convert.ToInt32(myData[iMarkDetailLoopCount][12]), null);
                                //newMarkDetail.GetType().GetProperty("Average").SetValue(newMarkDetail, myData[iMarkDetailLoopCount][12] == "" ? 0 : Convert.ToDecimal(myData[iMarkDetailLoopCount][13]), null);
                            }

                            newMarkDetail.GetType().GetProperty("Total").SetValue(newMarkDetail, myData[iMarkDetailLoopCount][12] == "" ? 0 : Convert.ToInt32(myData[iMarkDetailLoopCount][12]), null);
                            newMarkDetail.GetType().GetProperty("Average").SetValue(newMarkDetail, myData[iMarkDetailLoopCount][13] == "" ? 0 : Convert.ToDecimal(myData[iMarkDetailLoopCount][13]), null);
                            if (dbcontext.Mark.Where(a => a.Student_Id == newMarkDetail.Student_Id && a.Academic_Year == newMarkDetail.Academic_Year && a.Exam_Id == newMarkDetail.Exam_Id && (a.Is_Deleted == false || a.Is_Deleted == null)).Count() == 0)
                            {
                                dbcontext.Mark.Add(newMarkDetail);
                                dbcontext.SaveChanges();
                            }
                            else
                            {
                                var markId = dbcontext.Mark.Where(a => a.Student_Id == newMarkDetail.Student_Id && a.Academic_Year == newMarkDetail.Academic_Year && a.Exam_Id == newMarkDetail.Exam_Id && (a.Is_Deleted == false || a.Is_Deleted == null)).ToList()[0].Id;

                                Mark markToBeUpdated = dbcontext.Mark.Find(markId);
                                markToBeUpdated.Is_Active = true;

                                markToBeUpdated.Mark1   = newMarkDetail.Mark1;
                                markToBeUpdated.Mark2   = newMarkDetail.Mark2;
                                markToBeUpdated.Mark3   = newMarkDetail.Mark3;
                                markToBeUpdated.Mark4   = newMarkDetail.Mark4;
                                markToBeUpdated.Mark5   = newMarkDetail.Mark5;
                                markToBeUpdated.Mark6   = newMarkDetail.Mark6;
                                markToBeUpdated.Mark7   = newMarkDetail.Mark7;
                                markToBeUpdated.Mark8   = newMarkDetail.Mark8;
                                markToBeUpdated.Mark9   = newMarkDetail.Mark9;
                                markToBeUpdated.Mark10  = newMarkDetail.Mark10;
                                markToBeUpdated.Total   = newMarkDetail.Total;
                                markToBeUpdated.Average = newMarkDetail.Average;

                                dbcontext.Entry(markToBeUpdated).State = EntityState.Modified;
                                dbcontext.SaveChanges();
                            }

                            if (iMarkDetailLoopCount == (myData.ToList().Count() - 1))
                            {
                                transaction.Commit();
                                sReturnText = "OK";
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
                return(Json(sReturnText, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult SaveExamTimeTable_ForClass(string[][] exam_timetable)
        {
            string sReturnText = string.Empty;

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        if (exam_timetable.Length > 0)
                        {
                            for (int nRowCount = 0; nRowCount < exam_timetable.Length; nRowCount++)
                            {
                                Exam_TimeTable newexam_TimeTable = new Exam_TimeTable();
                                int            nSection_Id       = Convert.ToInt32(exam_timetable[nRowCount][2]);
                                long           nAcademic_Year    = Convert.ToInt64(exam_timetable[nRowCount][5]);
                                int            nClass_Id         = Convert.ToInt32(exam_timetable[nRowCount][3]);
                                int            nExam_Id          = Convert.ToInt32(exam_timetable[nRowCount][4]);
                                int            nSubject_Id       = Convert.ToInt32(exam_timetable[nRowCount][1]);
                                DateTime       dtExamDate        = Convert.ToDateTime(exam_timetable[nRowCount][0]);
                                int            nExam_Session     = Convert.ToInt16(exam_timetable[nRowCount][6]);


                                if (dbcontext.Exam_TimeTable.Where(x => x.Section_Id == nSection_Id && x.Academic_Year == nAcademic_Year && x.Exam_Id == nExam_Id && x.Subject_Id == nSubject_Id && (x.Is_Deleted == null || x.Is_Deleted == false)).Count() == 0)
                                {
                                    newexam_TimeTable.Academic_Year = nAcademic_Year;
                                    newexam_TimeTable.Section_Id    = nSection_Id;
                                    newexam_TimeTable.Class_Id      = dbcontext.Section.Where(x => x.Id == nSection_Id).FirstOrDefault().Class_Id;
                                    newexam_TimeTable.Section_Id    = nSection_Id;
                                    newexam_TimeTable.Exam_Id       = nExam_Id;
                                    newexam_TimeTable.Exam_Date     = dtExamDate;
                                    newexam_TimeTable.Subject_Id    = nSubject_Id;
                                    newexam_TimeTable.Created_By    = 5;
                                    newexam_TimeTable.Created_On    = DateTime.Now;
                                    newexam_TimeTable.Is_Active     = true;
                                    newexam_TimeTable.Exam_Session  = nExam_Session;

                                    dbcontext.Exam_TimeTable.Add(newexam_TimeTable);
                                    dbcontext.SaveChanges();
                                }
                                else
                                {
                                    var exam_TimeTable_Id_ToBeModified = dbcontext.Exam_TimeTable.Where(x => x.Section_Id == nSection_Id && x.Academic_Year == nAcademic_Year && x.Exam_Id == nExam_Id && x.Subject_Id == nSubject_Id && (x.Is_Deleted == null || x.Is_Deleted == false)).FirstOrDefault().Id;

                                    var exam_TimeTable_ToBeModified = dbcontext.Exam_TimeTable.Find(exam_TimeTable_Id_ToBeModified);
                                    exam_TimeTable_ToBeModified.Exam_Date    = dtExamDate;
                                    exam_TimeTable_ToBeModified.Updated_By   = 5;
                                    exam_TimeTable_ToBeModified.Updated_On   = DateTime.Now;
                                    exam_TimeTable_ToBeModified.Exam_Session = nExam_Session;

                                    dbcontext.Entry(exam_TimeTable_ToBeModified).State = EntityState.Modified;
                                    dbcontext.SaveChanges();
                                }
                                if (nRowCount == (exam_timetable.Length - 1))
                                {
                                    transaction.Commit();
                                    sReturnText = "OK";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sReturnText = ex.InnerException.Message.ToString();
                    }
                }
            }
            return(Json(sReturnText, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveTimeTable_For_Staff(string[][] data)
        {
            string sReturnText = string.Empty;

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        if (data.Length > 0)
                        {
                            int  nStaff_Id      = Convert.ToInt32(data[0][8]);
                            long nAcademic_Year = Convert.ToInt64(data[0][9]);

                            for (int nRowCount = 0; nRowCount < data.Length; nRowCount++)
                            {
                                Staff_TimeTable staff_TimeTable = new Staff_TimeTable();

                                if (dbcontext.Staff_TimeTable.Where(x => x.Staff_Id == nStaff_Id && x.Academic_Year == nAcademic_Year && (x.Is_Deleted == null || x.Is_Deleted == false) && x.Week == (nRowCount + 1)).Count() == 0)
                                {
                                    staff_TimeTable.Academic_Year = nAcademic_Year;
                                    staff_TimeTable.Staff_Id      = nStaff_Id;
                                    //staff_TimeTable.Class_Id = dbcontext.Section.Where(x => x.Id == nSection_Id).FirstOrDefault().Class_Id;
                                    staff_TimeTable.Section_Id_Period1 = Convert.ToInt16(data[nRowCount][0]);
                                    staff_TimeTable.Section_Id_Period2 = Convert.ToInt16(data[nRowCount][1]);
                                    staff_TimeTable.Section_Id_Period3 = Convert.ToInt16(data[nRowCount][2]);
                                    staff_TimeTable.Section_Id_Period4 = Convert.ToInt16(data[nRowCount][3]);
                                    staff_TimeTable.Section_Id_Period5 = Convert.ToInt16(data[nRowCount][4]);
                                    staff_TimeTable.Section_Id_Period6 = Convert.ToInt16(data[nRowCount][5]);
                                    staff_TimeTable.Section_Id_Period7 = Convert.ToInt16(data[nRowCount][6]);
                                    staff_TimeTable.Section_Id_Period8 = Convert.ToInt16(data[nRowCount][7]);
                                    staff_TimeTable.Week       = nRowCount + 1;
                                    staff_TimeTable.Created_By = 5;
                                    staff_TimeTable.Created_On = DateTime.Now;
                                    staff_TimeTable.Is_Active  = true;

                                    dbcontext.Staff_TimeTable.Add(staff_TimeTable);
                                    dbcontext.SaveChanges();
                                }
                                else
                                {
                                    var staff_TimeTable_Id_ToBeModified = dbcontext.Staff_TimeTable.Where(x => x.Staff_Id == nStaff_Id && x.Academic_Year == nAcademic_Year && (x.Is_Deleted == null || x.Is_Deleted == false) && x.Week == (nRowCount + 1)).FirstOrDefault().Id;

                                    var Staff_TimeTable_ToBeModified = dbcontext.Staff_TimeTable.Find(staff_TimeTable_Id_ToBeModified);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period1 = Convert.ToInt16(data[nRowCount][0]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period2 = Convert.ToInt16(data[nRowCount][1]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period3 = Convert.ToInt16(data[nRowCount][2]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period4 = Convert.ToInt16(data[nRowCount][3]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period5 = Convert.ToInt16(data[nRowCount][4]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period6 = Convert.ToInt16(data[nRowCount][5]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period7 = Convert.ToInt16(data[nRowCount][6]);
                                    Staff_TimeTable_ToBeModified.Section_Id_Period8 = Convert.ToInt16(data[nRowCount][7]);
                                    Staff_TimeTable_ToBeModified.Updated_By         = 5;
                                    Staff_TimeTable_ToBeModified.Updated_On         = DateTime.Now;

                                    dbcontext.Entry(Staff_TimeTable_ToBeModified).State = EntityState.Modified;
                                    dbcontext.SaveChanges();
                                }
                                if (nRowCount == (data.Length - 1))
                                {
                                    transaction.Commit();
                                    sReturnText = "OK";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        sReturnText = ex.InnerException.Message.ToString();
                    }
                }
            }
            return(Json(sReturnText, JsonRequestBehavior.AllowGet));
        }
Beispiel #15
0
        public JsonResult SaveAttendanceForClass(List <string[]> myData)
        {
            int nUser_Id;

            nStudentIdArr = (long[])TempData.Peek("StudentIdArr");

            string   sReturnText = string.Empty;
            DateTime termEndDate;
            DateTime termStartDate;

            using (var dbcontext = new SchoolERPDBContext())
            {
                //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
                nUser_Id = 4;
            }
            int nCount   = myData.ToList().Count;
            int nTerm_Id = Convert.ToInt16(TempData.Peek("Term_Id_For_Attendance"));

            int nLoopCount = 0;

            using (var dbcontext = new SchoolERPDBContext())
            {
                termEndDate   = dbcontext.Term.Where(x => x.Id == nTerm_Id).ToList()[0].To_Date;
                termStartDate = dbcontext.Term.Where(x => x.Id == nTerm_Id).ToList()[0].From_Date;
            }

            TimeSpan difference = termEndDate - termStartDate;
            int      nDays      = Convert.ToInt16(difference.TotalDays);

            nDays = nDays + 1;

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        for (int iAttendanceLoopCount = 1; iAttendanceLoopCount < myData.ToList().Count(); iAttendanceLoopCount++)
                        {
                            for (int nColumnCount = 3; nColumnCount < 3 + nDays; nColumnCount++)
                            {
                                Attendance newAttendance = new Attendance();
                                newAttendance.Academic_Year = Convert.ToInt32(GetAcademicYear());
                                if (Convert.ToString(myData[iAttendanceLoopCount][nColumnCount]) != "P" && Convert.ToString(myData[iAttendanceLoopCount][nColumnCount]) != "H" && Convert.ToString(myData[iAttendanceLoopCount][nColumnCount]) != "PH" && Convert.ToString(myData[iAttendanceLoopCount][nColumnCount]) != null)
                                {
                                    newAttendance.Class_Id     = Convert.ToInt16(TempData.Peek("Class_Id_For_Attendance"));
                                    newAttendance.Section_Id   = Convert.ToInt16(TempData.Peek("Section_Id_For_Attendance"));
                                    newAttendance.Leave_Date   = termStartDate.AddDays(nColumnCount - 3);
                                    newAttendance.Student_Id   = nStudentIdArr[iAttendanceLoopCount - 1];
                                    newAttendance.Leave_Reason = myData[iAttendanceLoopCount][nColumnCount];
                                    newAttendance.Is_Active    = true;
                                    //newAttendance.Is_Deleted = false;
                                    newAttendance.Term_Id       = Convert.ToInt16(TempData.Peek("Term_Id_For_Attendance"));
                                    newAttendance.Created_By    = 4;
                                    newAttendance.Created_On    = DateTime.Now;
                                    newAttendance.Academic_Year = Convert.ToInt16(TempData.Peek("Year_For_Attendance"));

                                    if (dbcontext.Attendance.Where(a => a.Student_Id == newAttendance.Student_Id && a.Academic_Year == newAttendance.Academic_Year && a.Leave_Date == newAttendance.Leave_Date && (a.Is_Deleted == false || a.Is_Deleted == null)).Count() == 0)
                                    {
                                        dbcontext.Attendance.Add(newAttendance);
                                        dbcontext.SaveChanges();
                                    }
                                    else
                                    {
                                        var attendanceId = dbcontext.Attendance.Where(a => a.Student_Id == newAttendance.Student_Id && a.Academic_Year == newAttendance.Academic_Year && a.Leave_Date == newAttendance.Leave_Date && (a.Is_Deleted == false || a.Is_Deleted == null)).ToList()[0].Id;

                                        Attendance attendanceToBeUpdated = dbcontext.Attendance.Find(attendanceId);

                                        attendanceToBeUpdated.Leave_Reason = myData[iAttendanceLoopCount][nColumnCount];
                                        attendanceToBeUpdated.Is_Active    = true;

                                        dbcontext.Entry(attendanceToBeUpdated).State = EntityState.Modified;
                                        dbcontext.SaveChanges();
                                    }
                                }
                                else
                                {
                                    newAttendance.Leave_Date = termStartDate.AddDays(nColumnCount - 3);
                                    string LeaveReason = myData[iAttendanceLoopCount][nColumnCount];
                                    if (dbcontext.Attendance.Where(a => a.Student_Id == newAttendance.Student_Id && a.Academic_Year == newAttendance.Academic_Year && a.Leave_Date == newAttendance.Leave_Date && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Leave_Reason != LeaveReason).Count() > 0)
                                    {
                                        var attendanceId = dbcontext.Attendance.Where(a => a.Student_Id == newAttendance.Student_Id && a.Academic_Year == newAttendance.Academic_Year && a.Leave_Date == newAttendance.Leave_Date && (a.Is_Deleted == false || a.Is_Deleted == null)).ToList()[0].Id;

                                        Attendance attendanceToBeUpdated = dbcontext.Attendance.Find(attendanceId);

                                        attendanceToBeUpdated.Leave_Reason = myData[iAttendanceLoopCount][nColumnCount];
                                        attendanceToBeUpdated.Is_Active    = false;
                                        attendanceToBeUpdated.Is_Deleted   = true;

                                        dbcontext.Entry(attendanceToBeUpdated).State = EntityState.Modified;
                                        dbcontext.SaveChanges();
                                    }
                                }

                                if (iAttendanceLoopCount == myData.ToList().Count() - 1 && nColumnCount == 3 + (nDays - 1))
                                {
                                    transaction.Commit();
                                    sReturnText = "OK";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
                return(Json(sReturnText, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #16
0
        public JsonResult SaveFeeConfiguration(List <string[]> myData, string Academic_Year)
        {
            Fee_Configuration newFeeConfig = new Fee_Configuration();
            int nUser_Id;

            nFeeIdArr = (int[])TempData.Peek("FeeIdArr");

            string sReturnText = string.Empty;

            using (var dbcontext = new SchoolERPDBContext())
            {
                //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
                nUser_Id = 4;
            }
            int nCount = myData.ToList().Count;

            int nLoopCount = 0;

            //var matchingvalues = myData.Where(stringToCheck => stringToCheck.Contains("Hostel Fees"));

            string hostelFeesIindex = Convert.ToString(myData.FindIndex(s => s.Contains("Hostel Fees")));


            //var hostelFeesIndex = myData.FindIndex(matchingvalues);

            string schoolBusIndex = Convert.ToString(myData.FindIndex(s => s.Contains("School Bus")));


            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        for (int i = 0; i < nCount - 1; i++)
                        {
                            if (myData[i][0] != string.Empty && myData[i][0] != null)
                            {
                                for (int j = 0; j < 4; j++)
                                {
                                    newFeeConfig.Class_Id      = Convert.ToInt16(TempData.Peek("Class_Id"));
                                    newFeeConfig.Academic_Year = Convert.ToInt64(myData[i][1]);
                                    newFeeConfig.Fee_Id        = Convert.ToInt16(nFeeIdArr[i]);
                                    newFeeConfig.Is_Active     = true;
                                    if (j == 0)
                                    {
                                        newFeeConfig.Frequency = 1;
                                        newFeeConfig.Amount    = (myData[i][2] == "") ? 0 : Convert.ToDecimal(myData[i][2]);

                                        newFeeConfig.Total = Convert.ToDecimal(myData[nCount - 1][2]);

                                        if (hostelFeesIindex != string.Empty)
                                        {
                                            int nhostelFeesIindex = Convert.ToInt16(hostelFeesIindex);

                                            newFeeConfig.Total_Excluding_HostelFees = Convert.ToDecimal(myData[nCount - 1][2]) - Convert.ToDecimal(myData[nhostelFeesIindex][2]);
                                        }


                                        if (schoolBusIndex != string.Empty)
                                        {
                                            int nschoolBusIndex = Convert.ToInt16(schoolBusIndex);

                                            newFeeConfig.Total_Excluding_Bus_Fees = Convert.ToDecimal(myData[nCount - 1][2]) - Convert.ToDecimal(myData[nschoolBusIndex][2]);
                                        }
                                    }
                                    else if (j == 1)
                                    {
                                        newFeeConfig.Frequency = 2;
                                        newFeeConfig.Amount    = (myData[i][3] == "") ? 0 : Convert.ToDecimal(myData[i][3]);
                                        newFeeConfig.Total     = Convert.ToDecimal(myData[nCount - 1][3]);
                                        if (hostelFeesIindex != string.Empty)
                                        {
                                            int nhostelFeesIindex = Convert.ToInt16(hostelFeesIindex);

                                            newFeeConfig.Total_Excluding_HostelFees = Convert.ToDecimal(myData[nCount - 1][3]) - Convert.ToDecimal(myData[nhostelFeesIindex][3]);
                                        }


                                        if (schoolBusIndex != string.Empty)
                                        {
                                            int nschoolBusIndex = Convert.ToInt16(schoolBusIndex);

                                            newFeeConfig.Total_Excluding_Bus_Fees = Convert.ToDecimal(myData[nCount - 1][3]) - Convert.ToDecimal(myData[nschoolBusIndex][3]);
                                        }
                                    }
                                    else if (j == 2)
                                    {
                                        newFeeConfig.Frequency = 3;
                                        newFeeConfig.Amount    = (myData[i][4] == "") ? 0 : Convert.ToDecimal(myData[i][4]);
                                        newFeeConfig.Total     = Convert.ToDecimal(myData[nCount - 1][4]);
                                        if (hostelFeesIindex != string.Empty)
                                        {
                                            int nhostelFeesIindex = Convert.ToInt16(hostelFeesIindex);

                                            newFeeConfig.Total_Excluding_HostelFees = Convert.ToDecimal(myData[nCount - 1][4]) - Convert.ToDecimal(myData[nhostelFeesIindex][4]);
                                        }


                                        if (schoolBusIndex != string.Empty)
                                        {
                                            int nschoolBusIndex = Convert.ToInt16(schoolBusIndex);

                                            newFeeConfig.Total_Excluding_Bus_Fees = Convert.ToDecimal(myData[nCount - 1][4]) - Convert.ToDecimal(myData[nschoolBusIndex][4]);
                                        }
                                    }
                                    else
                                    {
                                        newFeeConfig.Frequency = 4;
                                        newFeeConfig.Amount    = (myData[i][5] == "") ? 0 : Convert.ToDecimal(myData[i][5]);
                                        newFeeConfig.Total     = Convert.ToDecimal(myData[nCount - 1][5]);
                                        if (hostelFeesIindex != string.Empty)
                                        {
                                            int nhostelFeesIindex = Convert.ToInt16(hostelFeesIindex);

                                            newFeeConfig.Total_Excluding_HostelFees = Convert.ToDecimal(myData[nCount - 1][5]) - Convert.ToDecimal(myData[nhostelFeesIindex][5]);
                                        }


                                        if (schoolBusIndex != string.Empty)
                                        {
                                            int nschoolBusIndex = Convert.ToInt16(schoolBusIndex);

                                            newFeeConfig.Total_Excluding_Bus_Fees = Convert.ToDecimal(myData[nCount - 1][5]) - Convert.ToDecimal(myData[nschoolBusIndex][5]);
                                        }
                                    }
                                    newFeeConfig.Created_By = nUser_Id;
                                    newFeeConfig.Created_On = DateTime.Now;
                                    if (dbcontext.Fee_Configuration.Where(a => a.Class_Id == newFeeConfig.Class_Id && a.Fee_Id == newFeeConfig.Fee_Id && a.Academic_Year == newFeeConfig.Academic_Year && a.Frequency == newFeeConfig.Frequency && (a.Is_Deleted == false || a.Is_Deleted == null)).Count() == 0)
                                    {
                                        dbcontext.Fee_Configuration.Add(newFeeConfig);
                                        dbcontext.SaveChanges();
                                        if (nCount - 3 == i && j == 3)
                                        {
                                            transaction.Commit();
                                            sReturnText = "OK";
                                        }
                                    }
                                    else
                                    {
                                        var feeConfigId = dbcontext.Fee_Configuration.Where(x => x.Fee_Id == newFeeConfig.Fee_Id && x.Class_Id == newFeeConfig.Class_Id && x.Academic_Year == newFeeConfig.Academic_Year && x.Frequency == newFeeConfig.Frequency && (x.Is_Deleted == false || x.Is_Deleted == null)).FirstOrDefault().Id;

                                        Fee_Configuration feeConfigToBeUpdated = dbcontext.Fee_Configuration.Find(feeConfigId);

                                        feeConfigToBeUpdated.Fee_Id                     = newFeeConfig.Fee_Id;
                                        feeConfigToBeUpdated.Class_Id                   = newFeeConfig.Class_Id;
                                        feeConfigToBeUpdated.Frequency                  = newFeeConfig.Frequency;
                                        feeConfigToBeUpdated.Amount                     = newFeeConfig.Amount;
                                        feeConfigToBeUpdated.Academic_Year              = newFeeConfig.Academic_Year;
                                        feeConfigToBeUpdated.Total                      = newFeeConfig.Total;
                                        feeConfigToBeUpdated.Is_Active                  = true;
                                        feeConfigToBeUpdated.Total_Excluding_Bus_Fees   = newFeeConfig.Total_Excluding_Bus_Fees;
                                        feeConfigToBeUpdated.Total_Excluding_HostelFees = newFeeConfig.Total_Excluding_HostelFees;

                                        dbcontext.Entry(feeConfigToBeUpdated).State = EntityState.Modified;
                                        dbcontext.SaveChanges();

                                        if (nCount - 3 == i && j == 3)
                                        {
                                            transaction.Commit();
                                            sReturnText = "Updated";
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
                return(Json(sReturnText, JsonRequestBehavior.AllowGet));
            }
        }