public bool Update(MST_STUDENTFEE_RECEIPT data) { try { unitOfWork.StudentReceiptRepository.Update(data); unitOfWork.Save(); return(true); } catch (Exception ex) { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { bool error = false; uc_sucess.Visible = false; uc_sucess.VisibleError = false; if (ddlStudentList.SelectedValue == "" || ddlStudentList.SelectedValue == "0") { uc_sucess.VisibleError = true; uc_sucess.ErrorMessage = "Please Select Student Name!"; return; } else if (ddlPaymentType.SelectedValue == "" || ddlPaymentType.SelectedValue == "0") { uc_sucess.ErrorMessage = "Please Select Payment Type!"; uc_sucess.VisibleError = true; return; } else if (txtTransactionNumber.Visible == true && txtTransactionNumber.Text.Trim() == "") { uc_sucess.VisibleError = true; uc_sucess.ErrorMessage = "Please Enter Transaction/Cheque Number"; return; } try { List <MST_STUDENTFEE_RECEIPT> StudentFeeReceipts = new List <MST_STUDENTFEE_RECEIPT>(); decimal newFee = 0, OldFee = 0, NewSubmittedFee = 0, NewTotalFee = 0; List <MST_STUDENT_FEE> StudentFeeNewList = new List <MST_STUDENT_FEE>(); List <MST_STUDENT_FEE> StudentFeeOldList = new List <MST_STUDENT_FEE>(); MST_STUDENTFEE_RECEIPT FeeReceipt; foreach (ListViewDataItem item in lvStudentFee.Items) { MST_STUDENT_FEE StudentDtl = new MST_STUDENT_FEE(); string StudentFeeId = (lvStudentFee.DataKeys[item.DisplayIndex].Values["STUDENTFEEID"].ToString()); int FeeTermId = Convert.ToInt32(lvStudentFee.DataKeys[item.DisplayIndex].Values["FEETERMID"].ToString()); decimal TotalFee = Convert.ToDecimal(lvStudentFee.DataKeys[item.DisplayIndex].Values["FEEAMOUNT_NEW"].ToString()); NewTotalFee += TotalFee; StudentDtl.FeeTermId = Convert.ToInt32(FeeTermId); StudentDtl.StudentId = Convert.ToInt32(ddlStudentList.SelectedValue); TextBox txtDepositFeeNew = (TextBox)item.FindControl("txtDepositFeeNew"); TextBox txtDepositFeeOld = (TextBox)item.FindControl("txtDepositFeeOld"); TextBox txtCONCESSIONFEEAMT = (TextBox)item.FindControl("txtCONCESSIONFEEAMT"); TextBox txtDUEFEE = (TextBox)item.FindControl("txtDUEFEE"); TextBox txtFeeAmountNew = (TextBox)item.FindControl("ComparetxtFeeNew"); TextBox txtFeeAmountOld = (TextBox)item.FindControl("ComparetxtFeeOld"); FeeReceipt = new MST_STUDENTFEE_RECEIPT { ReceiptNumber = txtPaymentReceiptNumber.Text, SubmitDate = DateTime.Now, SubmitType = Convert.ToByte(ddlPaymentType.SelectedValue), TransactionNumber = txtTransactionNumber.Text, FeeTermId = FeeTermId, TotalFee = Convert.ToDecimal(txtDepositFeeNew.Text), StudentId = StudentDtl.StudentId, Fin_Id = Convert.ToInt32(ddlFinYear.SelectedValue) }; if (txtDepositFeeNew.Text != "") { StudentDtl.FeeAmount_New = Convert.ToDecimal(txtDepositFeeNew.Text); NewSubmittedFee += Convert.ToDecimal(txtDepositFeeNew.Text); } if (txtDepositFeeOld.Text != "") { StudentDtl.FeeAmount_Old = Convert.ToDecimal(txtDepositFeeOld.Text); } if (txtCONCESSIONFEEAMT.Text != "") { StudentDtl.ConcessionFeeAmt = Convert.ToDecimal(txtCONCESSIONFEEAMT.Text); } if (txtDUEFEE.Text != "") { StudentDtl.DueFee = Convert.ToDecimal(txtDUEFEE.Text); } if (TotalFee == Convert.ToDecimal(txtCONCESSIONFEEAMT.Text) + Convert.ToDecimal(txtDepositFeeNew.Text)) { StudentDtl.IsPaid = true; } else { StudentDtl.IsPaid = false; } StudentDtl.CreatedBy = cls_Common.UserProfile.Id; StudentDtl.CreatedDate = DateTime.Now; StudentDtl.Fin_ID = Convert.ToInt32(ddlFinYear.SelectedValue); if (StudentFeeId == null || StudentFeeId == "") { StudentFeeNewList.Add(StudentDtl); //var result = _FeeDTO.Save(StudentDtl); //if (!result) // error = true; } else { int exitStudentFeeId = Convert.ToInt32(StudentFeeId); var existStudentDtl = _FeeDTO.GetStudentFee(exitStudentFeeId); FeeReceipt.TotalFee -= existStudentDtl.FeeAmount_New; OldFee += Convert.ToDecimal(existStudentDtl.FeeAmount_New); //OldFee += Convert.ToDecimal(existStudentDtl.FeeAmount_New) + Convert.ToDecimal(existStudentDtl.FeeAmount_Old); existStudentDtl.FeeTermId = Convert.ToInt32(FeeTermId); existStudentDtl.StudentId = Convert.ToInt32(ddlStudentList.SelectedValue); if (txtDepositFeeNew.Text != "") { existStudentDtl.FeeAmount_New = Convert.ToDecimal(txtDepositFeeNew.Text); newFee += Convert.ToDecimal(txtDepositFeeNew.Text); } if (txtDepositFeeOld.Text != "") { existStudentDtl.FeeAmount_Old = Convert.ToDecimal(txtDepositFeeOld.Text); } if (txtCONCESSIONFEEAMT.Text != "") { existStudentDtl.ConcessionFeeAmt = Convert.ToDecimal(txtCONCESSIONFEEAMT.Text); } if (txtDUEFEE.Text != "") { existStudentDtl.DueFee = Convert.ToDecimal(txtDUEFEE.Text); } existStudentDtl.IsPaid = StudentDtl.IsPaid; existStudentDtl.CreatedBy = cls_Common.UserProfile.Id; existStudentDtl.CreatedDate = DateTime.Now; StudentFeeOldList.Add(existStudentDtl); //var result = _FeeDTO.Update(existStudentDtl); //if (!result) // error = true; //newFee += Convert.ToDecimal(txtDepositFeeNew.Text) + Convert.ToDecimal(txtDepositFeeOld.Text); } StudentFeeReceipts.Add(FeeReceipt); } if ((newFee <= OldFee || NewSubmittedFee <= 0) && StudentFeeNewList.Count == 0) { uc_sucess.VisibleError = true; uc_sucess.ErrorMessage = "You need to Enter more amount before pressing save!"; BindPaymentData(); return; } if (NewSubmittedFee > NewTotalFee) { uc_sucess.VisibleError = true; uc_sucess.ErrorMessage = "Submitted Amount can't be larger than total amount!"; BindPaymentData(); return; } foreach (var Student in StudentFeeNewList) { _FeeDTO.Save(Student); } foreach (var Student in StudentFeeOldList) { //if (OldFee >= newFee) //{ // uc_sucess.ErrorMessage = "Fees Total Amount is Still Same or lesser"; // uc_sucess.VisibleError = true; // return; //} _FeeDTO.Update(Student); } if (error) { uc_sucess.VisibleError = true; uc_sucess.ErrorMessage = "Error Occured"; } else { uc_sucess.Visible = true; uc_sucess.SuccessMessage = "Data Saved Successfully!"; } _FeeDTO.Save(StudentFeeReceipts); BindPaymentData(); lvStudentFee.DataBind(); } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } }