public DataSaveResult Save() { Acc_Reconcilation dbReconcilation; try { NewAppsCnn newAppsCnn = new NewAppsCnn(AppSettings.CrAppSettings.NewAppsConnectionString); var dbReconcilations = from u in newAppsCnn.Acc_Reconcilation where u.ReconcileId == this.ReconcileId select u; if (dbReconcilations.Count() > 0) { dbReconcilation = dbReconcilations.First(); this.ToDbReconcilation(dbReconcilation); List<Acc_ReconcilationDtl> DltLst = (from u in newAppsCnn.Acc_ReconcilationDtl where u.ReconcileId == this.ReconcileId select u).ToList(); foreach (var itm in DltLst) { newAppsCnn.Acc_ReconcilationDtl.Remove(itm); newAppsCnn.SaveChanges(); } foreach (var itm in this.ReconcilationDtlLst) { Acc_ReconcilationDtl Obj = new Acc_ReconcilationDtl() { ReconcileId = dbReconcilation.ReconcileId, VoucherId = itm.VoucherId, VoucherNo = (from u in newAppsCnn.Acc_Voucher where u.VoucherId == itm.VoucherId select u).ToList().FirstOrDefault().VoucherRefno, ReconcileDtlid = (from u in newAppsCnn.Acc_ReconcilationDtl select u.ReconcileDtlid).ToList().LastOrDefault() == null ? 1 : (1 + (from u in newAppsCnn.Acc_ReconcilationDtl select u.ReconcileDtlid).ToList().LastOrDefault()) }; newAppsCnn.Acc_ReconcilationDtl.Add(Obj); newAppsCnn.SaveChanges(); } } else { dbReconcilation = new Acc_Reconcilation(); this.ToDbReconcilation(dbReconcilation); newAppsCnn.Acc_Reconcilation.Add(dbReconcilation); newAppsCnn.SaveChanges(); foreach (var itm in this.ReconcilationDtlLst) { Acc_ReconcilationDtl Obj = new Acc_ReconcilationDtl() { ReconcileId = dbReconcilation.ReconcileId, VoucherId=itm.VoucherId, VoucherNo = (from u in newAppsCnn.Acc_Voucher where u.VoucherId == itm.VoucherId select u).ToList().FirstOrDefault().VoucherRefno, ReconcileDtlid = (from u in newAppsCnn.Acc_ReconcilationDtl select u.ReconcileDtlid).ToList().LastOrDefault() == null ? 1 : (from u in newAppsCnn.Acc_ReconcilationDtl select u.ReconcileDtlid).ToList().LastOrDefault() }; newAppsCnn.Acc_ReconcilationDtl.Add(Obj); newAppsCnn.SaveChanges(); } } newAppsCnn.SaveChanges(); Audit.AddDataAudit(Audit.AuditActionTypes.AddNew, "Acc_Reconcilation", this); this.FromDbReconcilation(dbReconcilation); return new DataSaveResult() { SaveStatus = true }; } catch (Exception ex) { return new DataSaveResult() { SaveStatus = false, ErrorMessage = ex.Message }; } }
public void ToDbReconcilation(Acc_Reconcilation _dbReconcilation) { NewAppsCnn newAppsCnn = new NewAppsCnn(AppSettings.CrAppSettings.NewAppsConnectionString); var RId = 1 + ((from u in newAppsCnn.Acc_Reconcilation select u.ReconcileId).ToList().LastOrDefault() == null ? 1 : (int.Parse((from u in newAppsCnn.Acc_Reconcilation select u.ReconcileId).ToList().LastOrDefault()))); _dbReconcilation.ReconcileId = this.ReconcileId ?? RId.ToString(); _dbReconcilation.ReconcileAccountId = this.ReconcileAccountId; _dbReconcilation.ReconcileYear = AppInfo.CurrentYear.YearId; _dbReconcilation.CurrentStatemantAmount = this.CurrentStatemantAmount; _dbReconcilation.CurrentStatementDate = this.CurrentStatementDate; _dbReconcilation.ReconciledLastBal = this.ReconciledLastBal; _dbReconcilation.ReconciledLastDate = this.ReconciledLastDate; _dbReconcilation.ReconcilationValue = this.ReconcilationValue; _dbReconcilation.AccountBalance = this.AccountBalance; _dbReconcilation.DiffreneceInBook = this.DiffreneceInBook; }
public void FromDbReconcilation(Acc_Reconcilation _dbReconcilation) { this.ReconcileId = _dbReconcilation.ReconcileId; this.ReconcileAccountId = _dbReconcilation.ReconcileAccountId; this.ReconcileYear = _dbReconcilation.ReconcileYear; this.CurrentStatemantAmount = _dbReconcilation.CurrentStatemantAmount; this.CurrentStatementDate = _dbReconcilation.CurrentStatementDate; this.ReconciledLastBal = _dbReconcilation.ReconciledLastBal; this.ReconciledLastDate = _dbReconcilation.ReconciledLastDate; this.ReconcilationValue = _dbReconcilation.ReconcilationValue; this.AccountBalance = _dbReconcilation.AccountBalance; this.DiffreneceInBook = _dbReconcilation.DiffreneceInBook; LoadVoucher(); }