You are on page 1of 16

សាខាសាកលវិទ្យាល័យ បៀលប្រាយ

BUILD BRIGHT UNIVERSITY

ខេត្តសៀមរាប

មហាវិទ្យាល័យវិទ្យាសាស្រ្តនិងបច្ចេកវិទ្យា

ជំនាន់ទី១៨ ឆ្នា ំ៣ ឆមាសទី២

កិច្ចការស្រាវជ្រាវបុគ្គល ់

មុខវិជ្ជា ៖ ប្រព័ន្ធប្រតិបត្តិការកុំព្យទ័
ូ រ

ASP.NET
ប្រធានបទ ៖

Employee Project

រៀបរៀងដោយ ៖

១. និស្សត
ិ ជឿន ឡេងយូ

ណែនា ំដោយ ៖
សាស្ត្រា ចារ្យ ម៉ុន មិញ

ឆ្នា ំសិក្សា ២០២១-២០២២


Result
Code

1. Startup.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using IBJOffice.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;

namespace IBJOffice
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the
container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddDbContext<IBJOfficeDbContext>(opt =>
{
opt.UseSqlServer(@"Server = (localDb)\
MSSQLlocalDb;database=Employee;Trusted_Connection=true;");
});
//services.AddIdentity<IdentityUser, IdentityRole>()
// .AddEntityFrameworkStores<StaffContextt>();

//services.AddDbContext<IBJOfficeDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
//services.AddControllersWithViews().AddRazorRuntimeCompilation();
}

// This method gets called by the runtime. Use this method to configure the HTTP
request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for
production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});

// Render only .js and css files in "Views" folder.


app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new
PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Views")),
RequestPath = new PathString("/Views"),
ContentTypeProvider = new FileExtensionContentTypeProvider(
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{".js", "application.javascript" },
{".css", "text/css" }
})
});

}
}
}

2.Layout.cshtml

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - STAFF MANAGEMENT </title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
<link href="~/fonts/font-awesome/4.7/css/font-awesome.min.css" rel="stylesheet" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white
border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-
action="Index"> Home</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-
action="Index">Department</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Employee"
asp-action="Index">Employees</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">


<div class="container">
&copy; 2022 - lengyou - <a asp-area="" asp-controller="Home" asp-
action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/lib/notify/notify.min.js"></script>

<script src="~/js/util.js"></script>

@RenderSection("Scripts", required: false)


</body>
</html>

3.Index.cshtml

@{
ViewData["Title"] = "Index";
}

@section scripts {
<script src="~/Views/Employee/employee.js"></script>
}

<div class="module employees" style="padding: 15px">

<div class="px-2 mt-2" style="padding: 15px; display:flex">

<input id="keyword" class="form-control-sm" placeholder="Search Keyword" />


<button id="search_employee" class="btn btn-sm btn-success w-15 ml-2">
<span class="spinner-border spinner-border-sm mr-1" role="status"
style="display:none"></span>
<i class="fa fa-search mr-1"></i>
Search
</button>
<button type="button" id="add_employee" data-toggle="modal" class="employee-
add btn btn-outline-secondary btn-sm ml-1">Add New Employee</button>
</div>

<div class="d-flex flex-row flex-wrap justify-content-center align-items-center"


style="margin-bottom: 60px; padding-left: 10px; padding-right: 10px;">
<table id="employees_list" class="table table-bordered table-sm table-striped table-
bordered" style="padding-left: 25px">
<thead>
<tr class="theme-secondary" style="background-color: #242562; text-
align:center;padding:25px;">
<th style="padding-left: 15px;">First Name</th>
<th>Last Name</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Department</th>
<th> Detail</th>
</tr>
</thead>
<tbody style="text-align:center">
@*This is a comment. The data of body will come from a partial view.*@
</tbody>
</table>
<div class="employee-form-container" id="employee_form" style="width: 100%;
height:100%">
@*We'll display add new employee form here.*@
</div>
</div>
</div>

4. Tabledata.cshtml

@{
List<Employee> EmployeeList = (List<Employee>)ViewData["EmployeesList"];
}

@if (EmployeeList.Count > 0)


{
foreach (var employee in EmployeeList)
{
<tr class="employees-row" style="width: 20%; text-align:center;">
<td>@employee.FirstName</td>
<td>@employee.LastName</td>
<td>@employee.Gender</td>
<td>@employee.Email</td>
<td>@employee.Address</td>
<td>@employee.Department</td>

<td>
<button type="button" class="btn btn-sm btn-dark employee-edit" data-
id="@employee.EmployeeId">
<i class="fa fa-edit"></i>
</button>
<button type="button" class="btn btn-sm btn-danger employee-delete" data-
id="@employee.EmployeeId">
<i class="fa fa-trash"></i>
</button>
</td>
</tr>
}
}
else
{
<tr>
<td colspan="10" style="text-align: center">
<div>
No Records
</div>
</td>
</tr>
}
5. AddstaffDepart.cs

@{
ViewData["Title"] = "AddStaffDepartForm";
Employee Employee = (Employee)ViewData["Employee"];
string Title = (string)ViewData["Title"];
}

<h1>AddStaffDepartForm</h1>

<div>
<label style="font-weight:bold">@Title</label>
</div>
<div class="pt-2 mb-2 employee_form" style="overflow:auto">
<table class="table table-bordered table-sm table-striped table-bordered">
<thead>
<tr style="background-color:azure">
<td>Property</td>
<td>Value</td>
</tr>
</thead>
<tbody>

<tr>
<td style="width: 100px">ID*</td>
<td>
<input type="hidden" id="employee_id" value="@Employee.EmployeeId" />
<input class="form-control-sm w-100" id="first_name"
value="@Employee.FirstName" autocomplete="off" />
</td>
</tr>
<tr>
<td style="width: 100px">Last Name*</td>
<td>
<input class="form-control-sm w-100" id="last_name"
value="@Employee.LastName" autocomplete="off" />
</td>
</tr>
<tr>
<td style="width: 100px">Gender</td>
<td>
<input class="form-control-sm w-100" id="Gender"
value="@Employee.Gender" autocomplete="off" />
</td>
</tr>

<tr>
<td style="width: 100px">Email</td>
<td>
<input class="form-control-sm w-100" id="Email"
value="@Employee.Email" autocomplete="off" />
</td>
</tr>
<tr>
<td style="width: 100px">Address</td>
<td>
<input class="form-control-sm w-100" id="Address"
value="@Employee.Address" autocomplete="off" />
</td>
</tr>
<tr>
<td style="width: 100px">Department</td>
<td>
<input class="form-control-sm w-100" id="department"
value="@Employee.Department" autocomplete="off" />

</tbody>
<tfoot>
<tr>
<td colspan="2" style="text-align:right">

<button type="button" class="btn btn-sm btn-outline-primary employee-


form-save" id="save_form">
<i class="fa fa-floppy-o" style="margin-right:5px"></i>
@(Employee.EmployeeId != 0? "Update" : "Create")
</button>

<button type="button" class="btn btn-sm btn-outline-primary employee-


form-close" id="close_form">
<i class="fa fa-close" style="margin-right:5px"></i>
Close
</button>
</td>
</tr>
</tfoot>
</table>
</div>

Add form

</tbody>
<tfoot>
<tr>
<td colspan="2" style="text-align:right">

<button type="button" class="btn btn-sm btn-outline-primary employee-


form-save" id="save_form">
<i class="fa fa-floppy-o" style="margin-right:5px"></i>
@(Employee.EmployeeId != 0? "Update" : "Create")
</button>

<button type="button" class="btn btn-sm btn-outline-primary employee-


form-close" id="close_form">
<i class="fa fa-close" style="margin-right:5px"></i>
Close
</button>
</td>
</tr>
</tfoot>
</table>
</div>
6. Staffdepart.cs

namespace IBJOffice.Models
{
public class StaffDepart
{
[Key]
public int EmployeeId { get; set; }

[Required]
public string DrpartmentName { get; set; }
[Required]
public string Descrition { get; set; }
}

You might also like