Example #1
0
        public Vendor GetVendor(int ID)
        {
            Vendor item = new Vendor();

            SqlCommand cmd = new SqlCommand("GetVendor") { CommandType = CommandType.StoredProcedure };
            cmd.Parameters.AddWithValue("@ID", ID);

            using (SqlDataReader rdr = (SqlDataReader)_repo.ExecuteReader(cmd))
            {
                while (rdr.Read())
                {
                    item = new Vendor()
                    {
                        ID = (int)rdr["ID"]
                        ,
                        Name = rdr["Name"] != DBNull.Value ? rdr["Name"].ToString() : ""
                        ,
                        Description = rdr["Description"] != DBNull.Value ? rdr["Description"].ToString() : ""
                        ,
                        ImageID = rdr["ImageID"] != DBNull.Value ? (int)rdr["ImageID"] : 0
                        ,
                        LinkURL = rdr["LinkURL"] != DBNull.Value ? rdr["LinkURL"].ToString() : ""
                        ,
                        LinkAltText = rdr["LinkAltText"] != DBNull.Value ? rdr["LinkAltText"].ToString() : ""
                        ,
                        DateInserted = (DateTime)rdr["DateInserted"]
                        ,
                        DateUpdated = rdr["DateUpdated"] != DBNull.Value ? (DateTime?)rdr["DateUpdated"] : DateTime.MinValue
                        ,
                        IsActive = (bool)rdr["IsActive"]
                    };
                }
            }
            return item;
        }
Example #2
0
        public void UpdateVendor(Vendor vendor)
        {
            SqlCommand cmd = new SqlCommand("UpdateVendor") { CommandType = CommandType.StoredProcedure };
            cmd.Parameters.AddWithValue("@ID", vendor.ID);
            cmd.Parameters.AddWithValue("@Name", vendor.Name);
            cmd.Parameters.AddWithValue("@Description", vendor.Description);
            cmd.Parameters.AddWithValue("@ImageID", vendor.ImageID);
            cmd.Parameters.AddWithValue("@LinkURL", vendor.LinkURL);
            cmd.Parameters.AddWithValue("@LinkAltText", vendor.LinkAltText);

            try
            {
                _repo.ExecuteNonQuery(cmd);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Example #3
0
        public int CreateVendor(Vendor vendor)
        {
            int id;

            SqlCommand cmd = new SqlCommand("CreateVendor") { CommandType = CommandType.StoredProcedure };
            cmd.Parameters.AddWithValue("@Name", vendor.Name);
            cmd.Parameters.AddWithValue("@Description", vendor.Description);
            cmd.Parameters.AddWithValue("@ImageID", vendor.ImageID);
            cmd.Parameters.AddWithValue("@LinkURL", vendor.LinkURL);
            cmd.Parameters.AddWithValue("@LinkAltText", vendor.LinkAltText);
            SqlParameter param = new SqlParameter("@ID", SqlDbType.Int);
            param.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(param);

            try
            {
                _repo.ExecuteNonQuery(cmd);
                id = (int)cmd.Parameters["@ID"].Value;
            }
            catch (Exception exc)
            {
                throw exc;
            }

            return id;
        }