protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Item newItem = new Item();

        newItem.CategoryName  = CategoryDB.getCategorybyName("Services");
        newItem.Deposit       = Convert.ToDecimal(tbxRefundableDeposit.Text);
        newItem.Location      = LocationDB.getLocationbyID(ddlMRTLocation.SelectedValue);
        newItem.PricePerDay   = Convert.ToDecimal(tbxPricePerDay);
        newItem.PricePerWeek  = Convert.ToDecimal(tbxPricePerWeek);
        newItem.PricePerMonth = Convert.ToDecimal(tbxPricePerMonth);
        newItem.Renter        = MemberDB.getMemberbyEmail(Session["user"].ToString());
        newItem.Description   = tbxDescription.InnerText;
        newItem.PostedDate    = DateTime.Now;
        newItem.ItemID        = Utility.convertIdentitytoPK("ITM", ItemDB.addItem(newItem));

        List <string> tags = Utility.findHashTags(tbxDescription.InnerText);

        if (tags.Count > 0)
        {
            foreach (string t in tags)
            {
                if (!TagDB.isTagPresent(t))
                {
                    TagDB.addTag(t);
                }

                ItemTagDB.addItemTag(newItem, t);
            }
        }
    }
Exemple #2
0
    // method to read the column values in the database (through the referenced reader) and assign it to the correct properties of the referenced Item object
    // allows for easier editing of column names if needed, used only for methods with select statments regarding Item
    private static void readAItem(ref Item i, ref SqlDataReader reader)
    {
        i.ItemID       = reader["itemID"].ToString();
        i.Name         = reader["name"].ToString();
        i.Description  = reader["description"].ToString();
        i.PostedDate   = Convert.ToDateTime(reader["postedDate"]);
        i.Deposit      = Convert.ToDecimal(reader["deposit"]);
        i.CategoryName = CategoryDB.getCategorybyName(reader["categoryName"].ToString());
        i.Location     = LocationDB.getLocationbyID(reader["locationName"].ToString());

        //This sectin will set the default value of 0 whenever null is found in the database
        if (reader["pricePerDay"] != DBNull.Value)
        {
            i.PricePerDay = Convert.ToDecimal(reader["pricePerDay"]);
        }
        else
        {
            i.PricePerDay = 0;
        }

        if (reader["pricePerWeek"] != DBNull.Value)
        {
            i.PricePerWeek = Convert.ToDecimal(reader["pricePerWeek"]);
        }
        else
        {
            i.PricePerWeek = 0;
        }

        if (reader["pricePerMonth"] != DBNull.Value)
        {
            i.PricePerMonth = Convert.ToDecimal(reader["pricePerMonth"]);
        }
        else
        {
            i.PricePerMonth = 0;
        }

        // This section for collecting images
        if (reader["img1"] != DBNull.Value)
        {
            i.Img1 = reader["img1"].ToString();
        }
        else
        {
            i.Img1 = "NotAvailable.jpg";
        }

        if (reader["img2"] != DBNull.Value)
        {
            i.Img2 = reader["img2"].ToString();
        }
        else
        {
            i.Img2 = "NotAvailable.jpg";
        }

        if (reader["img3"] != DBNull.Value)
        {
            i.Img3 = reader["img3"].ToString();
        }
        else
        {
            i.Img3 = "NotAvailable.jpg";
        }

        if (reader["img4"] != DBNull.Value)
        {
            i.Img4 = reader["img4"].ToString();
        }
        else
        {
            i.Img4 = "NotAvailable.jpg";
        }

        //This section for getting the renter of an item
        i.Renter = MemberDB.getMemberbyID(reader["renterID"].ToString());
    }