Exemplo n.º 1
0
        public static bool Exists(AdreLocatie adreLocatie)
        {
            if (category.CategoryId <= 0 && string.IsNullOrEmpty(category.Name))
            {
                return(false);
            }

            int count = 0;
            var conn  = new SqlConnection(_connStr);

            try
            {
                conn.Open();
                string sql = "SELECT CategoryId FROM Category WHERE ";
                if (category.CategoryId != 0)
                {
                    sql += " CategoryId = " + category.CategoryId;
                }
                else if (!string.IsNullOrEmpty(category.Name))
                {
                    sql += " Name = '" + category.Name + "'";
                }
                var           command    = new SqlCommand(sql, conn);
                SqlDataReader dataReader = command.ExecuteReader();
                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        category.CategoryId = (int)dataReader[0];
                        ++count;
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
            return(false);
        }
Exemplo n.º 2
0
        public static void Delete(AdreLocatie adreLocatie)
        {
            var conn = new SqlConnection(_connStr);

            try
            {
                //conn.Open();
                //string sql = $"DELETE FROM Category WHERE CategoryId = " + category.CategoryId;
                //var updateCommand = new SqlCommand(sql, conn);
                //updateCommand.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }
Exemplo n.º 3
0
        public static void Update(AdreLocatie adresLocatie)
        {
            var conn = new SqlConnection(_connStr);

            try
            {
                conn.Open();
                string sql           = $"UPDATE CartLine SET ProductId = ";
                var    updateCommand = new SqlCommand(sql, conn);
                updateCommand.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }