public List <BloodAvailability> GetAllBloodAvailabilities()
        {
            List <BloodAvailability> bloodAvailabilityList = new List <BloodAvailability>();

            using (SqlConnection con = new SqlConnection(Queries.connection))
            {
                con.Open();
                SqlCommand command = new SqlCommand()
                {
                    Connection  = con,
                    CommandType = CommandType.Text,
                    CommandText = Queries.getAllBloodAvailabilities
                };
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    BloodAvailability availability = new BloodAvailability();

                    availability.BloodGroup    = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.bloodGroup)));
                    availability.Area          = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.area)));
                    availability.State         = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.state)));
                    availability.Pincode       = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.pincode)));
                    availability.ContactNumber = Convert.ToInt64(reader.GetValue(reader.GetOrdinal(Constants.contactNumber)));
                    bloodAvailabilityList.Add(availability);
                }
                reader.Close();
            }
            return(bloodAvailabilityList);
        }
        public void TestDonateBlood()
        {
            BloodBL           bl = new BloodBL();
            BloodAvailability ba = new BloodAvailability(1, "A+", "AP", "area1", 123456, 9987654321);

            Assert.AreEqual(1, bl.DonateBlood(ba, 1));
        }
Esempio n. 3
0
    protected void btnMyLocationSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            BloodAvailability ba = new BloodAvailability();
            ba.State         = txtStateMyLocation.Text;
            ba.Area          = txtAreaMyLocation.Text;
            ba.Pincode       = int.Parse(txtPincodeMyLocation.Text);
            ba.BloodGroup    = txtBloodGroupMyLocation.Text;
            ba.ContactNumber = long.Parse(txtContactNumberMyLocation.Text);

            Hospital h = new Hospital();
            h.State        = txtStateMyLocation.Text;
            h.Area         = txtAreaMyLocation.Text;
            h.HospitalName = ddlHospitalMyLocation.SelectedItem.Text;

            if (txtDateMyLocation.Text != "" || txtDateMyLocation.Text != null)
            {
                if (DateTime.Compare(DateTime.Parse(txtDateMyLocation.Text), DateTime.Now) < 0)
                {
                    //lblDateMyLocation.Text = "* Select Future Date";
                    Response.Write("<script>alert('Select future date');</script>");
                    txtDateMyLocation.Text = "";
                    txtDateMyLocation.Focus();
                }
                else
                {
                    lblDateMyLocation.Text = "";
                }
            }

            h.Date = DateTime.Parse(txtDateMyLocation.Text);
            h.Time = txtTimeMyLocation.Text;

            BloodBL bl             = new BloodBL();
            int     userId         = int.Parse(Session[Constants.userId].ToString());
            int     donateResult   = bl.DonateBlood(ba, userId);
            int     hospitalResult = bl.SaveHospital(h, userId);
            if (donateResult + hospitalResult == 2)
            {
                string bloodPostingId = Request.QueryString[Constants.id].ToString();
                bl.RemoveBloodPosting(int.Parse(bloodPostingId));
                Response.Write("<script>alert('You saved a Life! Thank you...');window.location.href='HomePage.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('Failed to Save Blood Details...Try Again');window.location.href='DonateBlood_and_BookHospital.aspx';</script>");
            }
        }
        catch (TypeInitializationException ex)
        {
            Response.Write("<script>alert('Date should be in MM/dd/yyyy format');</script>");
        }
        catch (Exception ex)
        {
        }
    }
        public int DonateBlood(BloodAvailability ba, int userId)
        {
            int result = 0;

            using (SqlConnection con = new SqlConnection(Queries.connection))
            {
                con.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = con,
                    CommandType = CommandType.Text,
                    CommandText = Queries.saveDonorBloodDetails
                };
                command.Parameters.Add(Constants.paramBloodGroup, SqlDbType.VarChar).Value   = ba.BloodGroup;
                command.Parameters.Add(Constants.paramState, SqlDbType.VarChar).Value        = ba.State;
                command.Parameters.Add(Constants.paramArea, SqlDbType.VarChar).Value         = ba.Area;
                command.Parameters.Add(Constants.paramPincode, SqlDbType.BigInt).Value       = ba.Pincode;
                command.Parameters.Add(Constants.paramContactNumber, SqlDbType.BigInt).Value = ba.ContactNumber;
                command.Parameters.Add(Constants.paramUserId, SqlDbType.Int).Value           = userId;

                result = command.ExecuteNonQuery();
            }
            return(result);
        }