Skip to content

Commit 4458d01

Browse files
web api and others
1 parent 6525e04 commit 4458d01

19 files changed

+1289
-18
lines changed

.idea/config/applicationhost.config

+983
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BBM486Project.sln

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entiti
88
EndProject
99
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsFormsApp", "WindowsFormsApp\WindowsFormsApp.csproj", "{DD280ADE-41A1-4D7E-B480-BAC5B6AACD5C}"
1010
EndProject
11-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{32745145-4C4A-4830-B73B-8ADAC7508C6D}"
12-
EndProject
1311
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleUI", "ConsoleUI\ConsoleUI.csproj", "{CE460B84-0A52-4A1D-84DA-9C9D0998ACBE}"
1412
EndProject
1513
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{D31CD254-F103-4F2F-8852-6C087D2B4B42}"
1614
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{4775CBA8-1542-4750-93D5-8E4607D6607A}"
16+
EndProject
1717
Global
1818
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1919
Debug|Any CPU = Debug|Any CPU
@@ -36,10 +36,6 @@ Global
3636
{DD280ADE-41A1-4D7E-B480-BAC5B6AACD5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
3737
{DD280ADE-41A1-4D7E-B480-BAC5B6AACD5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
3838
{DD280ADE-41A1-4D7E-B480-BAC5B6AACD5C}.Release|Any CPU.Build.0 = Release|Any CPU
39-
{32745145-4C4A-4830-B73B-8ADAC7508C6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40-
{32745145-4C4A-4830-B73B-8ADAC7508C6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
41-
{32745145-4C4A-4830-B73B-8ADAC7508C6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
42-
{32745145-4C4A-4830-B73B-8ADAC7508C6D}.Release|Any CPU.Build.0 = Release|Any CPU
4339
{CE460B84-0A52-4A1D-84DA-9C9D0998ACBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4440
{CE460B84-0A52-4A1D-84DA-9C9D0998ACBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
4541
{CE460B84-0A52-4A1D-84DA-9C9D0998ACBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -48,5 +44,9 @@ Global
4844
{D31CD254-F103-4F2F-8852-6C087D2B4B42}.Debug|Any CPU.Build.0 = Debug|Any CPU
4945
{D31CD254-F103-4F2F-8852-6C087D2B4B42}.Release|Any CPU.ActiveCfg = Release|Any CPU
5046
{D31CD254-F103-4F2F-8852-6C087D2B4B42}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{4775CBA8-1542-4750-93D5-8E4607D6607A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48+
{4775CBA8-1542-4750-93D5-8E4607D6607A}.Debug|Any CPU.Build.0 = Debug|Any CPU
49+
{4775CBA8-1542-4750-93D5-8E4607D6607A}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{4775CBA8-1542-4750-93D5-8E4607D6607A}.Release|Any CPU.Build.0 = Release|Any CPU
5151
EndGlobalSection
5252
EndGlobal

DataAccess/Abstract/IInternDal.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System.Collections.Generic;
22
using Core.DataAccess;
33
using Entities.Concrete;
4+
using Entities.DTOs;
45

56
namespace DataAccess.Abstract
67
{
78
public interface IInternDal: IEntityRepository<Intern>
89
{
9-
10+
List<InternDetailDto> GetInternDetails();
1011
}
1112
}

DataAccess/Concrete/EntityFramework/EfInternDal.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,31 @@
55
using Core.DataAccess.EntityFramework;
66
using DataAccess.Abstract;
77
using Entities.Concrete;
8+
using Entities.DTOs;
89
using Microsoft.EntityFrameworkCore;
910

1011
namespace DataAccess.Concrete.EntityFramework
1112
{
1213
public class EfInternDal: EfEntityRepositoryBase<Intern,EmployeeContext>,IInternDal
1314
{
14-
15+
public List<InternDetailDto> GetInternDetails()
16+
{
17+
using (EmployeeContext context = new EmployeeContext())
18+
{
19+
var result = from i in context.Interns
20+
join s in context.SoftwareDevelopers
21+
on i.MentorId equals s.Id
22+
select new InternDetailDto
23+
{
24+
Id = i.Id,
25+
MentorId = s.Id,
26+
FirstName = i.FirstName,
27+
LastName = i.LastName,
28+
MentorName = s.FirstName + " " + s.LastName,
29+
Wage = i.Wage
30+
};
31+
return result.ToList();
32+
}
33+
}
1534
}
1635
}

DataAccess/Concrete/InMemory/InMemoryInternDal.cs

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq.Expressions;
55
using DataAccess.Abstract;
66
using Entities.Concrete;
7+
using Entities.DTOs;
78

89
namespace DataAccess.Concrete.InMemory
910
{
@@ -74,6 +75,11 @@ public void Delete(Intern intern)
7475
internToUpdate.WorkSituation = intern.WorkSituation;
7576
}
7677

78+
public List<InternDetailDto> GetInternDetails()
79+
{
80+
throw new NotImplementedException();
81+
}
82+
7783
public List<Intern> GetAllByMentor(int mentorId)
7884
{
7985
return _interns.Where(i => i.MentorId == mentorId).ToList();

Entities/DTOs/InternDetailDto.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace Entities.DTOs
4+
{
5+
public class InternDetailDto:IDto
6+
{
7+
public int Id { get; set; }
8+
public int MentorId { get; set; }
9+
public string FirstName { get; set; }
10+
public string LastName { get; set; }
11+
public string MentorName { get; set; }
12+
// public string Address { get; set; }
13+
// public long Phone { get; set; }
14+
// public string EmailAddress { get; set; }
15+
// public DateTime StartDate { get; set; }
16+
// public DateTime EndDate { get; set; }
17+
// public string WorkSituation { get; set; }
18+
public decimal Wage { get; set; }
19+
}
20+
}

Entities/IDto.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Entities
2+
{
3+
public interface IDto
4+
{
5+
6+
}
7+
}

Service/Abstract/IInternService.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
using System.Collections.Generic;
22
using Entities.Concrete;
3+
using Entities.DTOs;
34

45
namespace Service.Abstract
56
{
67
public interface IInternService
78
{
89
List<Intern> GetAll();
10+
List<InternDetailDto> GetInternDetails();
11+
void Add(Intern intern);
12+
void Update(Intern intern);
13+
void Delete(Intern intern);
14+
Intern GetById(int internId);
915
}
1016
}

Service/Concrete/InternManager.cs

+26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using DataAccess.Abstract;
33
using DataAccess.Concrete.InMemory;
44
using Entities.Concrete;
5+
using Entities.DTOs;
56
using Service.Abstract;
67

78
namespace Service.Concrete
@@ -19,5 +20,30 @@ public List<Intern> GetAll()
1920
{
2021
return _internDal.GetAll();
2122
}
23+
24+
public List<InternDetailDto> GetInternDetails()
25+
{
26+
return _internDal.GetInternDetails();
27+
}
28+
29+
public void Add(Intern intern)
30+
{
31+
throw new System.NotImplementedException();
32+
}
33+
34+
public void Update(Intern intern)
35+
{
36+
throw new System.NotImplementedException();
37+
}
38+
39+
public void Delete(Intern intern)
40+
{
41+
throw new System.NotImplementedException();
42+
}
43+
44+
public Intern GetById(int internId)
45+
{
46+
throw new System.NotImplementedException();
47+
}
2248
}
2349
}

WebAPI/Class1.cs

-8
This file was deleted.
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using DataAccess.Concrete.EntityFramework;
3+
using Entities.Concrete;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Service.Abstract;
6+
using Service.Concrete;
7+
8+
namespace WebAPI.Controllers
9+
{
10+
[Route("api/[controller]")]
11+
[ApiController]
12+
public class InternsController : ControllerBase
13+
{
14+
// GET
15+
[HttpGet]
16+
public List<Intern> Get()
17+
{
18+
IInternService internService = new InternManager(new EfInternDal());
19+
return internService.GetAll();
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace WebAPI.Controllers
9+
{
10+
[ApiController]
11+
[Route("[controller]")]
12+
public class WeatherForecastController : ControllerBase
13+
{
14+
private static readonly string[] Summaries = new[]
15+
{
16+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17+
};
18+
19+
private readonly ILogger<WeatherForecastController> _logger;
20+
21+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
22+
{
23+
_logger = logger;
24+
}
25+
26+
[HttpGet]
27+
public IEnumerable<WeatherForecast> Get()
28+
{
29+
var rng = new Random();
30+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
31+
{
32+
Date = DateTime.Now.AddDays(index),
33+
TemperatureC = rng.Next(-20, 55),
34+
Summary = Summaries[rng.Next(Summaries.Length)]
35+
})
36+
.ToArray();
37+
}
38+
}
39+
}

WebAPI/Program.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace WebAPI
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
22+
}
23+
}

WebAPI/Properties/launchSettings.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:45775",
8+
"sslPort": 44368
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "swagger",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"WebAPI": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": "true",
23+
"launchBrowser": true,
24+
"launchUrl": "swagger",
25+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

WebAPI/Startup.cs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.HttpsPolicy;
8+
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
using Microsoft.Extensions.Logging;
13+
using Microsoft.OpenApi.Models;
14+
15+
namespace WebAPI
16+
{
17+
public class Startup
18+
{
19+
public Startup(IConfiguration configuration)
20+
{
21+
Configuration = configuration;
22+
}
23+
24+
public IConfiguration Configuration { get; }
25+
26+
// This method gets called by the runtime. Use this method to add services to the container.
27+
public void ConfigureServices(IServiceCollection services)
28+
{
29+
services.AddControllers();
30+
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo {Title = "WebAPI", Version = "v1"}); });
31+
}
32+
33+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
34+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
35+
{
36+
if (env.IsDevelopment())
37+
{
38+
app.UseDeveloperExceptionPage();
39+
app.UseSwagger();
40+
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAPI v1"));
41+
}
42+
43+
app.UseHttpsRedirection();
44+
45+
app.UseRouting();
46+
47+
app.UseAuthorization();
48+
49+
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
50+
}
51+
}
52+
}

WebAPI/WeatherForecast.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace WebAPI
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int) (TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}

0 commit comments

Comments
 (0)