public ReceiptBo Get(int id) { using (SqlConnection conn = CreateConnection()) { using (SqlCommand cmd = CreateSpCommand("spReceiptGet", conn)) { cmd.Parameters.AddWithValue("@Id", id); cmd.AddDecimalOutParam("@Amount", 16, 2); cmd.AddDateTimeOutParam("@Date"); cmd.AddDateTimeOutParam("@CreationDate"); cmd.AddDateTimeOutParam("@ChangeDate"); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); var bo = new ReceiptBo(); bo.Id = id; bo.Amount = cmd.GetParamValue<decimal>("@Amount"); bo.Date = cmd.GetParamValue<DateTime>("@Date"); bo.CreationDate = cmd.GetParamValue<DateTime>("@CreationDate"); bo.ChangeDate = cmd.GetParamValue<DateTime>("@ChangeDate"); return bo; } } }
private void SaveReceipt() { if (_currentReceipt == null) { _currentReceipt = new ReceiptBo(); } _currentReceipt.Amount = clcValue.Value; _currentReceipt.Date = dateEditDate.DateTime; _receiptRepository.Save(_currentReceipt); }
public void Save(ReceiptBo bo) { if (bo.IsNewRecord) { Insert(bo); } else { Update(bo); } }
private void Insert(ReceiptBo bo) { using (SqlConnection conn = CreateConnection()) { using (SqlCommand cmd = CreateSpCommand("spReceiptIns", conn)) { cmd.AddIntOutParam("@Id"); cmd.Parameters.AddWithValue("@Amount", bo.Amount); cmd.Parameters.AddWithValue("@Date", bo.Date); cmd.AddDateTimeOutParam("@CreationDate"); cmd.AddDateTimeOutParam("@ChangeDate"); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); bo.Id = cmd.GetParamValue<int>("@Id"); bo.CreationDate = cmd.GetParamValue<DateTime>("@CreationDate"); bo.ChangeDate = cmd.GetParamValue<DateTime>("@ChangeDate"); } } }
public void SetCurrentId(int currentId) { _currentReceipt = _receiptRepository.Get(currentId); }