Exemple #1
0
        public void TransferMoney(Guid senderAccountNo, Guid reciverAccountNo, decimal amount)
        {
            SqlCommand cmd4 = new SqlCommand();

            cmd4.Connection  = conn;
            cmd4.CommandText = "select Bakiye from MusteriHesap where MusteriHesap.HesapNo=@GondericiHesapNo";
            cmd4.CommandType = System.Data.CommandType.Text;
            cmd4.Parameters.AddWithValue("@GondericiHesapNo", senderAccountNo);

            decimal ballance = (decimal)cmd4.ExecuteScalar(); //count,sum veya tek bir alan

            SqlTransaction transaction = conn.BeginTransaction();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "update MusteriHesap set Bakiye -= @OdenecekMiktar where MusteriHesap.HesapNo = @GondericiHesapNo";
            cmd.Connection  = conn;
            cmd.Parameters.AddWithValue("@GondericiHesapNo", senderAccountNo);
            cmd.Parameters.AddWithValue("@OdenecekMiktar", amount);
            cmd.Transaction = transaction;

            SqlCommand cmd2 = new SqlCommand();

            cmd2.Connection  = conn;
            cmd2.CommandText = "update MusteriHesap set Bakiye += @OdenecekMiktar where MusteriHesap.HesapNo = @AliciHesapNo";
            cmd2.Parameters.AddWithValue("@AliciHesapNo", reciverAccountNo);
            cmd2.Parameters.AddWithValue("@OdenecekMiktar", amount);
            cmd2.Transaction = transaction;

            SqlCommand cmd3 = new SqlCommand();

            cmd3.Connection  = conn;
            cmd3.CommandText = "insert into HesapIslemDetay(AliciHesapNo,GonderiHesapNo,GönderilenMiktar,İslemTarihi,İslemTipId,İslemYapanId) values(@AliciHesapNo, @GondericiHesapNo, @OdenecekMiktar, @now, @TransferTipId, @islemYapanId)";
            cmd3.Parameters.AddWithValue("@TransferTipId", 1);
            cmd3.Parameters.AddWithValue("@AliciHesapNo", reciverAccountNo);
            cmd3.Parameters.AddWithValue("@OdenecekMiktar", amount);
            cmd3.Parameters.AddWithValue("@GondericiHesapNo", senderAccountNo);
            cmd3.Parameters.AddWithValue("@now", DateTime.Now);
            cmd3.Parameters.AddWithValue("@islemYapanId", 2);
            cmd3.Transaction = transaction;

            //queryleri çalıştır.
            cmd2.ExecuteNonQuery();
            cmd3.ExecuteNonQuery();
            cmd.ExecuteNonQuery();


            if (ballance < amount)
            {
                transaction.Rollback();
            }
            else
            {
                transaction.Commit();
                _status = ProccessStatus.OK;
            }
        }
        public void TransferMoney(Guid senderAccountNo, Guid reciverAccountNo, decimal amount)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.CommandText = "ParaTransferiYap";

            cmd.Parameters.AddWithValue("@TransferTipId", 1);
            cmd.Parameters.AddWithValue("@GondericiHesapNo", senderAccountNo);
            cmd.Parameters.AddWithValue("@AliciHesapNo", reciverAccountNo);
            cmd.Parameters.AddWithValue("@OdenecekMiktar", amount);

            int r = cmd.ExecuteNonQuery();

            _status = r > 0 ? ProccessStatus.OK : ProccessStatus.NotOK;
        }