Skip to content

Commit fecd64e

Browse files
committed
first commit
first commit
1 parent 8fe9eed commit fecd64e

117 files changed

Lines changed: 21295 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
119 KB
Binary file not shown.

WebAPI/.vs/WebAPI/config/applicationhost.config

Lines changed: 997 additions & 0 deletions
Large diffs are not rendered by default.

WebAPI/.vs/WebAPI/v16/.suo

45 KB
Binary file not shown.

WebAPI/WebAPI.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPI", "WebAPI\WebAPI.csproj", "{DF7E65DF-81E8-4FDA-8B97-A21A55D3F99A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{DF7E65DF-81E8-4FDA-8B97-A21A55D3F99A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DF7E65DF-81E8-4FDA-8B97-A21A55D3F99A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DF7E65DF-81E8-4FDA-8B97-A21A55D3F99A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DF7E65DF-81E8-4FDA-8B97-A21A55D3F99A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {109D694C-DB8A-4CDE-8906-F007044E3DED}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Configuration;
8+
using System.Data.SqlClient;
9+
using System.Data;
10+
using WebAPI.Models;
11+
12+
namespace WebAPI.Controllers
13+
{
14+
[Route("api/[controller]")]
15+
[ApiController]
16+
public class DepartmentController : ControllerBase
17+
{
18+
private readonly IConfiguration _configuration;
19+
20+
public DepartmentController(IConfiguration configuration)
21+
{
22+
_configuration = configuration;
23+
}
24+
25+
[HttpGet]
26+
public JsonResult Get()
27+
{
28+
string query = @"
29+
select DepartmentId, DepartmentName from dbo.Department";
30+
DataTable table = new DataTable();
31+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
32+
SqlDataReader myReader;
33+
using(SqlConnection myCon=new SqlConnection(sqlDataSource))
34+
{
35+
myCon.Open();
36+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
37+
{
38+
myReader = myCommand.ExecuteReader();
39+
table.Load(myReader); ;
40+
41+
myReader.Close();
42+
myCon.Close();
43+
}
44+
}
45+
46+
return new JsonResult(table);
47+
}
48+
49+
50+
[HttpPost]
51+
public JsonResult Post(Department dep)
52+
{
53+
string query = @"
54+
insert into dbo.Department values
55+
('"+dep.DepartmentName+@"')
56+
";
57+
DataTable table = new DataTable();
58+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
59+
SqlDataReader myReader;
60+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
61+
{
62+
myCon.Open();
63+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
64+
{
65+
myReader = myCommand.ExecuteReader();
66+
table.Load(myReader); ;
67+
68+
myReader.Close();
69+
myCon.Close();
70+
}
71+
}
72+
73+
return new JsonResult("Added Successfully");
74+
}
75+
76+
77+
[HttpPut]
78+
public JsonResult Put(Department dep)
79+
{
80+
string query = @"
81+
update dbo.Department set
82+
DepartmentName = '"+dep.DepartmentName+@"'
83+
where DepartmentId = "+dep.DepartmentId + @"
84+
";
85+
DataTable table = new DataTable();
86+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
87+
SqlDataReader myReader;
88+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
89+
{
90+
myCon.Open();
91+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
92+
{
93+
myReader = myCommand.ExecuteReader();
94+
table.Load(myReader); ;
95+
96+
myReader.Close();
97+
myCon.Close();
98+
}
99+
}
100+
101+
return new JsonResult("Updated Successfully");
102+
}
103+
104+
105+
[HttpDelete("{id}")]
106+
public JsonResult Delete(int id)
107+
{
108+
string query = @"
109+
delete from dbo.Department
110+
where DepartmentId = " + id + @"
111+
";
112+
DataTable table = new DataTable();
113+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
114+
SqlDataReader myReader;
115+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
116+
{
117+
myCon.Open();
118+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
119+
{
120+
myReader = myCommand.ExecuteReader();
121+
table.Load(myReader); ;
122+
123+
myReader.Close();
124+
myCon.Close();
125+
}
126+
}
127+
128+
return new JsonResult("Deleted Successfully");
129+
}
130+
}
131+
}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Configuration;
8+
using System.Data.SqlClient;
9+
using System.Data;
10+
using WebAPI.Models;
11+
using System.IO;
12+
using Microsoft.AspNetCore.Hosting;
13+
14+
namespace WebAPI.Controllers
15+
{
16+
[Route("api/[controller]")]
17+
[ApiController]
18+
public class EmployeeController : ControllerBase
19+
{
20+
private readonly IConfiguration _configuration;
21+
private readonly IWebHostEnvironment _env;
22+
23+
public EmployeeController(IConfiguration configuration, IWebHostEnvironment env)
24+
{
25+
_configuration = configuration;
26+
_env = env;
27+
}
28+
29+
[HttpGet]
30+
public JsonResult Get()
31+
{
32+
string query = @"
33+
select EmployeeId, EmployeeName, Department,
34+
convert(varchar(10),DateOfJoining,120) as DateOfJoining
35+
,PhotoFileName
36+
from dbo.Employee
37+
";
38+
DataTable table = new DataTable();
39+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
40+
SqlDataReader myReader;
41+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
42+
{
43+
myCon.Open();
44+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
45+
{
46+
myReader = myCommand.ExecuteReader();
47+
table.Load(myReader); ;
48+
49+
myReader.Close();
50+
myCon.Close();
51+
}
52+
}
53+
54+
return new JsonResult(table);
55+
}
56+
57+
58+
[HttpPost]
59+
public JsonResult Post(Employee emp)
60+
{
61+
string query = @"
62+
insert into dbo.Employee
63+
(EmployeeName,Department,DateOfJoining,PhotoFileName)
64+
values
65+
(
66+
'" + emp.EmployeeName + @"'
67+
,'" + emp.Department + @"'
68+
,'" + emp.DateOfJoining + @"'
69+
,'" + emp.PhotoFileName + @"'
70+
)
71+
";
72+
DataTable table = new DataTable();
73+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
74+
SqlDataReader myReader;
75+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
76+
{
77+
myCon.Open();
78+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
79+
{
80+
myReader = myCommand.ExecuteReader();
81+
table.Load(myReader); ;
82+
83+
myReader.Close();
84+
myCon.Close();
85+
}
86+
}
87+
88+
return new JsonResult("Added Successfully");
89+
}
90+
91+
92+
[HttpPut]
93+
public JsonResult Put(Employee emp)
94+
{
95+
string query = @"
96+
update dbo.Employee set
97+
EmployeeName = '" + emp.EmployeeName + @"'
98+
,Department = '" + emp.Department + @"'
99+
,DateOfJoining = '" + emp.DateOfJoining + @"'
100+
where EmployeeId = " + emp.EmployeeId + @"
101+
";
102+
DataTable table = new DataTable();
103+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
104+
SqlDataReader myReader;
105+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
106+
{
107+
myCon.Open();
108+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
109+
{
110+
myReader = myCommand.ExecuteReader();
111+
table.Load(myReader); ;
112+
113+
myReader.Close();
114+
myCon.Close();
115+
}
116+
}
117+
118+
return new JsonResult("Updated Successfully");
119+
}
120+
121+
122+
[HttpDelete("{id}")]
123+
public JsonResult Delete(int id)
124+
{
125+
string query = @"
126+
delete from dbo.Employee
127+
where EmployeeId = " + id + @"
128+
";
129+
DataTable table = new DataTable();
130+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
131+
SqlDataReader myReader;
132+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
133+
{
134+
myCon.Open();
135+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
136+
{
137+
myReader = myCommand.ExecuteReader();
138+
table.Load(myReader); ;
139+
140+
myReader.Close();
141+
myCon.Close();
142+
}
143+
}
144+
145+
return new JsonResult("Deleted Successfully");
146+
}
147+
148+
149+
[Route("SaveFile")]
150+
[HttpPost]
151+
public JsonResult SaveFile()
152+
{
153+
try
154+
{
155+
var httpRequest = Request.Form;
156+
var postedFile = httpRequest.Files[0];
157+
string filename = postedFile.FileName;
158+
var physicalPath = _env.ContentRootPath + "/Photos/" + filename;
159+
160+
using(var stream = new FileStream(physicalPath, FileMode.Create))
161+
{
162+
postedFile.CopyTo(stream);
163+
}
164+
165+
return new JsonResult(filename);
166+
}
167+
catch (Exception)
168+
{
169+
170+
return new JsonResult("anonymous.png");
171+
}
172+
}
173+
174+
175+
[Route("GetAllDepartmentNames")]
176+
public JsonResult GetAllDepartmentNames()
177+
{
178+
string query = @"
179+
select DepartmentName from dbo.Department
180+
";
181+
DataTable table = new DataTable();
182+
string sqlDataSource = _configuration.GetConnectionString("EmployeeAppCon");
183+
SqlDataReader myReader;
184+
using (SqlConnection myCon = new SqlConnection(sqlDataSource))
185+
{
186+
myCon.Open();
187+
using (SqlCommand myCommand = new SqlCommand(query, myCon))
188+
{
189+
myReader = myCommand.ExecuteReader();
190+
table.Load(myReader); ;
191+
192+
myReader.Close();
193+
myCon.Close();
194+
}
195+
}
196+
197+
return new JsonResult(table);
198+
}
199+
200+
201+
}
202+
}

0 commit comments

Comments
 (0)