0% found this document useful (0 votes)
9 views19 pages

Home Controller Using Using Using Using Using Using Namespace Public Class

The document contains the implementation of the Home and Admin controllers for the RG Defence Academy application, which includes various actions for managing feedback, admissions, faculty, and contact lists. It handles user interactions such as logging in, submitting testimonials, and managing student and faculty information, along with error handling and response alerts. The document also includes a login form and a contact list view for displaying and managing user inquiries.

Uploaded by

SK Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views19 pages

Home Controller Using Using Using Using Using Using Namespace Public Class

The document contains the implementation of the Home and Admin controllers for the RG Defence Academy application, which includes various actions for managing feedback, admissions, faculty, and contact lists. It handles user interactions such as logging in, submitting testimonials, and managing student and faculty information, along with error handling and response alerts. The document also includes a login form and a contact list view for displaying and managing user inquiries.

Uploaded by

SK Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Home Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RGDefenceAcademy.Models;

namespace RGDefenceAcademy.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/

RGAcdemyDBEntities db = new RGAcdemyDBEntities();

public ActionResult Index()


{
List<Tbl_Feedback> TblFeeds = db.Tbl_Feedback.OrderByDescending(t =>
t.FeedId).Take(9).ToList();
return View(TblFeeds);
}
public ActionResult AboutUs()
{
return View();
}
public ActionResult Facility()
{
return View(db.Tbl_Faculity.ToList());
}
public ActionResult ContactUs()
{
return View();
}
[HttpPost]
public ActionResult ContactUs(Tbl_Contact con)
{
try
{
db.Tbl_Contact.Add(con);
db.SaveChanges();
Response.Write("<script>alert('Contact Save
SuccessFully')</script>");
}
catch (Exception)
{
Response.Write("<script>alert('Something Went Wrong')</script>");
}

return View();
}
public ActionResult AdmissionForm()
{
return View();
}
public ActionResult LogIn()
{
return View();
}
[HttpPost]
public ActionResult LogIn(string username, string pword)
{
if (username == "RGAdmin" && pword == "rg@123")
{
Session["username"] = username;
Response.Write("<script>alert('Welcome to Admin Zone
');window.location.href='/Admin/Index'</script>");
}
else
{
Response.Write("<script>alert('Invalid AdminId or
Password')</script>");
}
return View();
}

public ActionResult Testimonial()


{
List<Tbl_Feedback> TblFeeds = db.Tbl_Feedback.OrderByDescending(t =>
t.FeedId).Take(9).ToList();
return View(TblFeeds);
}
[HttpPost]
public ActionResult Testimonial(Tbl_Feedback model)
{
try
{
HttpPostedFileBase file = Request.Files["ProfilePic"];
if(file.FileName != "")
{
model.ProfilePic = file.FileName;
file.SaveAs(Server.MapPath("../Content/FeedPic/" +
file.FileName));
db.Tbl_Feedback.Add(model);
db.SaveChanges();
Response.Write("<script>alert('Your Feedback Submitted
Successfully');window.location.href='/Home/Testimonial'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your
profile')</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('something went wrong')</script>");
}
return View();
}
public ActionResult OurGallery()
{
List<Tbl_Gallery> TblGallery = db.Tbl_Gallery.OrderByDescending(t =>
t.GalleryId).Take(1000).ToList();
return View(TblGallery);
}
}
}

Admin Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RGDefenceAcademy.Models;

namespace RGDefenceAcademy.Controllers
{
public class AdminController : Controller
{
//
// GET: /Admin/

RGAcdemyDBEntities db = new RGAcdemyDBEntities();

public ActionResult Index()


{
if (Session["username"] != null)
{

}
else
{

Response.Write("<script>alert('Logout');window.location.href='/Home/LogIn'</script>");
}
return View();
}

public ActionResult ContactList()


{
//List<Tbl_Contact> lst = null;
//if (Session["aid"] != null)
//{
// lst = db.Tbl_Contact.ToList();
//}
//else
//{
//
Response.Write("<script>alert('Logout');window.location.href='/Home/Login'</script>");
//}
return View(db.Tbl_Contact.ToList());
}

public void DeleteContact(int ContactID)


{
try
{
Tbl_Contact model = db.Tbl_Contact.SingleOrDefault(a => a.ContactID == ContactID);
db.Tbl_Contact.Remove(model);
db.SaveChanges();
Response.Write("<script>alert('Student Information Deleted
Successfully');window.location.href='/Admin/ContactList'</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/ContactList'</script>");
}
}

public ActionResult StudentAdmission()


{
if (Session["username"] != null)
{

}
else
{

Response.Write("<script>alert('Logout');window.location.href='/Home/Login'</script>");
}
return View();
}
[HttpPost]
public ActionResult StudentAdmission(Tbl_Admission model, string submit)
{
try
{

HttpPostedFileBase file = Request.Files["StudentPic"];


if (file.FileName != "")
{
model.StudentPic = file.FileName;
file.SaveAs(Server.MapPath("../Content/studentimg/" + file.FileName));
model.Adddate = DateTime.Now;
db.Tbl_Admission.Add(model);
db.SaveChanges();
Response.Write("<script>alert('Student Admission Successfully
Completed');window.location.href='/Admin/StudentList'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your profile')</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('something went wrong')</script>");
}
return View();
}

public ActionResult UpdateStudentAdmission(int StudentId)


{

Tbl_Admission model = db.Tbl_Admission.SingleOrDefault(a => a.StudentId ==


StudentId);

return View(model);
}
[HttpPost]
public void UpdateStudentAdmission(Tbl_Admission model)
{

try
{
Tbl_Admission up = db.Tbl_Admission.SingleOrDefault(a => a.StudentId ==
model.StudentId);

HttpPostedFileBase file = Request.Files["StudentPic"];


if (file.FileName != "")
{
up.StudentPic = file.FileName;
file.SaveAs(Server.MapPath("../Content/studentimg/" + file.FileName));

up.StudentName = model.StudentName;
up.FatherName = model.FatherName;
up.MotherName = model.MotherName;
up.Class = model.Class;
up.DateOfBirth = model.DateOfBirth;
up.Gender = model.Gender;
up.MobileNo = model.MobileNo;
up.Address = model.Address;
db.SaveChanges();
Response.Write("<script>alert('Student Information Updated
Successfully');window.location.href='/Admin/StudentList'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your
profile');window.location.href='/Admin/UpdateStudentAdmission'</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/UpdateStudentAdmission'</script>");
}
}
public ActionResult StudentList()
{
return View(db.Tbl_Admission.ToList());
}

public void DeleteStudent(int StudentId)


{
try
{
Tbl_Admission model = db.Tbl_Admission.SingleOrDefault(a => a.StudentId ==
StudentId);
db.Tbl_Admission.Remove(model);
db.SaveChanges();
Response.Write("<script>alert('Student Information Deleted
Successfully');window.location.href='/Admin/StudentList'</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/StudentList'</script>");
}

public ActionResult Faculty()


{
return View();
}
[HttpPost]
public ActionResult Faculty(Tbl_Faculity model, string submit)
{
try
{
HttpPostedFileBase file = Request.Files["FaculityPic"];
if (file.FileName != "")
{
model.FaculityPic = file.FileName;
file.SaveAs(Server.MapPath("../Content/FacultyPic/" + file.FileName));
model.AddDate = DateTime.Now;
db.Tbl_Faculity.Add(model);
db.SaveChanges();
Response.Write("<script>alert('Student Admission Successfully
Completed');window.location.href='/Admin/facultyList'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your profile')</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('something went wrong')</script>");
}
return View();
}

public ActionResult facultyList()


{
return View(db.Tbl_Faculity.ToList());
}
public ActionResult UpdateFaculty(int FaculityId)
{

Tbl_Faculity model = db.Tbl_Faculity.SingleOrDefault(a => a.FaculityId == FaculityId);

return View(model);
}
[HttpPost]
public void UpdateFaculty(Tbl_Faculity model)
{

try
{
Tbl_Faculity up = db.Tbl_Faculity.SingleOrDefault(a => a.FaculityId ==
model.FaculityId);

HttpPostedFileBase file = Request.Files["FaculityPic"];


if (file.FileName != "")
{
up.FaculityPic = file.FileName;
file.SaveAs(Server.MapPath("../Content/FacultyPic/" + file.FileName));

up.FaculityName = model.FaculityName;
up.Degination = model.Degination;
up.Qualifaction = model.Qualifaction;
up.MobileNo = model.MobileNo;
up.Gender = model.Gender;
up.Address = model.Address;
db.SaveChanges();
Response.Write("<script>alert('Faculty Information Updated
Successfully');window.location.href='/Admin/facultyList'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your
profile');window.location.href='/Admin/UpdateStudentAdmission'</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('Some thing went
wrong');window.location.href='/Admin/UpdateStudentAdmission'</script>");
}
}

public void DeleteFaculty(int FaculityId)


{
try
{
Tbl_Faculity model = db.Tbl_Faculity.SingleOrDefault(a => a.FaculityId == FaculityId);
db.Tbl_Faculity.Remove(model);
db.SaveChanges();
Response.Write("<script>alert('Faculty Information Deleted
Successfully');window.location.href='/Admin/facultyList'</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/facultyList'</script>");
}
}

public ActionResult TestimonialList()


{
return View(db.Tbl_Feedback.ToList());
}

public void DeleteTestimonial(int FeedId)


{
try
{
Tbl_Feedback model = db.Tbl_Feedback.SingleOrDefault(a => a.FeedId == FeedId);
db.Tbl_Feedback.Remove(model);
db.SaveChanges();
Response.Write("<script>alert('Faculty Information Deleted
Successfully');window.location.href='/Admin/TestimonialList'</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/TestimonialList'</script>");
}
}
public ActionResult Gallery()
{
return View();
}
[HttpPost]
public ActionResult Gallery(Tbl_Gallery model)
{
try
{
HttpPostedFileBase file = Request.Files["PicName"];
if (file.FileName != "")
{
model.PicName = file.FileName;
file.SaveAs(Server.MapPath("../Content/Gallery/" + file.FileName));
db.Tbl_Gallery.Add(model);
db.SaveChanges();
Response.Write("<script>alert('Image Added
Successfully');window.location.href='/Admin/GalleryList'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your profile')</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/GalleryList'</script>");
}
return View();
}

public ActionResult GalleryList()


{
return View(db.Tbl_Gallery.ToList());
}

public ActionResult UpdateGallery(int GalleryId)


{
Tbl_Gallery model = db.Tbl_Gallery.SingleOrDefault(a => a.GalleryId == GalleryId);

return View(model);
}
[HttpPost]
public ActionResult UpdateGallery(Tbl_Gallery model,int GalleryId)
{
try
{
Tbl_Gallery up = db.Tbl_Gallery.SingleOrDefault(a => a.GalleryId == model.GalleryId);

HttpPostedFileBase file = Request.Files["PicName"];


if (file.FileName != "")
{
up.PicName = file.FileName;
file.SaveAs(Server.MapPath("../Content/FacultyPic/" + file.FileName));
db.SaveChanges();
Response.Write("<script>alert('Gallery Updated
Successfully');window.location.href='/Admin/GalleryList'</script>");
}
else
{
Response.Write("<script>alert('Kindly upload your
profile');window.location.href='/Admin/UpdateGallery'</script>");
}
}
catch (Exception ex)
{
Response.Write("<script>alert('Some thing went
wrong');window.location.href='/Admin/UpdateGallery'</script>");
}
return View(model);
}
public void DeleteGallery(int GalleryId)
{
try
{
Tbl_Gallery model = db.Tbl_Gallery.SingleOrDefault(a => a.GalleryId == GalleryId);
db.Tbl_Gallery.Remove(model);
db.SaveChanges();
Response.Write("<script>alert('Image Deleted
Successfully');window.location.href='/Admin/GalleryList'</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('some thing went
wrong');window.location.href='/Admin/GalleryList'</script>");
}
}
public void LogOut()
{
Session.Abandon();
Response.Write("<script>alert('LogOut');window.location.href='/Home/LogIn'</script>");
}
}
}

Login Page Home


<form action="/Home/LogIn" method="post">
<div class="row g-3">
<div class="col-12">
<div class="form-floating">
<input type="text" class="form-control" name="username"
placeholder="Subject">
<label for="subject">Mobile Number</label>
</div>
</div>
<div class="col-12">
<div class="form-floating">
<input type="password" class="form-control" name="pword"
placeholder="Password">
<label for="message">Password</label>
</div>
</div>
<div class="col-12">
<button class="btn btn-primary w-100 py-3" type="submit">LogIn</button>
</div>
</div>
</form>

===Contact List=====
@{
ViewBag.Title = "ContactList";
Layout = "~/Views/Shared/AdminMaster.cshtml";
}
@model List<RGDefenceAcademy.Models.Tbl_Contact>

<link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap4.min.css"
rel="stylesheet" />
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script
src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script
src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap4.min.js"></script>

<div class="col-lg-12 grid-margin stretch-card">


<div class="card">
<div class="card-body">
<h4 class="card-title">Contact List</h4>
<div class="table-responsive">
<table class="table table-striped" id="example">
<thead class=" thead-dark">
<tr>
<th>SrNo</th>
<th>Name</th>
<th>Email</th>
<th>Mobile No</th>
<th>Subject</th>
<th>Message</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@{
int j = 0;
foreach (var i in Model)
{
<tr>
<th>@(j + 1)</th>
<th>@i.Name</th>
<td>@i.Email</td>
<td>@i.MobNo</td>
<td>@i.Subject</td>
<td>@i.Msg</td>
<td>
<span>
<a class="btn btn-danger btn-sm"
href="/Admin/[email protected]"> Delete </a>
</span>
</td>
</tr>
j++;
}
}
</tbody>
</table>
</div>
</div>
</div>
</div>

<script>
$(document).ready(function () {
new DataTable('#example');
//save record

})
</script>

You might also like