Thursday, December 14, 2023

Bootstrap

Bootstrap, very cool, a popular front-end framework for building responsive and visually appealing websites.

d-inline is a utility class that sets the display property of an element to inline.

  • Margin and Padding:

    • m-1, m-2, ... m-5: Margin classes for spacing (1 to 5).
    • p-1, p-2, ... p-5: Padding classes for spacing (1 to 5).
    • mx-3: Horizontal margin.
    • px-3: Horizontal padding.
  • Text Alignment:

    • text-center: Center-align text.
    • text-right: Right-align text.
  • Background and Color:

    • bg-primary, bg-secondary, ...: Background color classes.
    • text-primary, text-secondary, ...: Text color classes.
  • Buttons:

    • btn, btn-primary, ...: Bootstrap button classes.
    • btn-outline-primary: Outline button with primary color.

Bootstrap, Here is the Documentation site for it: https://getbootstrap.com/docs/5.0/utilities/api/

WordPress - Useful Links

Very good WordPress tutorialshttps://www.wpbeginner.com/

Display posts plugin and tutorials:

https://displayposts.com/tutorials/

https://wordpress.org/plugins/display-post-types/


WordPress - PHP

Making new  menu and display location:

1. Code Snippets » Add Snippet 

<?php
    function wpb_top_right_menu() 
{
        register_nav_menu('top-right-menu',__( 'Top Right Menu' ));
}
add_action( 'init', 'wpb_top_right_menu' );?>

2. Appearance » Theme File Editor » Header(typically)

wp_nav_menu( array( 'theme_location'=>'top-right-menu', 'container_class'=>'top-right-class' ) );

WordPress - CSS

I am helping alumnus to build a WordPress website, quite interesting.

Additional CSS: good way to custom the style.

Remove the page title:

.bread_crumb

{ display: none; }

For custom top right menu:

div.top-right-class ul {

float:right;

    margin:20px 0px 20px 0px;

    list-style-type: none;

    list-style: none;

    list-style-image: none;

    text-align:right;

    display:inline-block;

}

div.top-right-class li {

    padding: 0px 20px 0px 0px;

    display: inline-block;

}  

div.top-right-class a { color:blue; }

Remove 1st letter drop cap:

.entry-content > p:first-of-type:first-letter{

font-size: 100%;

          line-height: 1; 

margin-right:-10px;

Display posts style:

.display-posts-listing .listing-item {    clear: both;  }

.display-posts-listing img {

    float: left;

    margin: 0 10px 10px 0;

}

Tuesday, November 28, 2023

MVC - C# Reference

? A question mark (?) is used to denote a nullable type. A nullable type can represent all the values of its underlying non-nullable value type plus an additional null value. This is particularly useful when dealing with value types, which cannot normally be assigned a null value. 

int? nullableInt = 42;  // Valid assignment

nullableInt = null;    // Valid assignment

DateTime? nullableDateTime = DateTime.Now;  // Valid assignment

nullableDateTime = null;                    // Valid assignment

?? The ?? operator, also known as the null-coalescing operator, is used for handling null values in a concise way. It provides a way to return a default value when the left-hand operand is null. 

string proName = pro?[0]?.Name ?? "Default Value";

The #pragma warning disable directive is used in C# to disable specific compiler warnings: #pragma warning disable CS8602

Target-typed new expressions are a feature introduced in C# 9.0. They allow you to omit the type in the new expression when the type can be inferred from the surrounding context. This helps reduce redundancy in your code and makes it more concise.        

// Without target-typed new expression

List<string> names = new List<string>();

// With target-typed new expression (C# 9.0 and later)

List<string> names = new(); 

The update-database command is part of the Entity Framework Migrations workflow and is crucial for keeping the database schema in sync with your code changes. It's a powerful tool that automates the process of evolving the database as your application evolves, making it easier to manage changes to your data model over time.

        Applying Database Migrations/Creating the Initial Database/Applying Subsequent     Migrations/Rolling Back Migrations

In Entity Framework, the DbContext class provides a set of methods to interact with the underlying database using LINQ queries. Here are some common methods associated with DbSet that allow you to perform various operations:

  1. Query Operations:

    • FirstOrDefault, SingleOrDefault: Retrieve the first or a single entity that satisfies a condition.
    • Where: Filter entities based on a condition.
    • OrderBy, OrderByDescending, ThenBy, ThenByDescending: Order entities based on one or more properties.
  2. Insert/Update Operations:

    • Add, AddRange: Add a new entity or a collection of entities to the context.
    • Attach: Attaches an entity or a disconnected graph of entities to the context.
    • Update: Marks an entity or entities as modified.
    • Remove, RemoveRange: Remove an entity or a collection of entities from the context.
  3. Save Changes:

    • SaveChanges, SaveChangesAsync: Persist changes made in the context to the underlying database.
  4. Bulk Operations:

    • Entity Framework Core (EF Core) has introduced extensions like BulkInsert, BulkUpdate, BulkDelete for handling bulk operations efficiently.
  5. Raw SQL Queries:

    • FromSqlRaw, FromSqlInterpolated: Execute raw SQL queries.