From c9e3374d5de70d60c542928605a61434c05363cf Mon Sep 17 00:00:00 2001 From: Nate VanBuskirk Date: Wed, 13 Nov 2019 10:06:24 -0600 Subject: [PATCH] Changes: ---------- VS Solutions are setup. Additions made to web project. Directory cleanup and movement completed. Updated with publish settings for website project (password NOT inlucded). Pub settings with password are saved in a localized file set that will be stored somewhere and backedup somewhere safe and private to avoid intrusions to webhosting rss. New: ------ Added Basic Models, SQL, EDMX, T4 Text Gen Files, and Auto-Gen'd the backing CS/SQL files. There is a database file added (not tested). There's also a backup of the sql files and other necessary tidbits included. Not Included: --------------- We do not yet have capacity for Scaffolding with current EF version and VS2017 because the backing database either is missing the table(s) OR because there's another issue caused by weirdness with the auto-gen process. No controllers/views/etc exist beyond the default template/wizard junk and the model system employed above. Expectations: --------------- Will need to test further once we've had a chance to back this up and walk through the manual steps to see what got missed by the auto-magic. Next Steps: ------------- Next step(s)/commit(s)/push(es) should include getting the datasbase populated with data-less tables, verifying the entity associations, scaffolding a very basic controller for each major entity, and testing basic add-update-view-delete logic (limited due to the tight relationships between certain tables/entities). More Info: ------------ Once we have the basic skeleton up and working, we can either dig into the Web side OR one of the front-end sides for devices (desktop.winforms, desktop.uwp.touch, mobile.xamarin, etc)... --- Simple-Shop.Tests/App.config | 22 +- Simple-Shop/Models.rar | Bin 0 -> 24357 bytes Simple-Shop/Models/Currency.cs | 32 + Simple-Shop/Models/CurrencyCategory.cs | 29 + Simple-Shop/Models/CurrencyCategoryImage.cs | 25 + Simple-Shop/Models/CurrencyImage.cs | 25 + Simple-Shop/Models/Deal.cs | 30 + Simple-Shop/Models/DealItem.cs | 32 + Simple-Shop/Models/Item.cs | 31 + Simple-Shop/Models/ItemCategory.cs | 31 + Simple-Shop/Models/ItemCategoryImage.cs | 25 + Simple-Shop/Models/ItemImage.cs | 25 + Simple-Shop/Models/Models.Context.cs | 41 + Simple-Shop/Models/Models.Context.tt | 735 +++++++++++++++++ Simple-Shop/Models/Models.Designer.cs | 10 + Simple-Shop/Models/Models.cs | 9 + Simple-Shop/Models/Models.edmx | 309 +++++++ Simple-Shop/Models/Models.edmx.diagram | 43 + Simple-Shop/Models/Models.edmx.sql | 483 +++++++++++ Simple-Shop/Models/Models.md | 1 + Simple-Shop/Models/Models.tt | 845 ++++++++++++++++++++ Simple-Shop/Models/PriceCategory.cs | 32 + Simple-Shop/Models/PricePoint.cs | 30 + Simple-Shop/Models/Tangibility.cs | 20 + Simple-Shop/Simple-Shop.csproj | 89 ++- Simple-Shop/Views/Home/Index.cshtml | 1 + Simple-Shop/Web.config | 92 ++- Simple-Shop/packages.config | 1 + 28 files changed, 3003 insertions(+), 45 deletions(-) create mode 100644 Simple-Shop/Models.rar create mode 100644 Simple-Shop/Models/Currency.cs create mode 100644 Simple-Shop/Models/CurrencyCategory.cs create mode 100644 Simple-Shop/Models/CurrencyCategoryImage.cs create mode 100644 Simple-Shop/Models/CurrencyImage.cs create mode 100644 Simple-Shop/Models/Deal.cs create mode 100644 Simple-Shop/Models/DealItem.cs create mode 100644 Simple-Shop/Models/Item.cs create mode 100644 Simple-Shop/Models/ItemCategory.cs create mode 100644 Simple-Shop/Models/ItemCategoryImage.cs create mode 100644 Simple-Shop/Models/ItemImage.cs create mode 100644 Simple-Shop/Models/Models.Context.cs create mode 100644 Simple-Shop/Models/Models.Context.tt create mode 100644 Simple-Shop/Models/Models.Designer.cs create mode 100644 Simple-Shop/Models/Models.cs create mode 100644 Simple-Shop/Models/Models.edmx create mode 100644 Simple-Shop/Models/Models.edmx.diagram create mode 100644 Simple-Shop/Models/Models.edmx.sql create mode 100644 Simple-Shop/Models/Models.md create mode 100644 Simple-Shop/Models/Models.tt create mode 100644 Simple-Shop/Models/PriceCategory.cs create mode 100644 Simple-Shop/Models/PricePoint.cs create mode 100644 Simple-Shop/Models/Tangibility.cs diff --git a/Simple-Shop.Tests/App.config b/Simple-Shop.Tests/App.config index d736f67..2bd1a5b 100644 --- a/Simple-Shop.Tests/App.config +++ b/Simple-Shop.Tests/App.config @@ -1,4 +1,4 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Simple-Shop/Models/Models.edmx.diagram b/Simple-Shop/Models/Models.edmx.diagram new file mode 100644 index 0000000..6e5b4c4 --- /dev/null +++ b/Simple-Shop/Models/Models.edmx.diagram @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Simple-Shop/Models/Models.edmx.sql b/Simple-Shop/Models/Models.edmx.sql new file mode 100644 index 0000000..1c722c4 --- /dev/null +++ b/Simple-Shop/Models/Models.edmx.sql @@ -0,0 +1,483 @@ + +-- -------------------------------------------------- +-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure +-- -------------------------------------------------- +-- Date Created: 11/12/2019 19:03:35 +-- Generated from EDMX file: D:\@Dev\_\_Repo.ASPnix\simple-shop\Simple-Shop\Models\Models.edmx +-- -------------------------------------------------- + +SET QUOTED_IDENTIFIER OFF; +GO +USE [simple-shop-0]; +GO +IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]'); +GO + +-- -------------------------------------------------- +-- Dropping existing FOREIGN KEY constraints +-- -------------------------------------------------- + + +-- -------------------------------------------------- +-- Dropping existing tables +-- -------------------------------------------------- + + +-- -------------------------------------------------- +-- Creating all tables +-- -------------------------------------------------- + +-- Creating table 'Items' +CREATE TABLE [dbo].[Items] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [Info] nvarchar(max) NULL, + [ItemCategory_Id] int NOT NULL, + [PriceCategory_Id] int NOT NULL, + [DealItem_Id] int NOT NULL +); +GO + +-- Creating table 'ItemCategories' +CREATE TABLE [dbo].[ItemCategories] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [Info] nvarchar(max) NULL, + [Tangibility] int NOT NULL, + [DealItem_Id] int NOT NULL, + [ItemCategoryImage_Id] int NULL +); +GO + +-- Creating table 'PriceCategories' +CREATE TABLE [dbo].[PriceCategories] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [Info] nvarchar(max) NULL +); +GO + +-- Creating table 'PricePoints' +CREATE TABLE [dbo].[PricePoints] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Qty] float NOT NULL, + [Currency_Id] int NOT NULL +); +GO + +-- Creating table 'Deals' +CREATE TABLE [dbo].[Deals] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [Info] nvarchar(max) NOT NULL, + [DateBegin] datetime NOT NULL, + [DateEnd] datetime NULL +); +GO + +-- Creating table 'DealItems' +CREATE TABLE [dbo].[DealItems] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Deal_Id] int NOT NULL, + [PriceCategory_Id] int NULL +); +GO + +-- Creating table 'ItemImages' +CREATE TABLE [dbo].[ItemImages] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [ImageURL] nvarchar(max) NULL, + [Image] nvarchar(max) NOT NULL, + [Author] nvarchar(max) NULL, + [Items_Id] int NULL +); +GO + +-- Creating table 'Currencies' +CREATE TABLE [dbo].[Currencies] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [Type] nvarchar(max) NOT NULL, + [Info] nvarchar(max) NULL, + [CurrencyCategory_Id] int NOT NULL +); +GO + +-- Creating table 'CurrencyCategories' +CREATE TABLE [dbo].[CurrencyCategories] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [Type] nvarchar(max) NOT NULL, + [CurrencyCategoryImage_Id] int NULL +); +GO + +-- Creating table 'ItemCategoryImages' +CREATE TABLE [dbo].[ItemCategoryImages] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [ImageURL] nvarchar(max) NULL, + [Image] varbinary(max) NULL, + [Author] nvarchar(max) NULL +); +GO + +-- Creating table 'CurrencyImages' +CREATE TABLE [dbo].[CurrencyImages] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [ImageURL] nvarchar(max) NULL, + [Image] varbinary(max) NULL, + [Author] nvarchar(max) NULL, + [Currencies_Id] int NULL +); +GO + +-- Creating table 'CurrencyCategoryImages' +CREATE TABLE [dbo].[CurrencyCategoryImages] ( + [Id] int IDENTITY(1,1) NOT NULL, + [Name] nvarchar(max) NOT NULL, + [ImageURL] nvarchar(max) NULL, + [Image] varbinary(max) NULL, + [Author] nvarchar(max) NULL +); +GO + +-- Creating table 'DealItemsPricePoints' +CREATE TABLE [dbo].[DealItemsPricePoints] ( + [DealItem_Id] int NOT NULL, + [PricePoints_Id] int NOT NULL +); +GO + +-- Creating table 'PriceCategoriesPricePoints' +CREATE TABLE [dbo].[PriceCategoriesPricePoints] ( + [PriceCategory_Id] int NOT NULL, + [PricePoints_Id] int NOT NULL +); +GO + +-- -------------------------------------------------- +-- Creating all PRIMARY KEY constraints +-- -------------------------------------------------- + +-- Creating primary key on [Id] in table 'Items' +ALTER TABLE [dbo].[Items] +ADD CONSTRAINT [PK_Items] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'ItemCategories' +ALTER TABLE [dbo].[ItemCategories] +ADD CONSTRAINT [PK_ItemCategories] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'PriceCategories' +ALTER TABLE [dbo].[PriceCategories] +ADD CONSTRAINT [PK_PriceCategories] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'PricePoints' +ALTER TABLE [dbo].[PricePoints] +ADD CONSTRAINT [PK_PricePoints] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'Deals' +ALTER TABLE [dbo].[Deals] +ADD CONSTRAINT [PK_Deals] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'DealItems' +ALTER TABLE [dbo].[DealItems] +ADD CONSTRAINT [PK_DealItems] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'ItemImages' +ALTER TABLE [dbo].[ItemImages] +ADD CONSTRAINT [PK_ItemImages] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'Currencies' +ALTER TABLE [dbo].[Currencies] +ADD CONSTRAINT [PK_Currencies] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'CurrencyCategories' +ALTER TABLE [dbo].[CurrencyCategories] +ADD CONSTRAINT [PK_CurrencyCategories] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'ItemCategoryImages' +ALTER TABLE [dbo].[ItemCategoryImages] +ADD CONSTRAINT [PK_ItemCategoryImages] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'CurrencyImages' +ALTER TABLE [dbo].[CurrencyImages] +ADD CONSTRAINT [PK_CurrencyImages] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [Id] in table 'CurrencyCategoryImages' +ALTER TABLE [dbo].[CurrencyCategoryImages] +ADD CONSTRAINT [PK_CurrencyCategoryImages] + PRIMARY KEY CLUSTERED ([Id] ASC); +GO + +-- Creating primary key on [DealItem_Id], [PricePoints_Id] in table 'DealItemsPricePoints' +ALTER TABLE [dbo].[DealItemsPricePoints] +ADD CONSTRAINT [PK_DealItemsPricePoints] + PRIMARY KEY CLUSTERED ([DealItem_Id], [PricePoints_Id] ASC); +GO + +-- Creating primary key on [PriceCategory_Id], [PricePoints_Id] in table 'PriceCategoriesPricePoints' +ALTER TABLE [dbo].[PriceCategoriesPricePoints] +ADD CONSTRAINT [PK_PriceCategoriesPricePoints] + PRIMARY KEY CLUSTERED ([PriceCategory_Id], [PricePoints_Id] ASC); +GO + +-- -------------------------------------------------- +-- Creating all FOREIGN KEY constraints +-- -------------------------------------------------- + +-- Creating foreign key on [ItemCategory_Id] in table 'Items' +ALTER TABLE [dbo].[Items] +ADD CONSTRAINT [FK_ItemCategoryItem] + FOREIGN KEY ([ItemCategory_Id]) + REFERENCES [dbo].[ItemCategories] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_ItemCategoryItem' +CREATE INDEX [IX_FK_ItemCategoryItem] +ON [dbo].[Items] + ([ItemCategory_Id]); +GO + +-- Creating foreign key on [PriceCategory_Id] in table 'Items' +ALTER TABLE [dbo].[Items] +ADD CONSTRAINT [FK_PriceCategoryItem] + FOREIGN KEY ([PriceCategory_Id]) + REFERENCES [dbo].[PriceCategories] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_PriceCategoryItem' +CREATE INDEX [IX_FK_PriceCategoryItem] +ON [dbo].[Items] + ([PriceCategory_Id]); +GO + +-- Creating foreign key on [Deal_Id] in table 'DealItems' +ALTER TABLE [dbo].[DealItems] +ADD CONSTRAINT [FK_DealsDealItems] + FOREIGN KEY ([Deal_Id]) + REFERENCES [dbo].[Deals] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_DealsDealItems' +CREATE INDEX [IX_FK_DealsDealItems] +ON [dbo].[DealItems] + ([Deal_Id]); +GO + +-- Creating foreign key on [DealItem_Id] in table 'Items' +ALTER TABLE [dbo].[Items] +ADD CONSTRAINT [FK_DealItemsItems] + FOREIGN KEY ([DealItem_Id]) + REFERENCES [dbo].[DealItems] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsItems' +CREATE INDEX [IX_FK_DealItemsItems] +ON [dbo].[Items] + ([DealItem_Id]); +GO + +-- Creating foreign key on [PriceCategory_Id] in table 'DealItems' +ALTER TABLE [dbo].[DealItems] +ADD CONSTRAINT [FK_DealItemsPriceCategories] + FOREIGN KEY ([PriceCategory_Id]) + REFERENCES [dbo].[PriceCategories] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsPriceCategories' +CREATE INDEX [IX_FK_DealItemsPriceCategories] +ON [dbo].[DealItems] + ([PriceCategory_Id]); +GO + +-- Creating foreign key on [DealItem_Id] in table 'DealItemsPricePoints' +ALTER TABLE [dbo].[DealItemsPricePoints] +ADD CONSTRAINT [FK_DealItemsPricePoints_DealItems] + FOREIGN KEY ([DealItem_Id]) + REFERENCES [dbo].[DealItems] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating foreign key on [PricePoints_Id] in table 'DealItemsPricePoints' +ALTER TABLE [dbo].[DealItemsPricePoints] +ADD CONSTRAINT [FK_DealItemsPricePoints_PricePoints] + FOREIGN KEY ([PricePoints_Id]) + REFERENCES [dbo].[PricePoints] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsPricePoints_PricePoints' +CREATE INDEX [IX_FK_DealItemsPricePoints_PricePoints] +ON [dbo].[DealItemsPricePoints] + ([PricePoints_Id]); +GO + +-- Creating foreign key on [PriceCategory_Id] in table 'PriceCategoriesPricePoints' +ALTER TABLE [dbo].[PriceCategoriesPricePoints] +ADD CONSTRAINT [FK_PriceCategoriesPricePoints_PriceCategories] + FOREIGN KEY ([PriceCategory_Id]) + REFERENCES [dbo].[PriceCategories] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating foreign key on [PricePoints_Id] in table 'PriceCategoriesPricePoints' +ALTER TABLE [dbo].[PriceCategoriesPricePoints] +ADD CONSTRAINT [FK_PriceCategoriesPricePoints_PricePoints] + FOREIGN KEY ([PricePoints_Id]) + REFERENCES [dbo].[PricePoints] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_PriceCategoriesPricePoints_PricePoints' +CREATE INDEX [IX_FK_PriceCategoriesPricePoints_PricePoints] +ON [dbo].[PriceCategoriesPricePoints] + ([PricePoints_Id]); +GO + +-- Creating foreign key on [DealItem_Id] in table 'ItemCategories' +ALTER TABLE [dbo].[ItemCategories] +ADD CONSTRAINT [FK_DealItemsItemCategories] + FOREIGN KEY ([DealItem_Id]) + REFERENCES [dbo].[DealItems] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsItemCategories' +CREATE INDEX [IX_FK_DealItemsItemCategories] +ON [dbo].[ItemCategories] + ([DealItem_Id]); +GO + +-- Creating foreign key on [Items_Id] in table 'ItemImages' +ALTER TABLE [dbo].[ItemImages] +ADD CONSTRAINT [FK_ImagesItems] + FOREIGN KEY ([Items_Id]) + REFERENCES [dbo].[Items] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_ImagesItems' +CREATE INDEX [IX_FK_ImagesItems] +ON [dbo].[ItemImages] + ([Items_Id]); +GO + +-- Creating foreign key on [CurrencyCategory_Id] in table 'Currencies' +ALTER TABLE [dbo].[Currencies] +ADD CONSTRAINT [FK_CurrencyCategoryCurrencies] + FOREIGN KEY ([CurrencyCategory_Id]) + REFERENCES [dbo].[CurrencyCategories] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_CurrencyCategoryCurrencies' +CREATE INDEX [IX_FK_CurrencyCategoryCurrencies] +ON [dbo].[Currencies] + ([CurrencyCategory_Id]); +GO + +-- Creating foreign key on [Currency_Id] in table 'PricePoints' +ALTER TABLE [dbo].[PricePoints] +ADD CONSTRAINT [FK_PricePointsCurrencies] + FOREIGN KEY ([Currency_Id]) + REFERENCES [dbo].[Currencies] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_PricePointsCurrencies' +CREATE INDEX [IX_FK_PricePointsCurrencies] +ON [dbo].[PricePoints] + ([Currency_Id]); +GO + +-- Creating foreign key on [ItemCategoryImage_Id] in table 'ItemCategories' +ALTER TABLE [dbo].[ItemCategories] +ADD CONSTRAINT [FK_ItemCategoryImageItemCategory] + FOREIGN KEY ([ItemCategoryImage_Id]) + REFERENCES [dbo].[ItemCategoryImages] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_ItemCategoryImageItemCategory' +CREATE INDEX [IX_FK_ItemCategoryImageItemCategory] +ON [dbo].[ItemCategories] + ([ItemCategoryImage_Id]); +GO + +-- Creating foreign key on [CurrencyCategoryImage_Id] in table 'CurrencyCategories' +ALTER TABLE [dbo].[CurrencyCategories] +ADD CONSTRAINT [FK_CurrencyCategoryImageCurrencyCategory] + FOREIGN KEY ([CurrencyCategoryImage_Id]) + REFERENCES [dbo].[CurrencyCategoryImages] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_CurrencyCategoryImageCurrencyCategory' +CREATE INDEX [IX_FK_CurrencyCategoryImageCurrencyCategory] +ON [dbo].[CurrencyCategories] + ([CurrencyCategoryImage_Id]); +GO + +-- Creating foreign key on [Currencies_Id] in table 'CurrencyImages' +ALTER TABLE [dbo].[CurrencyImages] +ADD CONSTRAINT [FK_CurrencyImageCurrency] + FOREIGN KEY ([Currencies_Id]) + REFERENCES [dbo].[Currencies] + ([Id]) + ON DELETE NO ACTION ON UPDATE NO ACTION; +GO + +-- Creating non-clustered index for FOREIGN KEY 'FK_CurrencyImageCurrency' +CREATE INDEX [IX_FK_CurrencyImageCurrency] +ON [dbo].[CurrencyImages] + ([Currencies_Id]); +GO + +-- -------------------------------------------------- +-- Script has ended +-- -------------------------------------------------- \ No newline at end of file diff --git a/Simple-Shop/Models/Models.md b/Simple-Shop/Models/Models.md new file mode 100644 index 0000000..9b40e48 --- /dev/null +++ b/Simple-Shop/Models/Models.md @@ -0,0 +1 @@ +// Models.edmx # Models.edmx ## TOC 1. Models 1. Pricing 1. PricePoint 1. PriceCategory 1. Currency 1. CurrencyCategory 1. Items 1. Items 1. ItemCategories 1. ItemImages 1. Deals 1. Deals 1. DealItems ## Models ### Pricing #### PricePoint Each PricePoint is a marker with a Qty value and ONE Currency. To represent an item that consists of multiple currencies (in this scenario, a single currency could be represented by something like a penny, nickle, dime, quarter, or dollar; a PriceCategory represents say the American currency), you would need to utilize a PriceCategory. For example, one PriceCategory could be represented as follows: 1q 1d 1n 1p or when aggregated, would look like: 41c. I drew this out because for a simple store for a toddler, you may want to utilize nickels and pennies not as an aggregate, but as separate currencies. For the normal currency system, you wouldn't care if someone used nickels, pennies, etc; but for a small child's money-teaching tool or a system that powers a vending machine limited to specific currency pieces, you DO care about the intricate systems at play within a single IRL currency. That is the system at play here. #### PriceCategory Represents a plurality of PricePoints. If a single price point could be 1q, 1d, 1n, or 1p, a PriceCategory could represent an aggregate of those PricePoints. You do NOT have to separate the coins from eachother OR even from dollars, should you choose to combine them into Dollars while utilizing the decimal notation to represent cents. This merely provides an avenue for being specific while allowing general use as well. #### Currency Not to beat a dead horse here, but a currency can either be represented: 1. **in the most aggregate sense** _(such as American Dollars to represent the entirety of the USA currency system)_ 1. **OR in the specific/system sense** _(such as red tokens, blue tokens, green tokens, 5-dollar-bills, 1-dollar-bills, quarters, dimes, nickels, and pennies)_ . #### CurrencyCategory Represents an amalgamation or system of Currencies. For example, in the systems mentioned above, where each piece of a currency set is specified (a quarter is treated as separate from a dime and a nickel and a penny), then the CurrencyCategory represents the whole system of all Currencies within it. In this instance, you might name it "American Coins" or something similar, distinct from "American Dollar" or whatever you use to represent the entire American currency system. In the example of poker chips of different colors, _"Poker Chip"_ could be the resounding CurrencyCategory. In the case of the American currency system (dollars are the trading currency, but it also includes coins and dollar bills of differing values in relation to the Dollar), _"American $$$"_ or _"American Dollar"_ could be the actual CurrencyCategory. This, too, allows you to have multiple differing systems with similar parts. You could have _"American $$$"_ for one shop, child, or system; then _"American Dollar (Coins)"_ for another; then _"Poker Chip"_ for yet another. The sky, your imagination, and the boxes you create are your only limitation. ### Items #### Items Any item is represented as an objectified representation of some kind which can be either tangible (a toy, a board game, or a consumable such as a piece of candy) OR something intangible such as a visit to the park, a happy meal and visit to McDonalds, getting to stay up an hour later one evening, or getting to spend X minutes/hours on a digital device … to name a few examples. #### ItemCategories ItemCategories are definitions of similarities between items. Use this to help categorize your shop items in a way that they can be filtered by your young consumers-in-training that makes sense to them. You may even want to include a sprite, icon, or image to represent your category such that even those learning to read, or those not quite there yet, can still recognize and take advantage of them. This also will help with future features such as logging, stats, notifications for getting low in stock of certain things (tangible or intangible) that you might need to prioritize. ##### Examples: 1. **Toys** _(tangible)_ 1. **Board Games** _(tangible)_ 1. **Outside Adventures** _(intangible)_ 1. **Visits to the Museum** _(intangible)_ 1. **Fast Food Visits** _(intangible)_ 1. **Consumables** (such as treats, food, stickers, markers, etc) _(tangible)_ #### ItemImages ### Deals #### Deals #### DealItems \ No newline at end of file diff --git a/Simple-Shop/Models/Models.tt b/Simple-Shop/Models/Models.tt new file mode 100644 index 0000000..f2c14a0 --- /dev/null +++ b/Simple-Shop/Models/Models.tt @@ -0,0 +1,845 @@ +<#@ template language="C#" debug="false" hostspecific="true"#> +<#@ include file="EF.Utility.CS.ttinclude"#><#@ + output extension=".cs"#><# + +const string inputFile = @"Models.edmx"; +var textTransform = DynamicTextTransformation.Create(this); +var code = new CodeGenerationTools(this); +var ef = new MetadataTools(this); +var typeMapper = new TypeMapper(code, ef, textTransform.Errors); +var fileManager = EntityFrameworkTemplateFileManager.Create(this); +var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile); +var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef); + +if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile)) +{ + return string.Empty; +} + +WriteHeader(codeStringGenerator, fileManager); + +foreach (var entity in typeMapper.GetItemsToGenerate(itemCollection)) +{ + fileManager.StartNewFile(entity.Name + ".cs"); + BeginNamespace(code); +#> +<#=codeStringGenerator.UsingDirectives(inHeader: false)#> +<#=codeStringGenerator.EntityClassOpening(entity)#> +{ +<# + var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity); + var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity); + var complexProperties = typeMapper.GetComplexProperties(entity); + + if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any()) + { +#> + public <#=code.Escape(entity)#>() + { +<# + foreach (var edmProperty in propertiesWithDefaultValues) + { +#> + this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>; +<# + } + + foreach (var navigationProperty in collectionNavigationProperties) + { +#> + this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>(); +<# + } + + foreach (var complexProperty in complexProperties) + { +#> + this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>(); +<# + } +#> + } + +<# + } + + var simpleProperties = typeMapper.GetSimpleProperties(entity); + if (simpleProperties.Any()) + { + foreach (var edmProperty in simpleProperties) + { +#> + <#=codeStringGenerator.Property(edmProperty)#> +<# + } + } + + if (complexProperties.Any()) + { +#> + +<# + foreach(var complexProperty in complexProperties) + { +#> + <#=codeStringGenerator.Property(complexProperty)#> +<# + } + } + + var navigationProperties = typeMapper.GetNavigationProperties(entity); + if (navigationProperties.Any()) + { +#> + +<# + foreach (var navigationProperty in navigationProperties) + { +#> + <#=codeStringGenerator.NavigationProperty(navigationProperty)#> +<# + } + } +#> +} +<# + EndNamespace(code); +} + +foreach (var complex in typeMapper.GetItemsToGenerate(itemCollection)) +{ + fileManager.StartNewFile(complex.Name + ".cs"); + BeginNamespace(code); +#> +<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#> +<#=Accessibility.ForType(complex)#> partial class <#=code.Escape(complex)#> +{ +<# + var complexProperties = typeMapper.GetComplexProperties(complex); + var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(complex); + + if (propertiesWithDefaultValues.Any() || complexProperties.Any()) + { +#> + public <#=code.Escape(complex)#>() + { +<# + foreach (var edmProperty in propertiesWithDefaultValues) + { +#> + this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>; +<# + } + + foreach (var complexProperty in complexProperties) + { +#> + this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>(); +<# + } +#> + } + +<# + } + + var simpleProperties = typeMapper.GetSimpleProperties(complex); + if (simpleProperties.Any()) + { + foreach(var edmProperty in simpleProperties) + { +#> + <#=codeStringGenerator.Property(edmProperty)#> +<# + } + } + + if (complexProperties.Any()) + { +#> + +<# + foreach(var edmProperty in complexProperties) + { +#> + <#=codeStringGenerator.Property(edmProperty)#> +<# + } + } +#> +} +<# + EndNamespace(code); +} + +foreach (var enumType in typeMapper.GetEnumItemsToGenerate(itemCollection)) +{ + fileManager.StartNewFile(enumType.Name + ".cs"); + BeginNamespace(code); +#> +<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#> +<# + if (typeMapper.EnumIsFlags(enumType)) + { +#> +[Flags] +<# + } +#> +<#=codeStringGenerator.EnumOpening(enumType)#> +{ +<# + var foundOne = false; + + foreach (MetadataItem member in typeMapper.GetEnumMembers(enumType)) + { + foundOne = true; +#> + <#=code.Escape(typeMapper.GetEnumMemberName(member))#> = <#=typeMapper.GetEnumMemberValue(member)#>, +<# + } + + if (foundOne) + { + this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 3, 1); + } +#> +} +<# + EndNamespace(code); +} + +fileManager.Process(); + +#> +<#+ + +public void WriteHeader(CodeStringGenerator codeStringGenerator, EntityFrameworkTemplateFileManager fileManager) +{ + fileManager.StartHeader(); +#> +//------------------------------------------------------------------------------ +// +// <#=GetResourceString("Template_GeneratedCodeCommentLine1")#> +// +// <#=GetResourceString("Template_GeneratedCodeCommentLine2")#> +// <#=GetResourceString("Template_GeneratedCodeCommentLine3")#> +// +//------------------------------------------------------------------------------ +<#=codeStringGenerator.UsingDirectives(inHeader: true)#> +<#+ + fileManager.EndBlock(); +} + +public void BeginNamespace(CodeGenerationTools code) +{ + var codeNamespace = code.VsNamespaceSuggestion(); + if (!String.IsNullOrEmpty(codeNamespace)) + { +#> +namespace <#=code.EscapeNamespace(codeNamespace)#> +{ +<#+ + PushIndent(" "); + } +} + +public void EndNamespace(CodeGenerationTools code) +{ + if (!String.IsNullOrEmpty(code.VsNamespaceSuggestion())) + { + PopIndent(); +#> +} +<#+ + } +} + +public const string TemplateId = "CSharp_DbContext_Types_EF5"; + +public class CodeStringGenerator +{ + private readonly CodeGenerationTools _code; + private readonly TypeMapper _typeMapper; + private readonly MetadataTools _ef; + + public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef) + { + ArgumentNotNull(code, "code"); + ArgumentNotNull(typeMapper, "typeMapper"); + ArgumentNotNull(ef, "ef"); + + _code = code; + _typeMapper = typeMapper; + _ef = ef; + } + + public string Property(EdmProperty edmProperty) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + Accessibility.ForProperty(edmProperty), + _typeMapper.GetTypeName(edmProperty.TypeUsage), + _code.Escape(edmProperty), + _code.SpaceAfter(Accessibility.ForGetter(edmProperty)), + _code.SpaceAfter(Accessibility.ForSetter(edmProperty))); + } + + public string NavigationProperty(NavigationProperty navigationProperty) + { + var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType()); + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)), + navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType, + _code.Escape(navigationProperty), + _code.SpaceAfter(Accessibility.ForGetter(navigationProperty)), + _code.SpaceAfter(Accessibility.ForSetter(navigationProperty))); + } + + public string AccessibilityAndVirtual(string accessibility) + { + return accessibility + (accessibility != "private" ? " virtual" : ""); + } + + public string EntityClassOpening(EntityType entity) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1}partial class {2}{3}", + Accessibility.ForType(entity), + _code.SpaceAfter(_code.AbstractOption(entity)), + _code.Escape(entity), + _code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType))); + } + + public string EnumOpening(SimpleType enumType) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} enum {1} : {2}", + Accessibility.ForType(enumType), + _code.Escape(enumType), + _code.Escape(_typeMapper.UnderlyingClrType(enumType))); + } + + public void WriteFunctionParameters(EdmFunction edmFunction, Action writeParameter) + { + var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); + foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable)) + { + var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null"; + var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")"; + var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + parameter.RawClrTypeName + "))"; + writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit); + } + } + + public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace) + { + var parameters = _typeMapper.GetParameters(edmFunction); + + return string.Format( + CultureInfo.InvariantCulture, + "{0} IQueryable<{1}> {2}({3})", + AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), + _typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), + _code.Escape(edmFunction), + string.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray())); + } + + public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace) + { + var parameters = _typeMapper.GetParameters(edmFunction); + + return string.Format( + CultureInfo.InvariantCulture, + "return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});", + _typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), + edmFunction.NamespaceName, + edmFunction.Name, + string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()), + _code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))); + } + + public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) + { + var parameters = _typeMapper.GetParameters(edmFunction); + var returnType = _typeMapper.GetReturnType(edmFunction); + + var paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray()); + if (includeMergeOption) + { + paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption"; + } + + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2}({3})", + AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), + returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", + _code.Escape(edmFunction), + paramList); + } + + public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) + { + var parameters = _typeMapper.GetParameters(edmFunction); + var returnType = _typeMapper.GetReturnType(edmFunction); + + var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())); + if (includeMergeOption) + { + callParams = ", mergeOption" + callParams; + } + + return string.Format( + CultureInfo.InvariantCulture, + "return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});", + returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", + edmFunction.Name, + callParams); + } + + public string DbSet(EntitySet entitySet) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} DbSet<{1}> {2} {{ get; set; }}", + Accessibility.ForReadOnlyProperty(entitySet), + _typeMapper.GetTypeName(entitySet.ElementType), + _code.Escape(entitySet)); + } + + public string UsingDirectives(bool inHeader, bool includeCollections = true) + { + return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion()) + ? string.Format( + CultureInfo.InvariantCulture, + "{0}using System;{1}" + + "{2}", + inHeader ? Environment.NewLine : "", + includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "", + inHeader ? "" : Environment.NewLine) + : ""; + } +} + +public class TypeMapper +{ + private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName"; + + private readonly System.Collections.IList _errors; + private readonly CodeGenerationTools _code; + private readonly MetadataTools _ef; + + public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors) + { + ArgumentNotNull(code, "code"); + ArgumentNotNull(ef, "ef"); + ArgumentNotNull(errors, "errors"); + + _code = code; + _ef = ef; + _errors = errors; + } + + public string GetTypeName(TypeUsage typeUsage) + { + return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null); + } + + public string GetTypeName(EdmType edmType) + { + return GetTypeName(edmType, isNullable: null, modelNamespace: null); + } + + public string GetTypeName(TypeUsage typeUsage, string modelNamespace) + { + return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace); + } + + public string GetTypeName(EdmType edmType, string modelNamespace) + { + return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace); + } + + public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace) + { + if (edmType == null) + { + return null; + } + + var collectionType = edmType as CollectionType; + if (collectionType != null) + { + return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace)); + } + + var typeName = _code.Escape(edmType.MetadataProperties + .Where(p => p.Name == ExternalTypeNameAttributeName) + .Select(p => (string)p.Value) + .FirstOrDefault()) + ?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ? + _code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) : + _code.Escape(edmType)); + + if (edmType is StructuralType) + { + return typeName; + } + + if (edmType is SimpleType) + { + var clrType = UnderlyingClrType(edmType); + if (!IsEnumType(edmType)) + { + typeName = _code.Escape(clrType); + } + + return clrType.IsValueType && isNullable == true ? + String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) : + typeName; + } + + throw new ArgumentException("edmType"); + } + + public Type UnderlyingClrType(EdmType edmType) + { + ArgumentNotNull(edmType, "edmType"); + + var primitiveType = edmType as PrimitiveType; + if (primitiveType != null) + { + return primitiveType.ClrEquivalentType; + } + + if (IsEnumType(edmType)) + { + return GetEnumUnderlyingType(edmType).ClrEquivalentType; + } + + return typeof(object); + } + + public object GetEnumMemberValue(MetadataItem enumMember) + { + ArgumentNotNull(enumMember, "enumMember"); + + var valueProperty = enumMember.GetType().GetProperty("Value"); + return valueProperty == null ? null : valueProperty.GetValue(enumMember, null); + } + + public string GetEnumMemberName(MetadataItem enumMember) + { + ArgumentNotNull(enumMember, "enumMember"); + + var nameProperty = enumMember.GetType().GetProperty("Name"); + return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null); + } + + public System.Collections.IEnumerable GetEnumMembers(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + var membersProperty = enumType.GetType().GetProperty("Members"); + return membersProperty != null + ? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null) + : Enumerable.Empty(); + } + + public bool EnumIsFlags(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + var isFlagsProperty = enumType.GetType().GetProperty("IsFlags"); + return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null); + } + + public bool IsEnumType(GlobalItem edmType) + { + ArgumentNotNull(edmType, "edmType"); + + return edmType.GetType().Name == "EnumType"; + } + + public PrimitiveType GetEnumUnderlyingType(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null); + } + + public string CreateLiteral(object value) + { + if (value == null || value.GetType() != typeof(TimeSpan)) + { + return _code.CreateLiteral(value); + } + + return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks); + } + + public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable types, string sourceFile) + { + ArgumentNotNull(types, "types"); + ArgumentNotNull(sourceFile, "sourceFile"); + + var hash = new HashSet(StringComparer.InvariantCultureIgnoreCase); + if (types.Any(item => !hash.Add(item))) + { + _errors.Add( + new CompilerError(sourceFile, -1, -1, "6023", + String.Format(CultureInfo.CurrentCulture, GetResourceString("Template_CaseInsensitiveTypeConflict")))); + return false; + } + return true; + } + + public IEnumerable GetEnumItemsToGenerate(IEnumerable itemCollection) + { + return GetItemsToGenerate(itemCollection) + .Where(e => IsEnumType(e)); + } + + public IEnumerable GetItemsToGenerate(IEnumerable itemCollection) where T: EdmType + { + return itemCollection + .OfType() + .Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName)) + .OrderBy(i => i.Name); + } + + public IEnumerable GetAllGlobalItems(IEnumerable itemCollection) + { + return itemCollection + .Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i)) + .Select(g => GetGlobalItemName(g)); + } + + public string GetGlobalItemName(GlobalItem item) + { + if (item is EdmType) + { + return ((EdmType)item).Name; + } + else + { + return ((EntityContainer)item).Name; + } + } + + public IEnumerable GetSimpleProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetSimpleProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetPropertiesWithDefaultValues(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetPropertiesWithDefaultValues(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type); + } + + public IEnumerable GetCollectionNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many); + } + + public FunctionParameter GetReturnParameter(EdmFunction edmFunction) + { + ArgumentNotNull(edmFunction, "edmFunction"); + + var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters"); + return returnParamsProperty == null + ? edmFunction.ReturnParameter + : ((IEnumerable)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault(); + } + + public bool IsComposable(EdmFunction edmFunction) + { + ArgumentNotNull(edmFunction, "edmFunction"); + + var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute"); + return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null); + } + + public IEnumerable GetParameters(EdmFunction edmFunction) + { + return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); + } + + public TypeUsage GetReturnType(EdmFunction edmFunction) + { + var returnParam = GetReturnParameter(edmFunction); + return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage); + } + + public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption) + { + var returnType = GetReturnType(edmFunction); + return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType; + } +} + +public class EdmMetadataLoader +{ + private readonly IDynamicHost _host; + private readonly System.Collections.IList _errors; + + public EdmMetadataLoader(IDynamicHost host, System.Collections.IList errors) + { + ArgumentNotNull(host, "host"); + ArgumentNotNull(errors, "errors"); + + _host = host; + _errors = errors; + } + + public IEnumerable CreateEdmItemCollection(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + if (!ValidateInputPath(sourcePath)) + { + return new EdmItemCollection(); + } + + var schemaElement = LoadRootElement(_host.ResolvePath(sourcePath)); + if (schemaElement != null) + { + using (var reader = schemaElement.CreateReader()) + { + IList errors; + var itemCollection = MetadataItemCollectionFactory.CreateEdmItemCollection(new[] { reader }, out errors); + + ProcessErrors(errors, sourcePath); + + return itemCollection; + } + } + return new EdmItemCollection(); + } + + public string GetModelNamespace(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + if (!ValidateInputPath(sourcePath)) + { + return string.Empty; + } + + var model = LoadRootElement(_host.ResolvePath(sourcePath)); + if (model == null) + { + return string.Empty; + } + + var attribute = model.Attribute("Namespace"); + return attribute != null ? attribute.Value : ""; + } + + private bool ValidateInputPath(string sourcePath) + { + if (sourcePath == "$" + "edmxInputFile" + "$") + { + _errors.Add( + new CompilerError(_host.TemplateFile ?? sourcePath, 0, 0, string.Empty, + GetResourceString("Template_ReplaceVsItemTemplateToken"))); + return false; + } + + return true; + } + + public XElement LoadRootElement(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + var root = XElement.Load(sourcePath, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo); + return root.Elements() + .Where(e => e.Name.LocalName == "Runtime") + .Elements() + .Where(e => e.Name.LocalName == "ConceptualModels") + .Elements() + .Where(e => e.Name.LocalName == "Schema") + .FirstOrDefault() + ?? root; + } + + private void ProcessErrors(IEnumerable errors, string sourceFilePath) + { + foreach (var error in errors) + { + _errors.Add( + new CompilerError( + error.SchemaLocation ?? sourceFilePath, + error.Line, + error.Column, + error.ErrorCode.ToString(CultureInfo.InvariantCulture), + error.Message) + { + IsWarning = error.Severity == EdmSchemaErrorSeverity.Warning + }); + } + } + + public bool IsLazyLoadingEnabled(EntityContainer container) + { + string lazyLoadingAttributeValue; + var lazyLoadingAttributeName = MetadataConstants.EDM_ANNOTATION_09_02 + ":LazyLoadingEnabled"; + bool isLazyLoading; + return !MetadataTools.TryGetStringMetadataPropertySetting(container, lazyLoadingAttributeName, out lazyLoadingAttributeValue) + || !bool.TryParse(lazyLoadingAttributeValue, out isLazyLoading) + || isLazyLoading; + } +} + +public static void ArgumentNotNull(T arg, string name) where T : class +{ + if (arg == null) + { + throw new ArgumentNullException(name); + } +} + +private static readonly Lazy ResourceManager = + new Lazy( + () => new System.Resources.ResourceManager("System.Data.Entity.Design", typeof(MetadataItemCollectionFactory).Assembly), isThreadSafe: true); + +public static string GetResourceString(string resourceName) +{ + ArgumentNotNull(resourceName, "resourceName"); + + return ResourceManager.Value.GetString(resourceName, null); +} + +#> \ No newline at end of file diff --git a/Simple-Shop/Models/PriceCategory.cs b/Simple-Shop/Models/PriceCategory.cs new file mode 100644 index 0000000..5c26fc0 --- /dev/null +++ b/Simple-Shop/Models/PriceCategory.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Simple_Shop.Models +{ + using System; + using System.Collections.Generic; + + public partial class PriceCategory + { + public PriceCategory() + { + this.Items = new HashSet(); + this.DealItem = new HashSet(); + this.PricePoints = new HashSet(); + } + + public int Id { get; set; } + public string Name { get; set; } + public string Info { get; set; } + + public virtual ICollection Items { get; set; } + public virtual ICollection DealItem { get; set; } + public virtual ICollection PricePoints { get; set; } + } +} diff --git a/Simple-Shop/Models/PricePoint.cs b/Simple-Shop/Models/PricePoint.cs new file mode 100644 index 0000000..eda8213 --- /dev/null +++ b/Simple-Shop/Models/PricePoint.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Simple_Shop.Models +{ + using System; + using System.Collections.Generic; + + public partial class PricePoint + { + public PricePoint() + { + this.DealItem = new HashSet(); + this.PriceCategory = new HashSet(); + } + + public int Id { get; set; } + public double Qty { get; set; } + + public virtual ICollection DealItem { get; set; } + public virtual ICollection PriceCategory { get; set; } + public virtual Currency Currency { get; set; } + } +} diff --git a/Simple-Shop/Models/Tangibility.cs b/Simple-Shop/Models/Tangibility.cs new file mode 100644 index 0000000..69b9418 --- /dev/null +++ b/Simple-Shop/Models/Tangibility.cs @@ -0,0 +1,20 @@ +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Simple_Shop.Models +{ + using System; + + public enum Tangibility : int + { + Unknown = 1, + Tangible = 2, + Intangible = 4 + } +} diff --git a/Simple-Shop/Simple-Shop.csproj b/Simple-Shop/Simple-Shop.csproj index 177cddc..520fd99 100644 --- a/Simple-Shop/Simple-Shop.csproj +++ b/Simple-Shop/Simple-Shop.csproj @@ -46,10 +46,18 @@ 4 + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + + + @@ -165,6 +173,60 @@ Global.asax + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + Models.tt + + + True + True + Models.Context.tt + + + True + True + Models.tt + + + True + True + Models.edmx + + + Models.tt + + + Models.tt + + + Models.tt + @@ -176,11 +238,32 @@ + + TextTemplatingFileGenerator + Models.Context.cs + Models.edmx + + + + + TextTemplatingFileGenerator + Models.cs + Models.edmx + + + PreserveNewest + + EntityModelCodeGenerator + Models.Designer.cs + + + Models.edmx + @@ -211,7 +294,8 @@ - + + @@ -226,6 +310,9 @@ + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/Simple-Shop/Views/Home/Index.cshtml b/Simple-Shop/Views/Home/Index.cshtml index 32e1dd9..6aa41f0 100644 --- a/Simple-Shop/Views/Home/Index.cshtml +++ b/Simple-Shop/Views/Home/Index.cshtml @@ -1,5 +1,6 @@ @{ ViewBag.Title = "Home Page"; + //ViewBag.Items = }
diff --git a/Simple-Shop/Web.config b/Simple-Shop/Web.config index 1dd54f4..dee598e 100644 --- a/Simple-Shop/Web.config +++ b/Simple-Shop/Web.config @@ -4,82 +4,88 @@ https://go.microsoft.com/fwlink/?LinkId=301880 --> + + +
+ + - - - - + + + + - - + + - + - - - - + + + + - - - - + + + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + + + + + + + + + + \ No newline at end of file diff --git a/Simple-Shop/packages.config b/Simple-Shop/packages.config index c260415..dedfcf1 100644 --- a/Simple-Shop/packages.config +++ b/Simple-Shop/packages.config @@ -2,6 +2,7 @@ +