Skip to content

Commit

Permalink
[UI] Added Project
Browse files Browse the repository at this point in the history
  • Loading branch information
hidayatarg committed Nov 24, 2023
1 parent f473390 commit 5cb3098
Show file tree
Hide file tree
Showing 73 changed files with 2,803 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/WebApps/AspnetRunBasics/AspnetRunBasics.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>cd5124f0-00bb-4cff-b8b9-dc4e11396fa3</UserSecretsId>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
</ItemGroup>



</Project>
20 changes: 20 additions & 0 deletions src/WebApps/AspnetRunBasics/Data/AspnetRunContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using AspnetRunBasics.Entities;
using Microsoft.EntityFrameworkCore;

namespace AspnetRunBasics.Data
{
public class AspnetRunContext : DbContext
{
public AspnetRunContext(DbContextOptions<AspnetRunContext> options)
: base(options)
{
}

public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Cart> Carts { get; set; }
public DbSet<CartItem> CartItems { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Contact> Contacts { get; set; }
}
}
133 changes: 133 additions & 0 deletions src/WebApps/AspnetRunBasics/Data/AspnetRunContextSeed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using AspnetRunBasics.Entities;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AspnetRunBasics.Data
{
public class AspnetRunContextSeed
{
public static async Task SeedAsync(AspnetRunContext aspnetrunContext, ILoggerFactory loggerFactory, int? retry = 0)
{
int retryForAvailability = retry.Value;

try
{
// TODO: Only run this if using a real database
// aspnetrunContext.Database.Migrate();
// aspnetrunContext.Database.EnsureCreated();

if (!aspnetrunContext.Categories.Any())
{
aspnetrunContext.Categories.AddRange(GetPreconfiguredCategories());
await aspnetrunContext.SaveChangesAsync();
}

if (!aspnetrunContext.Products.Any())
{
aspnetrunContext.Products.AddRange(GetPreconfiguredProducts());
await aspnetrunContext.SaveChangesAsync();
}
}
catch (Exception exception)
{
if (retryForAvailability < 10)
{
retryForAvailability++;
var log = loggerFactory.CreateLogger<AspnetRunContextSeed>();
log.LogError(exception.Message);
await SeedAsync(aspnetrunContext, loggerFactory, retryForAvailability);
}
throw;
}
}

private static IEnumerable<Category> GetPreconfiguredCategories()
{
return new List<Category>()
{
new Category()
{
Name = "White Appliances",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat.",
ImageName = "one"
},
new Category()
{
Name = "Smart Watches",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat.",
ImageName = "two"
},
new Category()
{
Name = "Home & Kitchen",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat.",
ImageName = "tree"
}
};
}

private static IEnumerable<Product> GetPreconfiguredProducts()
{
return new List<Product>()
{
new Product()
{
Name = "IPhone X",
Summary = "This phone is the company's biggest change to its flagship smartphone in years. It includes a borderless.",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.",
ImageFile = "product-1.png",
Price = 950.00M,
CategoryId = 1
},
new Product()
{
Name = "Samsung 10",
Summary = "This phone is the company's biggest change to its flagship smartphone in years. It includes a borderless.",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.",
ImageFile = "product-2.png",
Price = 840.00M,
CategoryId = 1
},
new Product()
{
Name = "Huawei Plus",
Summary = "This phone is the company's biggest change to its flagship smartphone in years. It includes a borderless.",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.",
ImageFile = "product-3.png",
Price = 650.00M,
CategoryId = 2
},
new Product()
{
Name = "Xiaomi Mi 9",
Summary = "This phone is the company's biggest change to its flagship smartphone in years. It includes a borderless.",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.",
ImageFile = "product-4.png",
Price = 470.00M,
CategoryId = 1
},
new Product()
{
Name = "HTC U11+ Plus",
Summary = "This phone is the company's biggest change to its flagship smartphone in years. It includes a borderless.",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.",
ImageFile = "product-5.png",
Price = 380.00M,
CategoryId = 1
},
new Product()
{
Name = "LG G7 ThinQ",
Summary = "This phone is the company's biggest change to its flagship smartphone in years. It includes a borderless.",
Description = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.",
ImageFile = "product-6.png",
Price = 240.00M,
CategoryId = 1
}
};
}
}
}
25 changes: 25 additions & 0 deletions src/WebApps/AspnetRunBasics/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1709 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1709 AS build
WORKDIR /src
COPY ["AspnetRunBasics/AspnetRunBasics.csproj", "AspnetRunBasics/"]
RUN dotnet restore "AspnetRunBasics/AspnetRunBasics.csproj"
COPY . .
WORKDIR "/src/AspnetRunBasics"
RUN dotnet build "AspnetRunBasics.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "AspnetRunBasics.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AspnetRunBasics.dll"]
25 changes: 25 additions & 0 deletions src/WebApps/AspnetRunBasics/Entities/Cart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace AspnetRunBasics.Entities
{
public class Cart
{
public int Id { get; set; }
public string UserName { get; set; }
public List<CartItem> Items { get; set; } = new List<CartItem>();

public decimal TotalPrice
{
get
{
decimal totalprice = 0;
foreach (var item in Items)
{
totalprice += item.Price * item.Quantity;
}

return totalprice;
}
}
}
}
12 changes: 12 additions & 0 deletions src/WebApps/AspnetRunBasics/Entities/CartItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace AspnetRunBasics.Entities
{
public class CartItem
{
public int Id { get; set; }
public int Quantity { get; set; }
public string Color { get; set; }
public decimal Price { get; set; }
public int ProductId { get; set; }
public Product Product { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/WebApps/AspnetRunBasics/Entities/Category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;

namespace AspnetRunBasics.Entities
{
public class Category
{
public int Id { get; set; }

[Required, StringLength(80)]
public string Name { get; set; }
public string Description { get; set; }
public string ImageName { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/WebApps/AspnetRunBasics/Entities/Contact.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;

namespace AspnetRunBasics.Entities
{
public class Contact
{
public int Id { get; set; }

[Required]
public string Name { get; set; }

[Phone]
[Required]
public string Phone { get; set; }

[Required]
public string Email { get; set; }

[MinLength(10)]
[Required]
public string Message { get; set; }
}
}
32 changes: 32 additions & 0 deletions src/WebApps/AspnetRunBasics/Entities/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace AspnetRunBasics.Entities
{
public class Order
{
public int Id { get; set; }
public string UserName { get; set; }
public decimal TotalPrice { get; set; }

// BillingAddress
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string AddressLine { get; set; }
public string Country { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }

// Payment
public string CardName { get; set; }
public string CardNumber { get; set; }
public string Expiration { get; set; }
public string CVV { get; set; }
public PaymentMethod PaymentMethod { get; set; }
}

public enum PaymentMethod
{
CreditCard = 1,
DebitCard = 2,
Paypal = 3
}
}
19 changes: 19 additions & 0 deletions src/WebApps/AspnetRunBasics/Entities/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;

namespace AspnetRunBasics.Entities
{
public class Product
{
public int Id { get; set; }

[Required, StringLength(80)]
public string Name { get; set; }

public string Summary { get; set; }
public string Description { get; set; }
public string ImageFile { get; set; }
public decimal Price { get; set; }
public int CategoryId { get; set; }
public Category Category { get; set; }
}
}
Loading

0 comments on commit 5cb3098

Please sign in to comment.