|
using System;
using System.Linq;
using System.Web.Mvc;
using CodeFirstEntities;
using CodeFirstServices.Interfaces;
namespace CodeFirstPortal.Controllers
{
public class StudentController : Controller
{
private readonly IStudentService _studentService;
public StudentController(IStudentService studentService)
{
this._studentService = studentService;
}
[HttpGet]
public ActionResult Details(int? id)
{
var studentDetails = _studentService.GetStudentById((int) id);
if (studentDetails == null) throw new ArgumentNullException("Not Found");
return View(studentDetails);
}
[HttpGet]
public ActionResult Delete(int? id)
{
var studentDetails = _studentService.GetStudentById((int) id);
if (studentDetails == null) throw new ArgumentNullException("Not Found");
return View(studentDetails);
}
[HttpPost]
public ActionResult Delete(Student student)
{
_studentService.DeleteStudent(student.StudentId);
return RedirectToAction("List", "Student");
}
[HttpGet]
public ActionResult Edit(int? id)
{
var studentDetails = _studentService.GetStudentById((int) id);
if (studentDetails == null) throw new ArgumentNullException("Not Found");
return View(studentDetails);
}
[HttpPost]
public ActionResult Edit(Student student)
{
_studentService.UpdateStudent(student);
return RedirectToAction("List", "Student");
}
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Student student)
{
var studentModel = new Student()
{
Address = student.Address,
Country = student.Country,
Name = student.Name,
Age = student.Age,
Email = student.Email
};
_studentService.CreateStudent(studentModel);
return RedirectToAction("List", "Student");
}
[HttpGet]
public ActionResult List()
{
var students = _studentService.GetStudents();
if (students.Any())
{
return View("List", students);
}
return View("List");
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Akhil Mittal is two times Microsoft MVP (Most Valuable Professional) firstly awarded in 2016 and continued in 2017 in Visual Studio and Technologies category, C# Corner MVP since 2013, Code Project MVP since 2014, a blogger, author and likes to write/read technical articles, blogs, and books. Akhil is a technical architect and loves to work on complex business problems and cutting-edge technologies. He has an experience of around 15 years in developing, designing, and architecting enterprises level applications primarily in Microsoft Technologies. He has diverse experience in working on cutting-edge technologies that include Microsoft Stack, AI, Machine Learning, and Cloud computing. Akhil is an MCP (Microsoft Certified Professional) in Web Applications and Dot Net Framework.
Visit Akhil Mittal’s personal blog CodeTeddy (
CodeTeddy ) for some good and informative articles. Following are some tech certifications that Akhil cleared,
• AZ-304: Microsoft Azure Architect Design.
• AZ-303: Microsoft Azure Architect Technologies.
• AZ-900: Microsoft Azure Fundamentals.
• Microsoft MCTS (70-528) Certified Programmer.
• Microsoft MCTS (70-536) Certified Programmer.
• Microsoft MCTS (70-515) Certified Programmer.
LinkedIn:
https://www.linkedin.com/in/akhilmittal/