Initial git push

This commit is contained in:
2019-12-17 20:44:55 +01:00
parent ab59feeebb
commit 766869a6d6
19 changed files with 818 additions and 0 deletions

25
H_PLUS_Sports.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "H_PLUS_Sports", "H_PLUS_Sports\H_PLUS_Sports.csproj", "{A5EEAD5D-227A-482E-AD66-F17D87C1E187}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5EEAD5D-227A-482E-AD66-F17D87C1E187}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E5C4E67-84F5-41E0-B246-265388B554AE}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using H_PLUS_Sports.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace H_PLUS_Sports.Controllers
{
[Produces("application/json")]
[Route("api/Customers")]
// [ApiController]
public class CustomersController : ControllerBase
{
private readonly H_Plus_SportsContext _context;
public CustomersController(H_Plus_SportsContext context)
{
_context = context;
}
[HttpGet]
public IActionResult GetCustomer()
{
var results = new ObjectResult(_context.Customer)
{
StatusCode = (int)HttpStatusCode.OK
};
Request.HttpContext.Response.Headers.Add("X-Total-Count", _context.Customer.Count().ToString());
return results;
}
[HttpGet("{id}", Name = "GetCustomer")]
public async Task<IActionResult> GetCustomer([FromRoute] int id)
{
if ((CustomerExists(id)))
{
var customer = await _context.Customer.SingleOrDefaultAsync(m => m.CustomerId == id);
return Ok(customer);
}
else
{
return NotFound();
}
}
private bool CustomerExists(int id)
{
return _context.Customer.Any(c => c.CustomerId == id);
}
[HttpPost]
public async Task<IActionResult> PostCustomer([FromBody] Customer customer)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_context.Customer.Add(customer);
await _context.SaveChangesAsync();
return CreatedAtAction("getCustomer", new { id = customer.CustomerId }, customer);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutCustomer([FromRoute] int id, [FromBody] Customer customer)
{
_context.Entry(customer).State = EntityState.Modified;
await _context.SaveChangesAsync();
return Ok(customer);
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteCustomer([FromRoute] int id)
{
var customer = await _context.Customer.SingleOrDefaultAsync(m => m.CustomerId == id);
_context.Customer.Remove(customer);
await _context.SaveChangesAsync();
return Ok(customer);
}
}
}

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using H_PLUS_Sports.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace HPlusSportsAPI.Controllers
{
[Produces("application/json")]
[Route("api/OrderItems")]
public class OrderItemsController : Controller
{
private readonly H_Plus_SportsContext _context;
public OrderItemsController(H_Plus_SportsContext context)
{
_context = context;
}
[HttpGet]
public IActionResult GetOrderItem()
{
return new ObjectResult(_context.OrderItem);
}
[HttpGet("{id}", Name = "GetOrderItem")]
public async Task<IActionResult> GetOrderItem([FromRoute] int id)
{
var orderItem = await _context.OrderItem.SingleOrDefaultAsync(m => m.OrderItemId == id);
return Ok(orderItem);
}
[HttpPost]
public async Task<IActionResult> PostOrderItem([FromBody] OrderItem orderItem)
{
_context.OrderItem.Add(orderItem);
await _context.SaveChangesAsync();
return CreatedAtAction("getOrderItem", new { id = orderItem.OrderItemId }, orderItem);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutOrderItem([FromRoute] int id, [FromBody] OrderItem orderItem)
{
_context.Entry(orderItem).State = EntityState.Modified;
await _context.SaveChangesAsync();
return Ok(orderItem);
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteOrderItem([FromRoute] int id)
{
var orderItem = await _context.OrderItem.SingleOrDefaultAsync(m => m.OrderItemId== id);
_context.OrderItem.Remove(orderItem);
await _context.SaveChangesAsync();
return Ok(orderItem);
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using H_PLUS_Sports.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace HPlusSportsAPI.Controllers
{
[Produces("application/json")]
[Route("api/Orders")]
public class OrdersController : Controller
{
private readonly H_Plus_SportsContext _context;
public OrdersController(H_Plus_SportsContext context)
{
_context = context;
}
[HttpGet]
public IActionResult GetOrder()
{
return new ObjectResult(_context.Order);
}
[HttpGet("{id}", Name = "GetOrder")]
public async Task<IActionResult> GetOrder([FromRoute] int id)
{
var order = await _context.Order.SingleOrDefaultAsync(m => m.OrderId == id);
return Ok(order);
}
[HttpPost]
public async Task<IActionResult> PostOrder([FromBody] Order order)
{
_context.Add(order);
await _context.SaveChangesAsync();
return CreatedAtAction("getOrder", new { id = order.OrderId }, order);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutOrder([FromRoute] int id, [FromBody] Order order)
{
_context.Entry(order).State = EntityState.Modified;
await _context.SaveChangesAsync();
return Ok(order);
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteOrder([FromRoute] int id)
{
var order = await _context.Order.SingleOrDefaultAsync(m => m.OrderId== id);
_context.Order.Remove(order);
await _context.SaveChangesAsync();
return Ok(order);
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using H_PLUS_Sports.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace HPlusSportsAPI.Controllers
{
[Produces("application/json")]
[Route("api/Products")]
public class ProductsController : Controller
{
private readonly H_Plus_SportsContext _context;
public ProductsController(H_Plus_SportsContext context)
{
_context = context;
}
[HttpGet]
public IActionResult GetProduct()
{
return new ObjectResult(_context.Product);
}
[HttpGet("{id}", Name = "GetProduct")]
public async Task<IActionResult> GetProduct([FromRoute] string id)
{
var product = await _context.Product.SingleOrDefaultAsync(m => m.ProductId == id);
return Ok(product);
}
[HttpPost]
public async Task<IActionResult> PostProduct([FromBody] Product product)
{
_context.Product.Add(product);
await _context.SaveChangesAsync();
return CreatedAtAction("getProduct", new { id = product.ProductId }, product);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutProduct([FromRoute] string id, [FromBody] Product product)
{
_context.Entry(product).State = EntityState.Modified;
await _context.SaveChangesAsync();
return Ok(product);
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteProduct([FromRoute] string id)
{
var product = await _context.Product.SingleOrDefaultAsync(m => m.ProductId == id);
_context.Product.Remove(product);
await _context.SaveChangesAsync();
return Ok(product);
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using H_PLUS_Sports.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace HPlusSportsAPI.Controllers
{
[Produces("application/json")]
[Route("api/Salespersons")]
public class SalespersonsController : Controller
{
private readonly H_Plus_SportsContext _context;
public SalespersonsController(H_Plus_SportsContext context)
{
_context = context;
}
[HttpGet]
public IActionResult GetSalesperson()
{
return new ObjectResult(_context.Salesperson);
}
[HttpGet("{id}", Name = "GetSalesPerson")]
public async Task<IActionResult> GetSalesperson([FromRoute] int id)
{
var salesPerson = await _context.Salesperson.SingleOrDefaultAsync(m => m.SalespersonId== id);
return Ok(salesPerson);
}
[HttpPost]
public async Task<IActionResult> PostSalesperson([FromBody] Salesperson salesPerson)
{
_context.Salesperson.Add(salesPerson);
await _context.SaveChangesAsync();
return CreatedAtAction("getSalesPerson", new { id = salesPerson.SalespersonId}, salesPerson);
}
[HttpPut("{id}")]
public async Task<IActionResult> PutSalesperson([FromRoute] int id, [FromBody] Salesperson salesPerson)
{
_context.Entry(salesPerson).State = EntityState.Modified;
await _context.SaveChangesAsync();
return Ok(salesPerson);
}
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteSalesperson([FromRoute] int id)
{
var salesPerson = await _context.Salesperson.SingleOrDefaultAsync(m => m.SalespersonId == id);
_context.Salesperson.Remove(salesPerson);
await _context.SaveChangesAsync();
return Ok(salesPerson);
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace H_PLUS_Sports.Models
{
public partial class Customer
{
public Customer()
{
Order = new HashSet<Order>();
}
public int CustomerId { get; set; }
[StringLength(50)]
public string FirstName { get; set; }
[StringLength(50)]
public string LastName { get; set; }
[EmailAddress]
public string Email { get; set; }
[Phone]
public string Phone { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zipcode { get; set; }
public virtual ICollection<Order> Order { get; set; }
}
}

View File

@ -0,0 +1,180 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace H_PLUS_Sports.Models
{
public partial class H_Plus_SportsContext : DbContext
{
public H_Plus_SportsContext()
{
}
public H_Plus_SportsContext(DbContextOptions<H_Plus_SportsContext> options)
: base(options)
{
}
public virtual DbSet<Customer> Customer { get; set; }
public virtual DbSet<Order> Order { get; set; }
public virtual DbSet<OrderItem> OrderItem { get; set; }
public virtual DbSet<Product> Product { get; set; }
public virtual DbSet<Salesperson> Salesperson { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>(entity =>
{
entity.Property(e => e.CustomerId).HasColumnName("CustomerID");
entity.Property(e => e.Address)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.City)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Email)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.FirstName)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.LastName)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Phone)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.State)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Zipcode)
.HasMaxLength(50)
.IsUnicode(false);
});
modelBuilder.Entity<Order>(entity =>
{
entity.Property(e => e.OrderId).HasColumnName("OrderID");
entity.Property(e => e.CustomerId).HasColumnName("CustomerID");
entity.Property(e => e.Date).HasColumnType("datetime");
entity.Property(e => e.SalespersonId).HasColumnName("SalespersonID");
entity.Property(e => e.Status)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.TotalDue).HasColumnType("money");
entity.HasOne(d => d.Customer)
.WithMany(p => p.Order)
.HasForeignKey(d => d.CustomerId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Order_Customer");
entity.HasOne(d => d.Salesperson)
.WithMany(p => p.Order)
.HasForeignKey(d => d.SalespersonId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_Order_Salesperson");
});
modelBuilder.Entity<OrderItem>(entity =>
{
entity.Property(e => e.OrderItemId).HasColumnName("OrderItemID");
entity.Property(e => e.OrderId).HasColumnName("OrderID");
entity.Property(e => e.ProductId)
.IsRequired()
.HasColumnName("ProductID")
.HasMaxLength(10);
entity.HasOne(d => d.Order)
.WithMany(p => p.OrderItem)
.HasForeignKey(d => d.OrderId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_OrderItem_Order");
entity.HasOne(d => d.Product)
.WithMany(p => p.OrderItem)
.HasForeignKey(d => d.ProductId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_OrderItem_Product1");
});
modelBuilder.Entity<Product>(entity =>
{
entity.Property(e => e.ProductId)
.HasColumnName("ProductID")
.HasMaxLength(10);
entity.Property(e => e.Price).HasColumnType("money");
entity.Property(e => e.ProductName)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Status)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Variety)
.HasMaxLength(50)
.IsUnicode(false);
});
modelBuilder.Entity<Salesperson>(entity =>
{
entity.Property(e => e.SalespersonId).HasColumnName("SalespersonID");
entity.Property(e => e.Address)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.City)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Email)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.FirstName)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.LastName)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Phone)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.State)
.HasMaxLength(50)
.IsUnicode(false);
entity.Property(e => e.Zipcode)
.HasMaxLength(50)
.IsUnicode(false);
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace H_PLUS_Sports.Models
{
public partial class Order
{
public Order()
{
OrderItem = new HashSet<OrderItem>();
}
public int OrderId { get; set; }
[Required]
[DataType(DataType.Date)]
public DateTime? Date { get; set; }
[Required]
public decimal? TotalDue { get; set; }
public string Status { get; set; }
public int CustomerId { get; set; }
public int SalespersonId { get; set; }
public virtual Customer Customer { get; set; }
public virtual Salesperson Salesperson { get; set; }
public virtual ICollection<OrderItem> OrderItem { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
namespace H_PLUS_Sports.Models
{
public partial class OrderItem
{
public int OrderItemId { get; set; }
public int OrderId { get; set; }
public string ProductId { get; set; }
public int? Quantity { get; set; }
public virtual Order Order { get; set; }
public virtual Product Product { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace H_PLUS_Sports.Models
{
public partial class Product
{
public Product()
{
OrderItem = new HashSet<OrderItem>();
}
public string ProductId { get; set; }
public string ProductName { get; set; }
public int? Size { get; set; }
public string Variety { get; set; }
public decimal? Price { get; set; }
public string Status { get; set; }
public virtual ICollection<OrderItem> OrderItem { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace H_PLUS_Sports.Models
{
public partial class Salesperson
{
public Salesperson()
{
Order = new HashSet<Order>();
}
public int SalespersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zipcode { get; set; }
public virtual ICollection<Order> Order { get; set; }
}
}

26
H_PLUS_Sports/Program.cs Normal file
View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace H_PLUS_Sports
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

View File

@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50683",
"sslPort": 44368
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"H_PLUS_Sports": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}

55
H_PLUS_Sports/Startup.cs Normal file
View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using H_PLUS_Sports.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace H_PLUS_Sports
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
var connection = "Server=tcp:hsportsoeman.database.windows.net,1433;Initial Catalog=H_Plus_Sports;Persist Security Info=False;User ID=saTfoman;Password=Jes@lin78;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
services.AddDbContext<H_Plus_SportsContext>(options => options.UseSqlServer(connection));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

View File

@ -0,0 +1,15 @@
using System;
namespace H_PLUS_Sports
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}