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 JsonResult CreateInventory(string Inventory_Item_Name)
 {
     try
     {
         Inventory newInventory = new Inventory();
         int       nUser_Id;
         using (var dbcontext = new SchoolERPDBContext())
         {
             //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
             nUser_Id = 5;
         }
         using (var dbcontext = new SchoolERPDBContext())
         {
             newInventory.Name          = Inventory_Item_Name;
             newInventory.Academic_Year = GetAcademicYear();
             newInventory.Is_Active     = true;
             newInventory.Created_By    = nUser_Id;
             newInventory.Created_On    = DateTime.Now;
             if (dbcontext.Inventory.Where(a => a.Name == Inventory_Item_Name.Trim().ToString() && a.Is_Deleted == false).Count() == 0)
             {
                 dbcontext.Inventory.Add(newInventory);
                 dbcontext.SaveChanges();
                 return(Json("OK", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Inventory Item Already Exists.", JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception e)
     {
         return(Json("Failure", JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult HostelRoomList(Hostel_Room hostel_Room)
        {
            string sReturn_Text = string.Empty;

            try
            {
                hostel_Room.Created_By = 5;
                hostel_Room.Created_On = DateTime.Now;
                hostel_Room.Is_Active  = true;
                long nYear = GetAcademicYear();

                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (dbcontext.Hostel_Room.Where(x => x.Room_No == hostel_Room.Room_No && (x.Is_Deleted == false || x.Is_Deleted == null) && x.Academic_Year == nYear).Count() == 0)
                    {
                        dbcontext.Hostel_Room.Add(hostel_Room);
                        dbcontext.SaveChanges();
                        sReturn_Text = "OK";
                    }
                    else
                    {
                        sReturn_Text = "Room No Already Exists";
                    }
                }
            }
            catch (Exception ex)
            {
                sReturn_Text = ex.InnerException.Message.ToString();
            }
            return(Json(sReturn_Text, JsonRequestBehavior.AllowGet));
        }
 public JsonResult CreateClass(string Class_Name)
 {
     try
     {
         Class newClass = new Class();
         int   nUser_Id;
         using (var dbcontext = new SchoolERPDBContext())
         {
             nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id;;
         }
         using (var dbcontext = new SchoolERPDBContext())
         {
             newClass.Name          = Class_Name;
             newClass.Academic_Year = (DateTime.Now.Month <= 4) ? DateTime.Now.Year - 1 : DateTime.Now.Year;
             newClass.Is_Active     = true;
             newClass.Created_By    = nUser_Id;
             newClass.Created_On    = DateTime.Now;
             if (dbcontext.User_Roles.Where(a => a.Name == Class_Name.Trim().ToString() && a.Is_Deleted == false).Count() == 0)
             {
                 dbcontext.Class.Add(newClass);
                 dbcontext.SaveChanges();
                 return(Json("OK", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Class Already Exists.", JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception e)
     {
         return(Json("Failure", JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult TransportList(Transport transport)
        {
            string sReturn_Text = string.Empty;

            try
            {
                transport.Created_By = 5;
                transport.Created_On = DateTime.Now;
                transport.Is_Active  = true;
                long nYear = GetAcademicYear();

                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (dbcontext.Transport.Where(x => x.Name == transport.Name && (x.Is_Deleted == false || x.Is_Deleted == null) && x.Academic_Year == nYear).Count() == 0)
                    {
                        dbcontext.Transport.Add(transport);
                        dbcontext.SaveChanges();
                        sReturn_Text = "OK";
                    }
                    else
                    {
                        sReturn_Text = "Vehicle No Already Exists";
                    }
                }
            }
            catch (Exception ex)
            {
                sReturn_Text = ex.InnerException.Message.ToString();
            }
            return(Json(sReturn_Text, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddTransportDestination(TransportDestination transport_Destination)
        {
            string sReturnText = string.Empty;
            long   nYear       = GetAcademicYear();

            try
            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (dbcontext.TransportDestination.Where(x => x.Name == transport_Destination.Name && x.Academic_Year == transport_Destination.Academic_Year && (x.Is_Deleted == null || x.Is_Deleted == false)).Count() == 0)
                    {
                        transport_Destination.Created_By = 5;
                        transport_Destination.Created_On = DateTime.Now;
                        transport_Destination.Is_Active  = true;
                        //transport_Destination.Is_Deleted = false;
                        transport_Destination.Academic_Year = nYear;

                        dbcontext.TransportDestination.Add(transport_Destination);
                        dbcontext.SaveChanges();
                        sReturnText = "OK";
                    }
                    else
                    {
                        sReturnText = "Transport Destination Already Exists";
                    }
                }
            }
            catch (Exception ex)
            {
                sReturnText = ex.InnerException.Message.ToString();
            }
            return(Json(sReturnText, JsonRequestBehavior.AllowGet));
        }
        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 ActionResult CreateStudentOtherDetails(Student_Other_Details Student_Other_Detail)
        {
            string sReturn_Text = string.Empty;
            Student_Other_Details newStudentOtherDetailsToBeAdded = new Student_Other_Details();

            newStudentOtherDetailsToBeAdded = Student_Other_Detail;
            newStudentOtherDetailsToBeAdded.Mother_Occupation_Id = Student_Other_Detail.Mother_Occupation_Id;
            newStudentOtherDetailsToBeAdded.Father_Occupation_Id = Student_Other_Detail.Father_Occupation_Id;
            newStudentOtherDetailsToBeAdded.Is_Active            = true;
            newStudentOtherDetailsToBeAdded.Created_By           = 5;
            //newStudentOtherDetailsToBeAdded.Student_Id = 113;
            newStudentOtherDetailsToBeAdded.Student_Id = Convert.ToInt64(TempData.Peek("Student_Id"));
            newStudentOtherDetailsToBeAdded.Created_On = DateTime.Now;

            try
            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    dbcontext.Student_Other_Details.Add(newStudentOtherDetailsToBeAdded);
                    dbcontext.SaveChanges();
                    sReturn_Text = "Student Other Details Saved Successfully";
                }
            }
            catch (Exception ex)
            {
                sReturn_Text = "Error";
            }

            return(Json(sReturn_Text, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
 public JsonResult CreateFee(string Fee_Name)
 {
     try
     {
         Fee newFee = new Fee();
         int nUser_Id;
         using (var dbcontext = new SchoolERPDBContext())
         {
             nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id;;
         }
         using (var dbcontext = new SchoolERPDBContext())
         {
             newFee.Name          = Fee_Name;
             newFee.Academic_Year = (DateTime.Now.Month <= 4) ? DateTime.Now.Year - 1 : DateTime.Now.Year;
             newFee.Is_Active     = true;
             newFee.Created_By    = nUser_Id;
             newFee.Created_On    = DateTime.Now;
             if (dbcontext.Fee.Where(a => a.Name.Replace(" ", "").Trim().ToString() == Fee_Name.Replace(" ", "").Trim().ToString() && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == newFee.Academic_Year).Count() == 0)
             {
                 dbcontext.Fee.Add(newFee);
                 dbcontext.SaveChanges();
                 return(Json("OK", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Fee Already Exists.", JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception e)
     {
         return(Json("Failure", JsonRequestBehavior.AllowGet));
     }
 }
        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 JsonResult CreateSection(string Class_Ids, string Section_Name)
        {
            string[] ClassIdStrArr = Class_Ids.Split(',');
            Section  newSection    = new Section();
            int      nUser_Id;
            string   sReturnText = string.Empty;

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

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        foreach (string ClassId in ClassIdStrArr)
                        {
                            newSection.Class_Id      = Convert.ToInt32(ClassId);
                            newSection.Name          = Section_Name;
                            newSection.Academic_Year = (DateTime.Now.Month <= 4) ? DateTime.Now.Year - 1 : DateTime.Now.Year;
                            newSection.Is_Active     = true;
                            newSection.Created_By    = nUser_Id;
                            newSection.Created_On    = DateTime.Now;
                            int nClassId = Convert.ToInt32(ClassId);
                            if (dbcontext.Section.Where(a => a.Class_Id == nClassId && a.Name.Trim().Replace(" ", "") == Section_Name.Trim().Replace(" ", "").ToString() && (a.Is_Deleted == false || a.Is_Deleted == null)).Count() == 0)
                            {
                                dbcontext.Section.Add(newSection);
                                dbcontext.SaveChanges();
                                sReturnText = "OK";
                                nLoopCount++;
                                if (nLoopCount == nCount)
                                {
                                    transaction.Commit();
                                }
                            }
                            else
                            {
                                sReturnText = "Section Already Exists For Class";
                                transaction.Rollback();
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                    }
                }
                return(Json(sReturnText, JsonRequestBehavior.AllowGet));
            }
        }
        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"));
        }
Ejemplo n.º 13
0
        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 List <Student_SiblingList_ViewModel> GetStudentSiblingDetails(Student_Sibling_Detail stuSiblingDetail)
        {
            long nYear       = GetAcademicYear();
            long nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id"));

            stuSiblingDetail.Student_Id = nStudent_Id;
            List <Student_SiblingList_ViewModel> addedStudentSiblingDetails = new List <Student_SiblingList_ViewModel>();

            try
            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (stuSiblingDetail != null)
                    {
                        dbcontext.Student_Sibling_Detail.Add(stuSiblingDetail);
                        dbcontext.SaveChanges();
                    }
                }

                using (var dbcontext = new SchoolERPDBContext())
                {
                    addedStudentSiblingDetails = (from stu in dbcontext.Student
                                                  join studentSiblingDetail in dbcontext.Student_Sibling_Detail on stu.Student_Id equals studentSiblingDetail.Sibling_Student_Id
                                                  join cls in dbcontext.Class on stu.Class_Id equals cls.Id
                                                  join sec in dbcontext.Section on stu.Section_Id equals sec.Id
                                                  where studentSiblingDetail.Student_Id == nStudent_Id && studentSiblingDetail.Academic_Year == nYear && studentSiblingDetail.Is_Deleted == null || studentSiblingDetail.Is_Deleted == false
                                                  select new Student_SiblingList_ViewModel
                    {
                        Sibling_Detail_Id = studentSiblingDetail.Sibling_Detail_Id,
                        Class = cls.Name,
                        Section = sec.Name,
                        Student_Name = stu.First_Name + "  " + stu.Last_Name,
                        Roll_No = stu.Roll_No,
                        Updated_On = studentSiblingDetail.Updated_On,
                        Student_Id = studentSiblingDetail.Student_Id,
                        Sibling_Relation = studentSiblingDetail.Sibling_Relation
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
            }

            return(addedStudentSiblingDetails);
        }
        public ActionResult AddAssignmentForClassAndSection(Assignment Assignment)
        {
            long nYear = GetAcademicYear();

            Assignment.Created_By = 5;
            Assignment.Created_On = DateTime.Now;
            string sReturn_Text = string.Empty;
            int    nAssignment_Id;

            try

            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (dbcontext.Assignment.ToList().Count == 0)
                    {
                        nAssignment_Id = 1;
                    }
                    else
                    {
                        nAssignment_Id = Convert.ToInt32(dbcontext.Assignment.Max(x => x.Id) + 1);


                        TempData["Assignment_Id"] = nAssignment_Id;
                        TempData.Keep("Assignment_Id");
                    }
                }



                using (var dbcontext = new SchoolERPDBContext())
                {
                    dbcontext.Assignment.Add(Assignment);
                    dbcontext.SaveChanges();
                    sReturn_Text = "OK";
                }
            }
            catch (Exception ex)
            {
                sReturn_Text = ex.InnerException.Message.ToString();
            }
            return(Json(sReturn_Text, JsonRequestBehavior.AllowGet));;
        }
        public ActionResult SaveTransportRoute(Transport_Destination_Detail Transport_Destination_Detail, string[] Route_Id)
        {
            string sReturn_text = string.Empty;

            using (var dbcontext = new SchoolERPDBContext())
            {
                //using (var transaction = dbcontext.Database.BeginTransaction())
                //{
                try
                {
                    if (dbcontext.Transport_Destination_Detail.Where(x => x.Name == Transport_Destination_Detail.Name && x.Academic_Year == Transport_Destination_Detail.Academic_Year && (x.Is_Deleted == null || x.Is_Deleted == false)).Count() == 0)
                    {
                        for (int nStopCount = 1; nStopCount <= Route_Id.Count(); nStopCount++)
                        {
                            int          stop_Value   = Convert.ToInt16(Route_Id[nStopCount - 1]);
                            PropertyInfo propertyInfo = Transport_Destination_Detail.GetType().GetProperty("Stop_" + nStopCount);
                            // make sure object has the property we are after
                            if (propertyInfo != null)
                            {
                                propertyInfo.SetValue(Transport_Destination_Detail, stop_Value, null);
                            }
                        }
                        Transport_Destination_Detail.Created_By = 5;
                        Transport_Destination_Detail.Created_On = DateTime.Now;
                        dbcontext.Transport_Destination_Detail.Add(Transport_Destination_Detail);
                        dbcontext.SaveChanges();
                        sReturn_text = "OK";
                    }
                    else
                    {
                        sReturn_text = "Exists";
                    }
                }
                catch (Exception ex)
                {
                    sReturn_text = ex.InnerException.Message.ToString();
                }
                //}
            }
            return(Json(sReturn_text, JsonRequestBehavior.AllowGet));
        }
        public List <Student_PrevSchoolList_ViewModel> GetStudentPrevSchoolDetails(Student_Prev_School_Details stuPrevSchoolDetail)
        {
            long nAcademicYear = GetAcademicYear();
            long nStudent_Id   = Convert.ToInt64(TempData.Peek("Student_Id"));

            stuPrevSchoolDetail.Student_Id = nStudent_Id;
            List <Student_PrevSchoolList_ViewModel> addedStudentPrevSchoolDetails = new List <Student_PrevSchoolList_ViewModel>();

            try
            {
                using (var dbcontext = new SchoolERPDBContext())
                {
                    dbcontext.Student_Prev_School_Detail.Add(stuPrevSchoolDetail);
                    dbcontext.SaveChanges();
                }

                using (var dbcontext = new SchoolERPDBContext())
                {
                    addedStudentPrevSchoolDetails = (from school in dbcontext.School
                                                     join prevSchooldetails in dbcontext.Student_Prev_School_Detail on school.Id equals prevSchooldetails.School_Id
                                                     where prevSchooldetails.Student_Id == nStudent_Id && prevSchooldetails.Academic_Year == nAcademicYear && prevSchooldetails.Is_Deleted == null || prevSchooldetails.Is_Deleted == false
                                                     select new Student_PrevSchoolList_ViewModel
                    {
                        Id = prevSchooldetails.Student_PrevSchool_Id,
                        Name = school.Name,
                        From_Year = prevSchooldetails.From_Year,
                        To_Year = prevSchooldetails.To_Year,
                        Leaving_Reason = prevSchooldetails.Leaving_Reason,
                        Updated_On = prevSchooldetails.Updated_On,
                        Student_Id = prevSchooldetails.Student_Id,
                        Comments = prevSchooldetails.Comments
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
            }

            return(addedStudentPrevSchoolDetails);
        }
 public ActionResult AddInventoryDetail(Inventory_Item_Detail Inventory_Item_Detail)
 {
     try
     {
         Inventory_Item_Detail newInventory_Item_Detail = new Inventory_Item_Detail();
         int  nUser_Id;
         long nYear = GetAcademicYear();
         using (var dbcontext = new SchoolERPDBContext())
         {
             //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
             nUser_Id = 5;
         }
         using (var dbcontext = new SchoolERPDBContext())
         {
             //newInventory_Item_Detail.Inventory_id = Inventory_Item_Detail.Inventory_id;
             //newInventory_Item_Detail.Academic_Year = GetAcademicYear();
             //newInventory_Item_Detail.Is_Active = true;
             //newInventory_Item_Detail.Created_By = nUser_Id;
             //newInventory_Item_Detail.Created_On = DateTime.Now;
             Inventory_Item_Detail.Created_By    = 5;
             Inventory_Item_Detail.Created_On    = DateTime.Now;
             Inventory_Item_Detail.Academic_Year = GetAcademicYear();
             if (dbcontext.Inventory_Item_Detail.Where(a => a.Inventory_id == Inventory_Item_Detail.Inventory_id && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == nYear).Count() == 0)
             {
                 dbcontext.Inventory_Item_Detail.Add(Inventory_Item_Detail);
                 dbcontext.SaveChanges();
                 return(Json("OK", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Already Exists", JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception e)
     {
         return(Json("Failure", JsonRequestBehavior.AllowGet));
     }
 }
 public JsonResult CreateRole(string Role_Name)
 {
     try
     {
         User_Role newUserRole = new User_Role();
         int       nUser_Id;
         using (var dbcontext = new SchoolERPDBContext())
         {
             nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id;;
         }
         using (var dbcontext = new SchoolERPDBContext())
         {
             string    role_name    = Role_Name;
             Role_Type userRoleType = (Role_Type)Enum.Parse(typeof(Role_Type), role_name);
             int       nroleId      = (int)userRoleType;
             newUserRole.Name          = Role_Name;
             newUserRole.Role_Id       = nroleId;
             newUserRole.Academic_Year = (DateTime.Now.Month <= 4) ? DateTime.Now.Year - 1 : DateTime.Now.Year;
             newUserRole.Is_Active     = true;
             newUserRole.Created_By    = nUser_Id;
             newUserRole.Created_On    = DateTime.Now;
             if (dbcontext.User_Roles.Where(a => a.Name == Role_Name.Trim().ToString() && a.Is_Deleted == false).Count() == 0)
             {
                 dbcontext.User_Roles.Add(newUserRole);
                 dbcontext.SaveChanges();
                 return(Json("OK", JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json("Role Already Exists.", JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception e)
     {
         return(Json("Failure", JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult AddUser(User user)
        {
            string sReturnText = string.Empty;

            try
            {
                user.Created_By    = 5;
                user.Created_On    = DateTime.Now;
                user.Is_Active     = true;
                user.Academic_Year = GetAcademicYear();
                string sEncryptedPassword = PasswordEncryptAndDecryptController.Encrypt(user.Password);
                user.Password = sEncryptedPassword;
                using (var dbcontext = new SchoolERPDBContext())
                {
                    if (dbcontext.Users.Any(o => o.User_Id == user.User_Id))
                    {
                        sReturnText = "Email Already Exists";
                    }
                    else
                    {
                        if (dbcontext.Users.Where(a => a.User_Id == user.User_Id.Trim().ToString() && (a.Is_Deleted == false || a.Is_Deleted == null)).Count() == 0)
                        {
                            dbcontext.Users.Add(user);
                            dbcontext.SaveChanges();
                            sReturnText = "OK";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sReturnText = ex.InnerException.Message.ToString();
            }

            return(Json(sReturnText, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 22
0
        public ActionResult AddHoliday(string Name, string From_Date, string To_Date, string Year)
        {
            DataTable dt = new DataTable();

            int nUser_Id;
            int nYear = Convert.ToInt16(Year);

            using (var dbcontext = new SchoolERPDBContext())
            {
                //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
                nUser_Id = 5;
            }
            DateTime dtFromDate = DateTime.ParseExact(From_Date, "dd/MM/yyyy", null);
            DateTime dtToDate   = DateTime.ParseExact(To_Date, "dd/MM/yyyy", null);
            TimeSpan ts         = dtToDate - dtFromDate;
            int      nDays      = Convert.ToInt16(ts.TotalDays) + 1;

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        for (int nHolidayCount = 0; nHolidayCount < nDays; nHolidayCount++)
                        {
                            Holiday newHoliday = new Holiday();
                            newHoliday.Name          = Name;
                            newHoliday.Academic_Year = nYear;
                            newHoliday.Is_Active     = true;
                            newHoliday.Created_By    = nUser_Id;
                            newHoliday.Created_On    = DateTime.Now;
                            newHoliday.Holiday_Date  = dtFromDate.AddDays(nHolidayCount);

                            newHoliday.From_Date = dtFromDate;
                            newHoliday.To_Date   = dtToDate;

                            //if (dbcontext.Holiday.Where(a => a.Name.Replace(" ", "").Trim().ToString() == Name.Replace(" ", "").Trim().ToString() && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == nYear).Count() == 0)
                            if (dbcontext.Holiday.Where(a => a.From_Date >= newHoliday.Holiday_Date && a.To_Date <= newHoliday.Holiday_Date && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == nYear).Count() == 0)
                            {
                                dbcontext.Holiday.Add(newHoliday);
                                dbcontext.SaveChanges();
                                //return Json("OK", JsonRequestBehavior.AllowGet);
                            }
                            else
                            {
                                return(Json("Holiday Already Exists.", JsonRequestBehavior.AllowGet));
                            }

                            if (nHolidayCount == (nDays - 1))
                            {
                                transaction.Commit();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        return(Json("Failure", JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json("OK", JsonRequestBehavior.AllowGet));
            }



            //return View();
        }
        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));
            }
        }
Ejemplo n.º 24
0
        public ActionResult AddStaffAttendance(string Staff_Id, string From_Date, string To_Date, string Reason)
        {
            DataTable dt = new DataTable();

            int    nUser_Id;
            string sReturnText = string.Empty;
            long   nYear       = GetAcademicYear();

            using (var dbcontext = new SchoolERPDBContext())
            {
                //nUser_Id = dbcontext.Users.Where(x => x.User_Id == User.Identity.Name).ToList()[0].Id; ;
                nUser_Id = 5;
            }
            DateTime dtFromDate = DateTime.ParseExact(From_Date, "dd/MM/yyyy", null);
            DateTime dtToDate   = DateTime.ParseExact(To_Date, "dd/MM/yyyy", null);
            TimeSpan ts         = dtToDate - dtFromDate;
            int      nDays      = Convert.ToInt16(ts.TotalDays) + 1;

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        for (int nHolidayCount = 0; nHolidayCount < nDays; nHolidayCount++)
                        {
                            Staff_Attendance newStaffAttendance = new Staff_Attendance();
                            newStaffAttendance.Staff_Id = Convert.ToInt16(Staff_Id);

                            newStaffAttendance.Academic_Year = nYear;
                            newStaffAttendance.Is_Active     = true;
                            newStaffAttendance.Created_By    = nUser_Id;
                            newStaffAttendance.Created_On    = DateTime.Now;
                            newStaffAttendance.Leave_Date    = dtFromDate.AddDays(nHolidayCount);

                            newStaffAttendance.From_Date = dtFromDate;
                            newStaffAttendance.To_Date   = dtToDate;
                            newStaffAttendance.Reason    = Reason;

                            //if (dbcontext.Holiday.Where(a => a.Name.Replace(" ", "").Trim().ToString() == Name.Replace(" ", "").Trim().ToString() && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == nYear).Count() == 0)
                            if (dbcontext.Staff_Attendance.Where(x => x.Staff_Id == newStaffAttendance.Staff_Id && x.Leave_Date == newStaffAttendance.Leave_Date && (x.Is_Deleted == null || x.Is_Deleted == null) && x.Academic_Year == nYear).Count() == 0)
                            //if (dbcontext.Holiday.Where(a => a.From_Date >= newStaffAttendance.Leave_Date && a.To_Date <= newStaffAttendance.Leave_Date && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == nYear).Count() == 0)
                            {
                                dbcontext.Staff_Attendance.Add(newStaffAttendance);
                                dbcontext.SaveChanges();
                                sReturnText = "OK";
                                //return Json("OK", JsonRequestBehavior.AllowGet);
                            }
                            else
                            {
                                return(Json("Holiday Already Exists.", JsonRequestBehavior.AllowGet));
                            }

                            if (nHolidayCount == (nDays - 1))
                            {
                                transaction.Commit();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        return(Json("Failure", JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(sReturnText, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult CreateStudent(Student formData)

        {
            Student newStudentToBeAdded = new Student();

            newStudentToBeAdded            = formData;
            newStudentToBeAdded.Student_Id = Convert.ToInt64(TempData.Peek("Student_Id"));


            newStudentToBeAdded.Is_Active = true;
            //newStudentToBeAdded.Created_By = GetLoggedInUserId();
            newStudentToBeAdded.Created_By = 4;
            newStudentToBeAdded.Created_On = DateTime.Now;
            string sEmail_Id    = formData.Email_Id;
            string sReturn_Text = string.Empty;
            string sPassword    = CreateRandomPassword(6);

            try
            {
                if (ModelState.IsValid)
                {
                    using (var dbcontext = new SchoolERPDBContext())
                    {
                        //if (dbcontext.Student.Any(o => o.Email_Id == sEmail_Id))
                        //{
                        //	sReturn_Text = "Email Already Exists";
                        //}
                        //else
                        //{
                        dbcontext.Student.Add(newStudentToBeAdded);
                        dbcontext.SaveChanges();


                        MailController oMailController = new MailController();
                        oMailController.SendMail(newStudentToBeAdded.Email_Id, newStudentToBeAdded.First_Name.Substring(0, 4) + newStudentToBeAdded.Student_Id, sPassword);

                        //To create the UserId in the User Table for Login

                        //}
                    }

                    using (var dbcontext = new SchoolERPDBContext())
                    {
                        User newUserToBeAdded = new User();
                        newUserToBeAdded.Name           = newStudentToBeAdded.First_Name + " " + newStudentToBeAdded.Last_Name;
                        newUserToBeAdded.EmailConfirmed = true;
                        newUserToBeAdded.Created_By     = 5;
                        newUserToBeAdded.User_Id        = newStudentToBeAdded.First_Name.Substring(0, 4) + newStudentToBeAdded.Student_Id;
                        newUserToBeAdded.Password       = sPassword;
                        newUserToBeAdded.Is_Active      = true;
                        newUserToBeAdded.Academic_Year  = newStudentToBeAdded.Academic_Year;
                        newUserToBeAdded.Role_Id        = Convert.ToInt16(Role_Type.Student);
                        sReturn_Text = "SuccessFully Added";
                    }
                    //return Json(sReturn_Text, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    foreach (ModelState modelState in ViewData.ModelState.Values)
                    {
                        foreach (ModelError error in modelState.Errors)
                        {
                            sReturn_Text = error.ErrorMessage.ToString();
                            break;
                        }

                        if (sReturn_Text != string.Empty)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                sReturn_Text = "Error";
                //return Json(sReturn_Text, JsonRequestBehavior.AllowGet);
            }

            return(Json(sReturn_Text, 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));
        }
Ejemplo n.º 27
0
        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 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));
        }
Ejemplo n.º 29
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));
            }
        }
Ejemplo n.º 30
0
        public JsonResult ConfigureSubjectsForClass(string[] Class_Ids, string[] Subject_Ids)
        {
            string[] nClassSectionIds = Class_Ids[0].Split(',');
            string[] nSubjectIds      = Subject_Ids[0].Split(',');
            string   sReturnText      = string.Empty;
            int      nClassIds;


            Subject_Class_Detail newSubjClassDetail = new Subject_Class_Detail();

            int nUser_Id;

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

            using (var dbcontext = new SchoolERPDBContext())
            {
                using (var transaction = dbcontext.Database.BeginTransaction())
                {
                    try
                    {
                        for (int nClassSubLoopCount = 0; nClassSubLoopCount < nClassSectionIds.Count(); nClassSubLoopCount++)
                        {
                            int nSectionId = Convert.ToInt16(nClassSectionIds[nClassSubLoopCount]);


                            for (int nSubjectLoopCount = 0; nSubjectLoopCount < nSubjectIds.Count(); nSubjectLoopCount++)
                            {
                                nClassIds = dbcontext.Section.Where(x => x.Id == nSectionId).ToList()[0].Class_Id;

                                newSubjClassDetail.Class_Id      = nClassIds;
                                newSubjClassDetail.Subject_Id    = Convert.ToInt16(nSubjectIds[nSubjectLoopCount]);
                                newSubjClassDetail.Section_Id    = Convert.ToInt16(nClassSectionIds[nClassSubLoopCount]);
                                newSubjClassDetail.Academic_Year = GetAcademicYear();
                                newSubjClassDetail.Is_Active     = true;
                                newSubjClassDetail.Created_By    = nUser_Id;
                                newSubjClassDetail.Created_On    = DateTime.Now;

                                if (dbcontext.Subject_Class_Detail.Where(a => a.Class_Id == nClassIds && a.Subject_Id == newSubjClassDetail.Subject_Id && a.Section_Id == newSubjClassDetail.Section_Id && (a.Is_Deleted == false || a.Is_Deleted == null) && a.Academic_Year == newSubjClassDetail.Academic_Year).Count() == 0)
                                {
                                    dbcontext.Subject_Class_Detail.Add(newSubjClassDetail);
                                    dbcontext.SaveChanges();
                                    //return Json("OK", JsonRequestBehavior.AllowGet);

                                    if (nClassSubLoopCount == nClassSectionIds.Count() - 1 && nSubjectLoopCount == nSubjectIds.Count() - 1)
                                    {
                                        transaction.Commit();
                                        sReturnText = "OK";
                                    }
                                }
                                else
                                {
                                    return(Json("Already Exists", JsonRequestBehavior.AllowGet));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
            }


            return(Json(sReturnText.ToString(), JsonRequestBehavior.AllowGet));
        }