diff --git a/Business/Concrete/ProductManager.cs b/Business/Concrete/ProductManager.cs index 4eb858b..18167fd 100644 --- a/Business/Concrete/ProductManager.cs +++ b/Business/Concrete/ProductManager.cs @@ -36,7 +36,7 @@ public IResult Add(Product product) public IDataResult> GetAll() { - if (DateTime.Now.Hour==22) + if (DateTime.Now.Hour == 1) { return new ErrorDataResult>(Messages.MaintenanceTime); } diff --git a/MyFinalProject.sln b/MyFinalProject.sln index 32e2172..b871e72 100644 --- a/MyFinalProject.sln +++ b/MyFinalProject.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entiti EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{591DFF85-F9C2-47E3-BE46-0C068A763280}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{B2669097-0693-4207-A802-C71D1B2639ED}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{B2669097-0693-4207-A802-C71D1B2639ED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{C3B968CB-0251-4F7C-9D4F-C6BC25440E9E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {B2669097-0693-4207-A802-C71D1B2639ED}.Debug|Any CPU.Build.0 = Debug|Any CPU {B2669097-0693-4207-A802-C71D1B2639ED}.Release|Any CPU.ActiveCfg = Release|Any CPU {B2669097-0693-4207-A802-C71D1B2639ED}.Release|Any CPU.Build.0 = Release|Any CPU + {C3B968CB-0251-4F7C-9D4F-C6BC25440E9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C3B968CB-0251-4F7C-9D4F-C6BC25440E9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C3B968CB-0251-4F7C-9D4F-C6BC25440E9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C3B968CB-0251-4F7C-9D4F-C6BC25440E9E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WebAPI/Controllers/ProductsController.cs b/WebAPI/Controllers/ProductsController.cs new file mode 100644 index 0000000..bbc2a34 --- /dev/null +++ b/WebAPI/Controllers/ProductsController.cs @@ -0,0 +1,65 @@ +using Business.Abstract; +using Business.Concrete; +using DataAccess.Concrete.EntityFramework; +using Entities.Concrete; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ProductsController : ControllerBase + { + //Loosely coupled + //nameing convention + //IoC Container -- Inversion of Controller + + IProductService _productService; + + public ProductsController(IProductService productService) + { + _productService = productService; + } + + [HttpGet("getall")] + public IActionResult GetAll() + { + //Dependency chain + //IProductService productService = new ProductManager(new EfProductDal()); + + var result = _productService.GetAll(); + if (result.Success) + { + return Ok(result.Data); + } + return BadRequest(result.Message); + } + + [HttpGet("getbyid")] + public IActionResult GetById(int id) + { + var result = _productService.GetById(id); + if (result.Success) + { + return Ok(result); + } + return BadRequest(result); + } + [HttpPost("add")] + public IActionResult Add(Product product) + { + var result = _productService.Add(product); + if (result.Success) + { + return Ok(result); + } + return BadRequest(result); + } + + } +} diff --git a/WebAPI/Controllers/WeatherForecastController.cs b/WebAPI/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..da06093 --- /dev/null +++ b/WebAPI/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/WebAPI/Program.cs b/WebAPI/Program.cs new file mode 100644 index 0000000..ae04053 --- /dev/null +++ b/WebAPI/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI +{ + 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(); + }); + } +} diff --git a/WebAPI/Properties/launchSettings.json b/WebAPI/Properties/launchSettings.json new file mode 100644 index 0000000..262d24b --- /dev/null +++ b/WebAPI/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52594", + "sslPort": 44391 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WebAPI": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WebAPI/Startup.cs b/WebAPI/Startup.cs new file mode 100644 index 0000000..71d493f --- /dev/null +++ b/WebAPI/Startup.cs @@ -0,0 +1,58 @@ +using Business.Abstract; +using Business.Concrete; +using DataAccess.Abstract; +using DataAccess.Concrete.EntityFramework; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WebAPI +{ + 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) + { + //Autofac,Ninject,CastleWindsor + services.AddControllers(); + services.AddSingleton();//bana arka plnada referans oluþtur + services.AddSingleton(); + } + + // 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(); + }); + } + } +} diff --git a/WebAPI/WeatherForecast.cs b/WebAPI/WeatherForecast.cs new file mode 100644 index 0000000..c6c5567 --- /dev/null +++ b/WebAPI/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace WebAPI +{ + 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; } + } +} diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj new file mode 100644 index 0000000..165acc1 --- /dev/null +++ b/WebAPI/WebAPI.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + + + + + + + + + + diff --git a/WebAPI/appsettings.Development.json b/WebAPI/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/WebAPI/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/WebAPI/appsettings.json b/WebAPI/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/WebAPI/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}