Skip to content

Commit be1c511

Browse files
Merge pull request #30 from phamtiendungcw/dungcw
This pull request focuses on enhancing code robustness, error handling, and reducing redundancy through the adoption of non-nullable reference types and initialization of properties with default values across various classes and DTOs.
2 parents 0adb7a0 + ae3f0e4 commit be1c511

File tree

174 files changed

+481
-679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+481
-679
lines changed

src/MLS.Domain/Entities/Address.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace MLS.Domain.Entities
44
{
55
public class Address : BaseEntity
66
{
7-
public string Street { get; set; }
8-
public string City { get; set; }
9-
public string State { get; set; }
10-
public string Country { get; set; }
11-
public string PostalCode { get; set; }
7+
public string Street { get; set; } = string.Empty;
8+
public string City { get; set; } = string.Empty;
9+
public string State { get; set; } = string.Empty;
10+
public string Country { get; set; } = string.Empty;
11+
public string PostalCode { get; set; } = string.Empty;
1212

1313
public int UserId { get; set; } // Foreign key referencing User
14-
public User User { get; set; } // Navigation property for User
14+
public User User { get; set; } = null!; // Navigation property for User
1515
}
1616
}

src/MLS.Domain/Entities/Article.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ namespace MLS.Domain.Entities
44
{
55
public class Article : BaseEntity
66
{
7-
public string Title { get; set; } // Article title
8-
public string Content { get; set; } // Article content
9-
public string Author { get; set; } // Author name
7+
public string Title { get; set; } = string.Empty; // Article title
8+
public string Content { get; set; } = string.Empty; // Article content
9+
public string Author { get; set; } = string.Empty; // Author name
1010
public DateTime PublicationDate { get; set; } // Date and time of publication
1111

1212
public int UserId { get; set; } // Foreign key referencing User (author)
13-
public User AuthorUser { get; set; } // Navigation property for User
13+
public User AuthorUser { get; set; } = null!; // Navigation property for User
1414

15-
public List<Comment> Comments { get; set; } // One-to-Many relationship with Comment
15+
public List<Comment> Comments { get; set; } = new(); // One-to-Many relationship with Comment
1616
}
1717
}

src/MLS.Domain/Entities/Category.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace MLS.Domain.Entities
44
{
55
public class Category : BaseEntity
66
{
7-
public string Name { get; set; } // Category name
8-
public string Description { get; set; } // Optional category description
7+
public string Name { get; set; } = string.Empty; // Category name
8+
public string Description { get; set; } = string.Empty; // Optional category description
99

10-
public ICollection<Product> Products { get; set; } // One-to-Many relationship with Product
10+
public ICollection<Product> Products { get; set; } = new List<Product>(); // One-to-Many relationship with Product
1111
}
1212
}

src/MLS.Domain/Entities/Comment.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ namespace MLS.Domain.Entities
44
{
55
public class Comment : BaseEntity
66
{
7-
public string Content { get; set; } // Comment content
8-
public string Author { get; set; } // Comment author name (optional)
7+
public string Content { get; set; } = string.Empty; // Comment content
8+
public string? Author { get; set; } // Comment author name (optional)
99
public DateTime Timestamp { get; set; } // Date and time comment was posted
1010

1111
public int ArticleId { get; set; } // Foreign key referencing Article (optional)
12-
public Article Article { get; set; } // Navigation property for Article
12+
public Article Article { get; set; } = null!; // Navigation property for Article
1313

1414
public int UserId { get; set; } // Foreign key referencing User (optional)
15-
public User Commenter { get; set; } // Navigation property for User
15+
public User Commenter { get; set; } = null!; // Navigation property for User
1616
}
1717
}

src/MLS.Domain/Entities/Discount.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace MLS.Domain.Entities
44
{
55
public class Discount : BaseEntity
66
{
7-
public string Code { get; set; }
7+
public string Code { get; set; } = string.Empty;
88
public decimal Percentage { get; set; } // Percentage discount off the price
99
public DateTime StartDate { get; set; } // Start date of the discount
1010
public DateTime EndDate { get; set; } // End date of the discount

src/MLS.Domain/Entities/Notification.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace MLS.Domain.Entities
44
{
55
public class Notification : BaseEntity
66
{
7-
public string Message { get; set; } // Notification message content
7+
public string Message { get; set; } = string.Empty; // Notification message content
88
public DateTime Timestamp { get; set; } // Date and time notification was sent
99
public bool IsRead { get; set; }
1010

1111
public int UserId { get; set; } // Foreign key referencing User
12-
public User User { get; set; } // Navigation property for User
12+
public User User { get; set; } = null!; // Navigation property for User
1313
}
1414
}

src/MLS.Domain/Entities/Order.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public class Order : BaseEntity
66
{
77
public DateTime OrderDate { get; set; } // Date and time order was placed
88
public decimal TotalPrice { get; set; } // Total order amount including discounts
9-
public string OrderStatus { get; set; } // Order status (e.g., "Pending", "Processing", "Shipped", "Delivered")
9+
public string OrderStatus { get; set; } = string.Empty; // Order status (e.g., "Pending", "Processing", "Shipped", "Delivered")
1010

1111
public int UserId { get; set; } // Foreign key referencing User
12-
public User User { get; set; } // Navigation property for User
12+
public User User { get; set; } = null!; // Navigation property for User
1313

14-
public List<OrderDetail> OrderDetails { get; set; } // One-to-Many relationship with OrderDetail
14+
public List<OrderDetail> OrderDetails { get; set; } = new(); // One-to-Many relationship with OrderDetail
1515
}
1616
}

src/MLS.Domain/Entities/OrderDetail.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace MLS.Domain.Entities
55
public class OrderDetail : BaseEntity
66
{
77
public int ProductId { get; set; } // Foreign key referencing Product
8-
public Product Product { get; set; } // Navigation property for Product
8+
public Product Product { get; set; } = null!; // Navigation property for Product
99

1010
public int Quantity { get; set; } // Quantity of the product ordered
1111
public decimal UnitPrice { get; set; } // UnitPrice of the product at the time of order
1212

1313
public int OrderId { get; set; } // Foreign key referencing Order
14-
public Order Order { get; set; } // Navigation property for Order
14+
public Order Order { get; set; } = null!; // Navigation property for Order
1515
}
1616
}

src/MLS.Domain/Entities/Payment.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace MLS.Domain.Entities
44
{
55
public class Payment : BaseEntity
66
{
7-
public string PaymentMethod { get; set; } // Payment method (e.g., "Credit Card", "PayPal")
7+
public string PaymentMethod { get; set; } = string.Empty; // Payment method (e.g., "Credit Card", "PayPal")
88
public decimal AmountPaid { get; set; } // Amount paid
99
public DateTime PaymentDate { get; set; } // Date and time payment was made
1010

1111
public int OrderId { get; set; } // Foreign key referencing Order
12-
public Order Order { get; set; } // Navigation property for Order
12+
public Order Order { get; set; } = null!; // Navigation property for Order
1313
}
1414
}

src/MLS.Domain/Entities/Product.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ namespace MLS.Domain.Entities
44
{
55
public class Product : BaseEntity
66
{
7-
public string Name { get; set; } // Product name
8-
public string Description { get; set; } // Product description
7+
public string Name { get; set; } = string.Empty; // Product name
8+
public string Description { get; set; } = string.Empty; // Product description
99
public decimal Price { get; set; } // Product price
1010

1111
public int CategoryId { get; set; } // Foreign key referencing Category
12-
public Category Category { get; set; } // Navigation property for Category
12+
public Category Category { get; set; } = null!; // Navigation property for Category
1313

14-
public List<ProductOption> ProductOptions { get; set; } // One-to-Many relationship with ProductOption
15-
public List<ProductColor> ProductColors { get; set; } // One-to-Many relationship with ProductColor
16-
public List<ProductImage> ProductImages { get; set; } // One-to-Many relationship with ProductImage
17-
public List<ProductReview> ProductReviews { get; set; } // One-to-Many relationship with ProductReview
18-
public List<OrderDetail> OrderDetails { get; set; } // One-to-Many relationship with OrderDetail
14+
public List<ProductOption> ProductOptions { get; set; } = new(); // One-to-Many relationship with ProductOption
15+
public List<ProductColor> ProductColors { get; set; } = new(); // One-to-Many relationship with ProductColor
16+
public List<ProductImage> ProductImages { get; set; } = new(); // One-to-Many relationship with ProductImage
17+
public List<ProductReview> ProductReviews { get; set; } = new(); // One-to-Many relationship with ProductReview
18+
public List<OrderDetail> OrderDetails { get; set; } = new(); // One-to-Many relationship with OrderDetail
1919
}
2020
}

src/MLS.Domain/Entities/ProductColor.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace MLS.Domain.Entities
44
{
55
public class ProductColor : BaseEntity
66
{
7-
public string ColorName { get; set; } // Color name (e.g., "Red", "Blue")
8-
public string ColorHexCode { get; set; } // Hexadecimal color code (#FF0000, #0000FF)
7+
public string ColorName { get; set; } = string.Empty; // Color name (e.g., "Red", "Blue")
8+
public string ColorHexCode { get; set; } = string.Empty; // Hexadecimal color code (#FF0000, #0000FF)
99

1010
public int ProductId { get; set; } // Foreign key referencing Product
11-
public Product Product { get; set; } // Navigation property for Product
11+
public Product Product { get; set; } = null!; // Navigation property for Product
1212
}
1313
}

src/MLS.Domain/Entities/ProductImage.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace MLS.Domain.Entities
44
{
55
public class ProductImage : BaseEntity
66
{
7-
public string ImageUrl { get; set; } // URL of the product image
8-
public string ImageDescription { get; set; } // Optional image description
7+
public string ImageUrl { get; set; } = string.Empty; // URL of the product image
8+
public string? ImageDescription { get; set; } // Optional image description
99

1010
public int ProductId { get; set; } // Foreign key referencing Product
11-
public Product Product { get; set; } // Navigation property for Product
11+
public Product Product { get; set; } = null!; // Navigation property for Product
1212
}
1313
}

src/MLS.Domain/Entities/ProductOption.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace MLS.Domain.Entities
44
{
55
public class ProductOption : BaseEntity
66
{
7-
public string Name { get; set; } // Option name (e.g., "Size", "Color")
7+
public string Name { get; set; } = string.Empty; // Option name (e.g., "Size", "Color")
88
public decimal Value { get; set; } // Option value (e.g., "25", "Black")
99

1010
public int ProductId { get; set; } // Foreign key referencing Product
11-
public Product Product { get; set; } // Navigation property for Product
11+
public Product Product { get; set; } = null!; // Navigation property for Product
1212
}
1313
}

src/MLS.Domain/Entities/ProductReview.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace MLS.Domain.Entities
55
public class ProductReview : BaseEntity
66
{
77
public int Rating { get; set; } // Rating out of 5 stars
8-
public string ReviewText { get; set; } // Detailed review text
8+
public string ReviewText { get; set; } = string.Empty; // Detailed review text
99
public DateTime ReviewDate { get; set; } // Date and time review was posted
1010

1111
public int ProductId { get; set; } // Foreign key referencing Product
12-
public Product Product { get; set; } // Navigation property for Product
12+
public Product Product { get; set; } = null!; // Navigation property for Product
1313

1414
public int UserId { get; set; } // Foreign key referencing User
15-
public User User { get; set; } // Navigation property for User
15+
public User User { get; set; } = null!; // Navigation property for User
1616
}
1717
}

src/MLS.Domain/Entities/ProductTag.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace MLS.Domain.Entities
44
{
55
public class ProductTag : BaseEntity
66
{
7-
public string TagName { get; set; } // Tag name (e.g., "Electronics", "Clothing")
7+
public string TagName { get; set; } = string.Empty; // Tag name (e.g., "Electronics", "Clothing")
88

99
public int ProductId { get; set; } // Foreign key referencing Product
10-
public Product Product { get; set; } // Navigation property for Product
10+
public Product Product { get; set; } = null!; // Navigation property for Product
1111

1212
public int TagId { get; set; } // Foreign key referencing Tag
13-
public Tag Tag { get; set; } // Navigation property for Tag
13+
public Tag Tag { get; set; } = null!; // Navigation property for Tag
1414
}
1515
}

src/MLS.Domain/Entities/Shipment.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace MLS.Domain.Entities
44
{
55
public class Shipment : BaseEntity
66
{
7-
public string ShippingMethod { get; set; } // Shipping method (e.g., "UPS Ground", "FedEx Express")
8-
public string TrackingNumber { get; set; } // Tracking number for the shipment
7+
public string ShippingMethod { get; set; } = string.Empty; // Shipping method (e.g., "UPS Ground", "FedEx Express")
8+
public string? TrackingNumber { get; set; } // Tracking number for the shipment
99
public DateTime EstimatedDeliveryDate { get; set; } // Estimated delivery date
1010

1111
public int OrderId { get; set; } // Foreign key referencing Order
12-
public Order Order { get; set; } // Navigation property for Order
12+
public Order Order { get; set; } = null!; // Navigation property for Order
1313
}
1414
}

src/MLS.Domain/Entities/ShoppingCart.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace MLS.Domain.Entities
55
public class ShoppingCart : BaseEntity
66
{
77
public int UserId { get; set; } // Foreign key referencing User
8-
public User User { get; set; } // Navigation property for User
8+
public User User { get; set; } = null!; // Navigation property for User
99

10-
public List<ShoppingCartItem> ShoppingCartItems { get; set; } // One-to-Many relationship with ShoppingCartItem
10+
public List<ShoppingCartItem> ShoppingCartItems { get; set; } = new(); // One-to-Many relationship with ShoppingCartItem
1111
}
1212
}

src/MLS.Domain/Entities/ShoppingCartItem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace MLS.Domain.Entities
55
public class ShoppingCartItem : BaseEntity
66
{
77
public int ProductId { get; set; } // Foreign key referencing Product
8-
public Product Product { get; set; } // Navigation property for Product
8+
public Product Product { get; set; } = null!; // Navigation property for Product
99

1010
public int Quantity { get; set; } // Quantity of the product in the cart
1111
public decimal Price { get; set; } // Price of the product at the time it was added to the cart
1212

1313
public int ShoppingCartId { get; set; } // Foreign key referencing ShoppingCart
14-
public ShoppingCart ShoppingCart { get; set; } // Navigation property for ShoppingCart
14+
public ShoppingCart ShoppingCart { get; set; } = null!; // Navigation property for ShoppingCart
1515
}
1616
}

src/MLS.Domain/Entities/Supplier.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace MLS.Domain.Entities
44
{
55
public class Supplier : BaseEntity
66
{
7-
public string Name { get; set; } // Supplier name
8-
public string ContactEmail { get; set; } // Contact details email
9-
public string ContactPhone { get; set; } // Contact details phone
7+
public string Name { get; set; } = string.Empty; // Supplier name
8+
public string ContactEmail { get; set; } = string.Empty; // Contact details email
9+
public string ContactPhone { get; set; } = string.Empty; // Contact details phone
1010

11-
public List<Product> Products { get; set; } // One-to-Many relationship with Product
11+
public List<Product> Products { get; set; } = new(); // One-to-Many relationship with Product
1212
}
1313
}

src/MLS.Domain/Entities/Supply.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace MLS.Domain.Entities
55
public class Supply : BaseEntity
66
{
77
public int ProductId { get; set; } // Foreign key referencing Product
8-
public Product Product { get; set; } // Navigation property for Product
8+
public Product Product { get; set; } = null!; // Navigation property for Product
99

1010
public int SupplierId { get; set; } // Foreign key referencing Supplier
11-
public Supplier Supplier { get; set; } // Navigation property for Supplier
11+
public Supplier Supplier { get; set; } = null!; // Navigation property for Supplier
1212

1313
public int Quantity { get; set; } // Quantity of the product supplied by the supplier
1414
public decimal Price { get; set; } // Cost of the product from the supplier

src/MLS.Domain/Entities/Tag.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace MLS.Domain.Entities
44
{
55
public class Tag : BaseEntity
66
{
7-
public string Name { get; set; } // Tag name (e.g., "Electronics", "Clothing")
7+
public string Name { get; set; } = string.Empty; // Tag name (e.g., "Electronics", "Clothing")
88

9-
public ICollection<ProductTag> ProductTags { get; set; } // One-to-Many relationship with ProductTag
10-
public ICollection<Article> Articles { get; set; } // One-to-Many relationship with Article (optional)
9+
public ICollection<ProductTag> ProductTags { get; set; } = new List<ProductTag>(); // One-to-Many relationship with ProductTag
10+
public ICollection<Article> Articles { get; set; } = new List<Article>(); // One-to-Many relationship with Article (optional)
1111
}
1212
}

src/MLS.Domain/Entities/User.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ namespace MLS.Domain.Entities
44
{
55
public class User : BaseEntity
66
{
7-
public string Username { get; set; } // Unique username for login
8-
public string Email { get; set; } // User's email address
9-
public string PasswordHash { get; set; } // Hashed password for security
10-
public string FirstName { get; set; } // User's FirstName
11-
public string LastName { get; set; } // User's LastName
12-
public string Phone { get; set; } // User's phone number
7+
public string Username { get; set; } = string.Empty; // Unique username for login
8+
public string Email { get; set; } = string.Empty; // User's email address
9+
public string PasswordHash { get; set; } = string.Empty; // Hashed password for security
10+
public string FirstName { get; set; } = string.Empty; // User's FirstName
11+
public string LastName { get; set; } = string.Empty; // User's LastName
12+
public string Phone { get; set; } = string.Empty; // User's phone number
1313

14-
public ICollection<Order> Orders { get; set; } // One-to-Many relationship with Order
15-
public ICollection<ProductReview> ProductReviews { get; set; } // One-to-Many relationship with ProductReview
16-
public ICollection<WishList> WishLists { get; set; } // One-to-Many relationship with WishList
17-
public ICollection<Comment> Comments { get; set; } // One-to-Many relationship with Comment
18-
public ICollection<Notification> Notifications { get; set; } // One-to-Many relationship with Notification
14+
public ICollection<Order> Orders { get; set; } = new List<Order>(); // One-to-Many relationship with Order
15+
public ICollection<ProductReview> ProductReviews { get; set; } = new List<ProductReview>(); // One-to-Many relationship with ProductReview
16+
public ICollection<WishList> WishLists { get; set; } = new List<WishList>(); // One-to-Many relationship with WishList
17+
public ICollection<Comment> Comments { get; set; } = new List<Comment>(); // One-to-Many relationship with Comment
18+
public ICollection<Notification> Notifications { get; set; } = new List<Notification>(); // One-to-Many relationship with Notification
1919
}
2020
}

0 commit comments

Comments
 (0)