public string InsertStudentPayment(InsertStudentPayment obj) { string returnResult = (dynamic)null; try { if (obj != null) { //[Note: insert 'states' table] if (obj._StudentPayments != null) { var getPayment = _StudentPaymentsRepo.GetAll().ToList(); foreach (var item in obj._StudentPayments) { DateTime feeYear = DateTime.ParseExact(item.FeeYear, "yyyy", null); var isExist = (from sp in getPayment where sp.ClassId == item.ClassId && sp.FeeTypeId == item.FeeTypeId && sp.StudentId == item.StudentId && sp.FeeTermDescriptionId == item.FeeTermDescriptionId && sp.FeeYearDate.Value.Year == feeYear.Year select sp).SingleOrDefault(); if (isExist != null) { isExist.ClassId = item.ClassId; isExist.FeeYearDate = feeYear; isExist.PaymentDate = item.PaymentDate; isExist.StudentId = item.StudentId; isExist.FeeTypeId = item.FeeTypeId; isExist.FeeTermDescriptionId = item.FeeTermDescriptionId; isExist.Fine = item.Fine; isExist.PaidAmount = item.PaidAmount; isExist.Remarks = item.Remarks != null ? item.Remarks:""; _StudentPaymentsRepo.Update(isExist); } else { var StudentPayments = new InsertStudentPayment_StudentPayments() { ClassId = item.ClassId, FeeTypeId = item.FeeTypeId, FeeTermDescriptionId = item.FeeTermDescriptionId, FeeYearDate = feeYear, PaymentDate = item.PaymentDate, StudentId = item.StudentId, Fine = item.Fine, PaidAmount = item.PaidAmount, Remarks = item.Remarks }; _StudentPaymentsRepo.Insert(StudentPayments); } } returnResult = "Saved"; } } } catch (Exception ex) { returnResult = "ERROR102:ClassesServ/InsertClassessList - " + ex.Message; } return(returnResult); }
public JsonResult InsertStudentPayment(IndexPaymentDetailByIdVM obj) { var result = (dynamic)null; string message = (dynamic)null; try { if (obj.StudentPayments != null) { var paymentLists = new List <InsertStudentPayment_StudentPayments>(); foreach (var item in obj._FeeStructure) { var payment = new InsertStudentPayment_StudentPayments() { PaymentDate = obj.StudentPayments.PaymentDate, StudentId = obj.StudentPayments.StudentId, FeeTypeId = item.FeeTypeId, ClassId = obj.StudentPayments.ClassId, FeeTermDescriptionId = item.TermNo, FeeYear = obj.StudentPayments.FeeYear, Fine = item.Fine, PaidAmount = item.PaidAmount, Remarks = item.Remarks }; paymentLists.Add(payment); } var model = new InsertStudentPayment() { _StudentPayments = paymentLists }; message = _StudentPaymentsServ.InsertStudentPayment(model); result = Json(new { success = true, Message = message }); } } catch (Exception ex) { result = Json(new { success = false, Message = "ERROR101:StudentPayment/InsertStudentPayment - " + ex.Message }); } return(result); }