-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployeeController .cs
112 lines (100 loc) · 2.81 KB
/
EmployeeController .cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Authentication.Models;
namespace Authentication.Controllers
{
public class EmployeeController : Controller
{
EmployeeDAL employeeDAL = new EmployeeDAL();
public IActionResult Index()
{
List<Employee> empList = new List<Employee>();
empList = employeeDAL.GetAllEmployee().ToList();
return View(empList);
}
//For my review [http]
public IActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create([Bind] Employee objEmp)
{
if (ModelState.IsValid)
{
employeeDAL.AddEmployee(objEmp);
return RedirectToAction("Index");
}
return View(objEmp);
}
[HttpGet]
[ValidateAntiForgeryToken]
public IActionResult Edit(int? id)
{
if (id == null)
{
return NotFound();
}
Employee emp = employeeDAL.GetEmployeeById(id);
if (emp == null)
{
return NotFound();
}
return View(emp);
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(int? id, [Bind] Employee objEmp)
{
if (id == null)
{
return NotFound();
}
if (ModelState.IsValid)
{
employeeDAL.UpdateEmployee(objEmp);
return RedirectToAction("Index");
}
return View(employeeDAL);
}
[HttpGet]
public IActionResult Details(int? id)
{
if (id == null)
{
return NotFound();
}
Employee emp = employeeDAL.GetEmployeeById(id);
if (emp == null)
{
return NotFound();
}
return View(emp);
}
public IActionResult Delete(int? id)
{
if (id == null)
{
return NotFound();
}
Employee emp = employeeDAL.GetEmployeeById(id);
if (emp == null)
{
return NotFound();
}
return View(emp);
}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public IActionResult DeleteEmp(int? id)
{
employeeDAL.DeleteEmployee(id);
return RedirectToAction("Index");
}
}
}