I, as the developer, must create classes to represent the entities outlined within the ERD to all for Entity Framework to import said entities to PostgreSQL database.
Acceptance Criteria
Listed classes should follow the structure and data type of the entities within the provided ERD
Folder hierarchy must be setup to serve as the foundation for the structure of the project. This will include the following:
Models
API Calls
Test Data
DBContext.cs
All tables outside of join tables should refer to their respective classes
The following entities will have a related class file:
[x] Users
[x] Schedule
[x] Class
[x] Notes
ICOllections/Lists will need to be referenced between the following entities
[x] Class + Schedule
Dependencies
N / A, this is one of the first tasks which need to be completed, even before the seeding of test data.
Dev Notes
Class Structure, Models > Orders and Items
Will create the join table between Order and Items
using System.ComponentModel.DataAnnotations;
namespace Bangazon.Models
{
public class Product
{
public int Id { get; set; }
[Required]
public string Title { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public int QuantityAvailable { get; set; }
public float Price { get; set; }
public int SellerId { get; set; }
public int CategoryId { get; set; }
public ICollection Orders { get; set; }
}
}
Examples of utilizing accumulators to generate 'Totals' - CreekRiver:
public decimal? TotalCost
{
get
{
if (Campsite?.CampsiteType != null)
{
return Campsite.CampsiteType.FeePerNight * TotalNights + _reservationBaseFee;
}
return null;
}
}
- DbContext Structure Example:
```chsarp
using Microsoft.EntityFrameworkCore;
using Bangazon.Models;
namespace Bangazon
{
public class BangazonDbContext : DbContext
{
public DbSet<User> Users { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<PaymentType> PaymentTypes { get; set; }
public DbSet<Category> Categories { get; set; }
public BangazonDbContext(DbContextOptions<BangazonDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().HasData(new User[]
{
new User
{
Id = 1,
Username = "kcob",
FirstName = "Keana",
LastName = "Cobarde",
Email = "keanacobarde@gmail.com",
Address = "123 Witchy Lane",
IsSeller = true,
Uid = "Kqa5uPcWOgRIUtiXEBnJbP6VQXB3"
},
new User
{
Id = 2,
Username = "keykey",
FirstName = "Kiki",
LastName = "Wiki",
Email = "keyzelgears@gmail.com",
Address = "124 Witchy Lane",
IsSeller = true,
Uid = "Kqa5uPcWOgRIUtiXEBnJbP6VQXB3"
},
new User
{
Id = 3,
Username = "kira",
FirstName = "June",
LastName = "Bloom",
Email = "junejune22@gmail.com",
Address = "125 Witchy Lane",
IsSeller = false,
Uid = "Kqa5uPcWOgRIUtiXEBnJbP6VQXB3"
}
});
modelBuilder.Entity<Product>().HasData(new Product[]
{
new Product
{
Id = 1,
Title = "Laptop",
Description = "Powerful laptop for all your computing needs",
ImageUrl = "laptop_image_url.jpg",
QuantityAvailable = 50,
Price = 999.99f,
SellerId = 1,
CategoryId = 1,
},
new Product
{
Id = 2,
Title = "Smartphone",
Description = "High-performance smartphone with advanced features",
ImageUrl = "smartphone_image_url.jpg",
QuantityAvailable = 100,
Price = 499.99f,
SellerId = 2,
CategoryId = 2,
},
new Product
{
Id = 3,
Title = "Headphones",
Description = "Premium noise-canceling headphones for an immersive audio experience",
ImageUrl = "headphones_image_url.jpg",
QuantityAvailable = 30,
Price = 149.99f,
SellerId = 1,
CategoryId = 2,
}
});
modelBuilder.Entity<Order>().HasData(new Order[]
{
new Order
{
Id = 1,
CustomerId = 2,
PaymentId = 2,
IsOrderOpen = true,
},
new Order
{
Id = 2,
CustomerId = 2,
PaymentId = 3,
IsOrderOpen = true,
},
new Order
{
Id = 3,
CustomerId = 2,
PaymentId = 1,
IsOrderOpen = false,
}
});
modelBuilder.Entity<PaymentType>().HasData(new PaymentType[]
{
new PaymentType
{
Id = 1,
Name = "Credit",
},
new PaymentType
{
Id = 2,
Name = "Debit Card",
},
new PaymentType
{
Id = 3,
Name = "Cryptocurrency",
},
});
modelBuilder.Entity<Category>().HasData(new Category[]
{
new Category
{
Id = 1,
Name = "Samsung",
},
new Category
{
Id = 2,
Name = "Apple",
},
new Category
{
Id = 3,
Name = "Sony",
},
});
}
}
}
-Seeding Test Data Example
DBCONTEXT
```csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().HasData(UsersData.Users);
modelBuilder.Entity<Item>().HasData(ItemsData.Items);
modelBuilder.Entity<Order>().HasData(OrdersData.Orders);
}
DATA FILE
using HHPWsBe.Models;
namespace HHPWsBe.Data
{
public class ItemsData
{
public static List<Item> Items = new List<Item>
{
new Item() { Id = 1, Name = "Margherita", Price = 8.99M },
new Item() { Id = 2, Name = "Pepperoni", Price = 9.99M },
new Item() { Id = 3, Name = "Vegetarian", Price = 10.99M },
new Item() { Id = 4, Name = "Hawaiian", Price = 11.99M },
};
}
}
User Story
I, as the developer, must create classes to represent the entities outlined within the ERD to all for Entity Framework to import said entities to PostgreSQL database.
Acceptance Criteria
Listed classes should follow the structure and data type of the entities within the provided ERD
Folder hierarchy must be setup to serve as the foundation for the structure of the project. This will include the following:
All tables outside of join tables should refer to their respective classes
The following entities will have a related class file:
[x] Users
[x] Schedule
[x] Class
[x] Notes
ICOllections/Lists will need to be referenced between the following entities
Dependencies
Dev Notes
namespace Bangazon.Models { public class Product { public int Id { get; set; } [Required] public string Title { get; set; } public string Description { get; set; } public string ImageUrl { get; set; } public int QuantityAvailable { get; set; } public float Price { get; set; } public int SellerId { get; set; } public int CategoryId { get; set; } public ICollection Orders { get; set; }
}
}
DATA FILE
-Creating Modularized API Call Example PROGRAM.CS
API FILE