Individual Assignment
Individual Assignment
បេត្តប ៀមរា
មហាិវលកសាខាសាិវលកលស្រ ន
ត វង បចេាិវលក
ជំនាន់ល១
ី ៨ ឆ្ន ំ៣ ឆមា លី២
ាវចេការប្រលិប្រាិ ុគ្សា
គ ់
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;
}
// 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?}");
});
}
}
}
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>
<script src="~/js/util.js"></script>
3. Index.cshtml
@{
ViewData["Title"] = "Index";
}
@section scripts {
<script src="~/Views/Employee/employee.js"></script>
}
4. Tabledata.cshtml
@{
List<Employee> EmployeeList = (List<Employee>)ViewData["EmployeesList"];
}
<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">
Add form
</tbody>
<tfoot>
<tr>
<td colspan="2" style="text-align:right">
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; }
}