[HttpPost] public ActionResult Index(CUSTOM_STUDENT_FEEALLOCTION_DATA CUSTOM_STUDENT_FEEALLOCTION_DATAObj) { var Student_FeeallocationDetail = CUSTOM_STUDENT_FEEALLOCTION_DATAObj.CUSTOM_STUDENT_FEEALLOCATION_DETAIL; var SelectStufeedetail = Student_FeeallocationDetail.Where(b => b.SELECTED_STUDENT == true).ToList(); CUSTOM_STU_DETAIL stuentdetail = new CUSTOM_STU_DETAIL(); try { foreach (var studentfeedatal in SelectStufeedetail) { if (studentfeedatal.Registration_Id == null) { List<studentregdetail> regIdObj = new List<studentregdetail>(); regIdObj = (from r in db.Student_Registration join ra in db.Student_Re_Admission on r.Registration_Id equals ra.Registration_Id where r.Academic_Year_Id== studentfeedatal.Academic_Year_Id && r.Class_Id==studentfeedatal.Class_Id where ra.Promoted==false select new StudentRegDetail() { Registration_Id = r.Registration_Id, Admission_No = ra.Admission_No }).OrderBy(a => a.Registration_Id).ToList(); foreach (var regIds in regIdObj) { var fee_set = db.Student_Fee_Allocation.Where(a => a.Fee_Master_Id == studentfeedatal.Fee_Master_Id && a.Registration_Id == regIds.Registration_Id).ToList(); if (fee_set.Count == 0) { Student_Fee_Allocation Student_Fee_AlloctionObj = new Student_Fee_Allocation(); Student_Fee_AlloctionObj.Last_Updated_Date = DateTime.Now.ToUniversalTime(); Student_Fee_AlloctionObj.Last_Updated_By = CurrentUserID; Student_Fee_AlloctionObj.Creation_Date = DateTime.Now.ToUniversalTime(); Student_Fee_AlloctionObj.Created_By = CurrentUserID; //Student_Fee_AlloctionObj.Fee_Allocation_Id = studentfeedatal.Fee_Allocation_Id; Student_Fee_AlloctionObj.Academic_Year_Id = studentfeedatal.Academic_Year_Id; Student_Fee_AlloctionObj.Class_Id = studentfeedatal.Class_Id; Student_Fee_AlloctionObj.Admission_No = regIds.Admission_No.ToString(); Student_Fee_AlloctionObj.Registration_Id = regIds.Registration_Id; Student_Fee_AlloctionObj.Fee_Master_Id = studentfeedatal.Fee_Master_Id; Student_Fee_AlloctionObj.Fee_Period_Id = studentfeedatal.Fee_Period_Id; Student_Fee_AlloctionObj.Amount = studentfeedatal.Amount; Student_Fee_AlloctionObj.Consession = studentfeedatal.Concession; Student_Fee_AlloctionObj.Final_Amount = studentfeedatal.Final_Amount; Student_Fee_AlloctionObj.Paid_Amount = 0; Student_Fee_AlloctionObj.Balance = studentfeedatal.Final_Amount; Student_Fee_AlloctionObj.Delete_Flag = false; db.Student_Fee_Allocation.AddObject(Student_Fee_AlloctionObj); db.SaveChanges(); } else { foreach (var feeset in fee_set) { db.ObjectStateManager.ChangeObjectState(feeset, EntityState.Modified); db.SaveChanges(); } } } ModelState.AddModelError("", "Fees Allocated Successfully."); } else { var fee_set = db.Student_Fee_Allocation.Where(a => a.Fee_Master_Id == studentfeedatal.Fee_Master_Id && a.Registration_Id == studentfeedatal.Registration_Id).ToList(); if (fee_set.Count == 0) { Student_Fee_Allocation Student_Fee_AlloctionObj = new Student_Fee_Allocation(); Student_Fee_AlloctionObj.Last_Updated_Date = DateTime.Now.ToUniversalTime(); Student_Fee_AlloctionObj.Last_Updated_By = CurrentUserID; Student_Fee_AlloctionObj.Creation_Date = DateTime.Now.ToUniversalTime(); Student_Fee_AlloctionObj.Created_By = CurrentUserID; //Student_Fee_AlloctionObj.Fee_Allocation_Id = studentfeedatal.Fee_Allocation_Id; Student_Fee_AlloctionObj.Academic_Year_Id = studentfeedatal.Academic_Year_Id; Student_Fee_AlloctionObj.Class_Id = studentfeedatal.Class_Id; Student_Fee_AlloctionObj.Admission_No = studentfeedatal.Admission_No.ToString(); Student_Fee_AlloctionObj.Registration_Id = studentfeedatal.Registration_Id; Student_Fee_AlloctionObj.Fee_Master_Id = studentfeedatal.Fee_Master_Id; Student_Fee_AlloctionObj.Fee_Period_Id = studentfeedatal.Fee_Period_Id; Student_Fee_AlloctionObj.Amount = studentfeedatal.Amount; Student_Fee_AlloctionObj.Consession = studentfeedatal.Concession; Student_Fee_AlloctionObj.Final_Amount = studentfeedatal.Final_Amount; Student_Fee_AlloctionObj.Paid_Amount = 0; Student_Fee_AlloctionObj.Balance = studentfeedatal.Final_Amount; Student_Fee_AlloctionObj.Delete_Flag = false; db.Student_Fee_Allocation.AddObject(Student_Fee_AlloctionObj); db.SaveChanges(); ModelState.AddModelError("", "Fees Allocated Successfully."); } else { foreach (var feeset in fee_set) { db.ObjectStateManager.ChangeObjectState(feeset, EntityState.Modified); db.SaveChanges(); } } } } FillViewBag_Search(); return View(); } catch (Exception ex) { ModelState.AddModelError("", "Error Allocating Fees." + ex.Message.ToString()); FillViewBag_Search(); return View(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)