public void CompareEvent(SavingEvent originalEvent, SavingEvent retrievedEvent) { Assert.AreEqual(originalEvent.Amount, retrievedEvent.Amount); Assert.AreEqual(originalEvent.User.Id, retrievedEvent.User.Id); Assert.AreEqual(originalEvent.Code, retrievedEvent.Code); Assert.AreEqual(originalEvent.Date, retrievedEvent.Date); Assert.AreEqual(originalEvent.Cancelable, retrievedEvent.Cancelable); Assert.AreEqual(originalEvent.IsFired, retrievedEvent.IsFired); if (originalEvent is SavingTransferEvent) Assert.AreEqual(((SavingTransferEvent)originalEvent).RelatedContractCode, ((SavingTransferEvent)retrievedEvent).RelatedContractCode); if (originalEvent is ISavingsFees) if (((ISavingsFees)originalEvent).Fee.HasValue || ((ISavingsFees)retrievedEvent).Fee.HasValue) Assert.AreEqual(((ISavingsFees)originalEvent).Fee, ((ISavingsFees)retrievedEvent).Fee); }
public int Add(SavingEvent pSavingEvent, int pSavingContactId) { using (SqlConnection conn = GetConnection()) { using (SqlTransaction t = conn.BeginTransaction()) { try { int id = Add(pSavingEvent, pSavingContactId, t); t.Commit(); return id; } catch (Exception) { t.Rollback(); throw; } } } }
private void SavingEventOrigination(SavingEvent savingEvent, ISavingsContract savingsContract, SqlTransaction sqlTransac) { _savingEventManagement.Add(savingEvent, savingsContract.Id, sqlTransac); }
public void FireEvent(SavingEvent e) { Debug.Assert(e.Target != null, "Saving event's target is null"); e.IsFired = true; using (SqlConnection conn = _savingEventManagement.GetConnection()) using (SqlTransaction t = conn.BeginTransaction()) { try { SavingEventOrigination(e, e.Target, t); t.Commit(); } catch (Exception) { t.Rollback(); throw; } } }
public void FireEvent(SavingEvent e, ISavingsContract pSaving, SqlTransaction sqlTransac) { e.IsFired = true; SavingEventOrigination(e, pSaving, sqlTransac); }
public void CancelFireEvent(SavingEvent savingEvent, int currencyId) { _savingEventManagement.DeleteEventInDatabase(savingEvent); }
protected SavingEvent EvaluateSavingsEvent(SavingEvent e) { if (!e.Amount.HasValue) e.Amount = 0m; if (!e.Fee.HasValue) e.Fee = 0m; if (e is SavingInterestsAccrualEvent || e is SavingInterestsPostingEvent) { if (e.Amount > 0) { e.Amount = Product.Currency.UseCents ? Math.Round(e.Amount.Value, 2, MidpointRounding.AwayFromZero) : Math.Round(e.Amount.Value, 0, MidpointRounding.AwayFromZero); if (e.Amount > 0) return e; } } if(e is SavingAgioEvent || e is SavingManagementFeeEvent) { if (e.Fee > 0) { e.Fee = Product.Currency.UseCents ? Math.Round(e.Fee.Value, 2, MidpointRounding.AwayFromZero) : Math.Round(e.Fee.Value, 0, MidpointRounding.AwayFromZero); if (e.Fee > 0) return e; } } //return filteredEvents; return null; }
public void CancelEvent(SavingEvent pSavingEvent) { pSavingEvent.Deleted = true; }
public SavingEvent AddSavingEvent(SavingEvent e) { SavingEvent savEvent = EvaluateSavingsEvent(e); if (savEvent != null) { Events.Add(e); } return savEvent; }
public int Add(SavingEvent pSavingEvent, int pSavingContractId, SqlTransaction sqlTransac) { const string q = @"INSERT INTO [SavingEvents]( [user_id], [contract_id], [code], [amount], [description], [deleted], [creation_date], [cancelable], [is_fired], [related_contract_code], [fees], [savings_method], [pending], [pending_event_id], [teller_id], [loan_event_id]) VALUES( @user_id, @contract_id, @code, @amount, @description, @deleted, @creation_date, @cancelable, @is_fired, @related_contract_code, @fees, @savings_method, @pending, @pending_event_id, @teller_id, @loan_event_id) SELECT CONVERT(int, SCOPE_IDENTITY())"; using (OpenCbsCommand c = new OpenCbsCommand(q, sqlTransac.Connection, sqlTransac)) { SetInsertCommandForSavingEvent(c, pSavingEvent, pSavingContractId); pSavingEvent.Id = Convert.ToInt32(c.ExecuteScalar()); return pSavingEvent.Id; } }
private static void SetSavingsEvent(OpenCbsReader r, SavingEvent e, ISavingProduct pProduct) { e.Id = r.GetInt("id"); e.ContracId = r.GetInt("contract_id"); e.Code = r.GetString("code"); e.Amount = r.GetMoney("amount"); e.Description = r.GetString("description"); e.Deleted = r.GetBool("deleted"); e.Date = r.GetDateTime("creation_date"); e.Cancelable = r.GetBool("cancelable"); e.IsFired = r.GetBool("is_fired"); e.CancelDate = r.GetNullDateTime("cancel_date"); if(pProduct != null) e.ProductType = pProduct.GetType(); if (r.GetNullSmallInt("savings_method").HasValue) e.SavingsMethod = (OSavingsMethods)r.GetNullSmallInt("savings_method").Value; e.IsPending = r.GetBool("pending"); e.PendingEventId = r.GetNullInt("pending_event_id"); e.TellerId = r.GetNullInt("teller_id"); e.LoanEventId = r.GetNullInt("loan_event_id"); if (pProduct != null) { e.ProductType = pProduct.GetType(); } if (e is SavingTransferEvent) { ((SavingTransferEvent)e).RelatedContractCode = r.GetString("related_contract_code"); } if (e is ISavingsFees) { ((ISavingsFees) e).Fee = r.GetMoney("fees"); } e.User = new User { Id = r.GetInt("user_id"), UserName = r.GetString("user_name"), Password = r.GetString("user_pass"), LastName = r.GetString("last_name"), FirstName = r.GetString("first_name") }; e.User.SetRole(r.GetString("role_code")); e.ClientType = OClientTypes.All; switch (r.GetString("client_type_code")) { case "I": e.ClientType = OClientTypes.Person; break; case "C": e.ClientType = OClientTypes.Corporate; break; case "G": e.ClientType = OClientTypes.Group; break; case "V": e.ClientType = OClientTypes.Village; break; } e.Branch = new Branch { Id = r.GetInt("branch_id") }; e.Currency = new Currency { Id = r.GetInt("currency_id"), Code = r.GetString("currency_code"), IsPivot = r.GetBool("is_pivot"), IsSwapped = r.GetBool("is_swapped") }; e.SavingProduct = new SavingsBookProduct { Id = r.GetInt("product_id") }; }
private static void SetInsertCommandForSavingEvent(OpenCbsCommand c, SavingEvent pSavingEvent, int pSavingContractId) { c.AddParam("@user_id", pSavingEvent.User.Id); c.AddParam("@contract_id", pSavingContractId); c.AddParam("@code", pSavingEvent.Code); c.AddParam("@amount", pSavingEvent.Amount); c.AddParam("@description", pSavingEvent.Description); c.AddParam("@deleted", pSavingEvent.Deleted); c.AddParam("@creation_date", pSavingEvent.Date); c.AddParam("@cancelable", pSavingEvent.Cancelable); c.AddParam("@is_fired", pSavingEvent.IsFired); c.AddParam("@related_contract_code", pSavingEvent is SavingTransferEvent ? ((SavingTransferEvent)pSavingEvent).RelatedContractCode : null); c.AddParam("@fees", pSavingEvent is ISavingsFees ? ((ISavingsFees)pSavingEvent).Fee : null); if (pSavingEvent.SavingsMethod.HasValue) c.AddParam("@savings_method", (int)pSavingEvent.SavingsMethod.Value); else c.AddParam("@savings_method", null); c.AddParam("@pending", pSavingEvent.IsPending); if (pSavingEvent.PendingEventId.HasValue) c.AddParam("@pending_event_id", pSavingEvent.PendingEventId); else c.AddParam("@pending_event_id", null); if (pSavingEvent.TellerId.HasValue && pSavingEvent.TellerId > 0) { if (pSavingEvent.TellerId != 0) { c.AddParam("@teller_id", pSavingEvent.TellerId); } else { c.AddParam("@teller_id", null); } } else c.AddParam("@teller_id", null); c.AddParam("@loan_event_id", pSavingEvent.LoanEventId); }
public void DeleteEventInDatabase(SavingEvent pSavingEvent) { const string q = @"UPDATE [SavingEvents] SET [deleted] = 1 , is_exported = 0 ,[cancel_date] = @cancel_date WHERE id = @id"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@id", pSavingEvent.Id); c.AddParam("@cancel_date", pSavingEvent.CancelDate.Value); c.ExecuteNonQuery(); } }
public void DeleteEvent(SavingEvent savingEvent) { _savingEventManager.DeleteEventInDatabase(savingEvent); }