Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
3
Answers
MVC CRUD Operation With Case Cading
Singaravel Vela
5y
689
1
Reply
Hi All,
I have creating MVC application Crud opration with Case Cading using DB First.
Please find the source below.
Add View
@model Learning1.Models.Tbl_employee
@
using
(Html.BeginForm())
{
@Html.AntiForgeryToken()
<div
class
=
"form-horizontal"
>
<h4>Tbl_employee</h4>
<hr />
@*@Html.ValidationSummary(
true
,
""
,
new
{ @
class
=
"text-danger"
})*@
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.EmpName, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.EmpName,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.EmpName,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Gender, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*Male
@Html.RadioButtonFor(model => model.Gender,
"Male"
)
Female
@Html.RadioButtonFor(model => model.Gender,
"Female"
)*@
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.SkillsID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@
for
(
int
i=0;i<Model.SkillList.Count;i++)
{
//string tes = "chk_" + Model.SkillList[i].SkillName;
@Html.HiddenFor(m => Model.SkillList[i].SkillID)
@Html.HiddenFor(m => Model.SkillList[i].SkillName)
@Html.CheckBoxFor(m => Model.SkillList[i].Checked)
@*<input id=
"@tes"
type=
"checkbox"
value=
"@Model.SkillList[i].SkillName"
/>@Model.SkillList[i].SkillName<br />*@
@Html.DisplayFor(m => Model.SkillList[i].SkillName)
}
@Html.ValidationMessageFor(model => model.SkillsID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.MobileNumber, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.MobileNumber,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.MobileNumber,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.DesignationID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.DesignationID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.DesignationID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Salary, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Salary,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Salary,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.SkillsID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@
for
(
int
i = 0; i < Model.SkillList.Count; i++)
{
//string tes = "chk_" + Model.SkillList[i].SkillName;
@Html.HiddenFor(m => Model.SkillList[i].SkillID)
@Html.HiddenFor(m => Model.SkillList[i].SkillName)
@Html.CheckBoxFor(m => Model.SkillList[i].Checked)
@*<input id=
"@tes"
type=
"checkbox"
value=
"@Model.SkillList[i].SkillName"
/>@Model.SkillList[i].SkillName<br />*@
@Html.DisplayFor(m => Model.SkillList[i].SkillName)
}
@Html.ValidationMessageFor(model => model.SkillsID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.DepartmentID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.EditorFor(model => model.DepartmentID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })*@
@Html.DropDownListFor(model=>model.DepartmentID,
new
System.Web.Mvc.SelectList(Model.DepartmentList.OrderBy(s=>s.DepartmentName),
"DepartmentID"
,
"DepartmentName"
,Model.DepartmentID),
"-select"
,
new
{ @
class
=
"form-control"
, @role =
"DropDown"
})
@Html.ValidationMessageFor(model => model.DepartmentID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.CountryID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.EditorFor(model => model.CountryID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })*@
@Html.DropDownListFor(model => model.CountryID,
new
System.Web.Mvc.SelectList(Model.CountryList.OrderBy(s => s.CountryName),
"CountryID"
,
"CountryName"
, Model.CountryID),
"-select-"
,
new
{ @
class
=
"form-control"
, @role =
"DropDown"
})
@Html.ValidationMessageFor(model => model.CountryID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.CityID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.EditorFor(model => model.CityID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })*@
@Html.DropDownListFor(model => model.CityID,
new
System.Web.Mvc.SelectList(Model.CityList.OrderBy(s => s.CityName),
"CityID"
,
"CityName"
, Model.CityID),
"-select-"
,
new
{ @
class
=
"form-control"
, @role =
"DropDown"
})
@Html.ValidationMessageFor(model => model.CityID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
<div
class
=
"col-md-offset-2 col-md-10"
>
<input type=
"submit"
value=
"Create"
class
=
"btn btn-default"
/>
</div>
</div>
</div>
}
<div>
@Html.ActionLink(
"Back to List"
,
"Index"
)
</div>
<script src=
"~/Scripts/jquery-1.10.2.min.js"
></script>
<script src=
"~/Scripts/jquery.validate.min.js"
></script>
<script src=
"~/Scripts/jquery.validate.unobtrusive.min.js"
></script>
<script>
$(document).ready(function () {
$(
"#CountryID"
).change(function () {
$.ajax({
type:
"POST"
,
url:
'@Url.Action("GetCity", "Employee")'
,
// contentType: "application/json; charset=utf-8",
data: { CountryID: $(
this
).val() },
dataType:
"json"
,
success: function (response) {
let options =
''
;
options +=
'<option value=0>-Select-</option>'
;
$.each(response, function (i, item) {
options +=
'<option value='
+item.CityID+
'>'
+item.CityName+
'</option>'
;
})
;
$(
'#CityID'
).html(options);
},
error: function (error) {
debugger
},
});
});
});
</script>
Edit View
@model Learning1.Models.Tbl_employee
@
using
(Html.BeginForm())
{
@Html.AntiForgeryToken()
<div
class
=
"form-horizontal"
>
<h4>Tbl_employee</h4>
<hr />
@*@Html.ValidationSummary(
true
,
""
,
new
{ @
class
=
"text-danger"
})*@
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.EmpName, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.EmpName,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.EmpName,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Gender, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*Male
@Html.RadioButtonFor(model => model.Gender,
"Male"
)
Female
@Html.RadioButtonFor(model => model.Gender,
"Female"
)*@
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.SkillsID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@
for
(
int
i = 0; i < Model.SkillList.Count; i++)
{
@Html.HiddenFor(m => Model.SkillList[i].SkillID)
@Html.HiddenFor(m => Model.SkillList[i].SkillName)
@Html.CheckBoxFor(m => Model.SkillList[i].Checked, htmlAttributes:
new
{ @
checked
=
true
})
@Html.DisplayFor(m => Model.SkillList[i].SkillName)
}
@Html.ValidationMessageFor(model => model.SkillsID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.MobileNumber, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.MobileNumber,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.MobileNumber,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.DesignationID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.DesignationID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.DesignationID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Salary, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Salary,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Salary,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.DepartmentID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.EditorFor(model => model.DepartmentID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })*@
@Html.DropDownListFor(model => model.DepartmentID,
new
System.Web.Mvc.SelectList(Model.DepartmentList.OrderBy(s => s.DepartmentName),
"DepartmentID"
,
"DepartmentName"
, Model.DepartmentID),
"-select"
,
new
{ @
class
=
"form-control"
, @role =
"DropDown"
})
@Html.ValidationMessageFor(model => model.DepartmentID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.CountryID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.EditorFor(model => model.CountryID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })*@
@Html.DropDownListFor(model => model.CountryID,
new
System.Web.Mvc.SelectList(Model.CountryList.OrderBy(s => s.CountryName),
"CountryID"
,
"CountryName"
, Model.CountryID),
"-select-"
,
new
{ @
class
=
"form-control"
, @role =
"DropDown"
})
@Html.ValidationMessageFor(model => model.CountryID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.CityID, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@*@Html.EditorFor(model => model.CityID,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })*@
@Html.DropDownListFor(model => model.CityID,
new
System.Web.Mvc.SelectList(Model.CityList.OrderBy(s => s.CityName),
"CityID"
,
"CityName"
, Model.CityID),
"-select-"
,
new
{ @
class
=
"form-control"
, @role =
"DropDown"
})
@Html.ValidationMessageFor(model => model.CityID,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
<div
class
=
"col-md-offset-2 col-md-10"
>
<input type=
"submit"
value=
"Create"
class
=
"btn btn-default"
/>
</div>
</div>
</div>
}
<div>
@Html.ActionLink(
"Back to List"
,
"List"
)
</div>
<script src=
"~/Scripts/jquery-1.10.2.min.js"
></script>
<script src=
"~/Scripts/jquery.validate.min.js"
></script>
<script src=
"~/Scripts/jquery.validate.unobtrusive.min.js"
></script>
<script>
$(document).ready(function () {
$(
"#CountryID"
).change(function () {
$.ajax({
type:
"POST"
,
url:
'@Url.Action("GetCity", "Employee")'
,
// contentType: "application/json; charset=utf-8",
data: { CountryID: $(
this
).val() },
dataType:
"json"
,
success: function (response) {
let options =
''
;
options +=
'<option value=0>-Select-</option>'
;
$.each(response, function (i, item) {
options +=
'<option value='
+item.CityID+
'>'
+item.CityName+
'</option>'
;
})
;
$(
'#CityID'
).html(options);
},
error: function (error) {
debugger
},
});
});
});
</script>
List View
@model IEnumerable<Learning1.Models.EmployeeDTO>
@
using
Learning1.Models;
@{
ViewBag.Title =
"List"
;
LeaningOneEntities dbEntity =
new
LeaningOneEntities();
}
<h2>List</h2>
<p>
@Html.ActionLink(
"Create New"
,
"AddNew"
,
"Employee"
)
</p>
<table
class
=
"table"
>
<tr>
<th>
@Html.DisplayNameFor(model => model.EmpName)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.MobileNumber)
</th>
<th>
@Html.DisplayName(
"Designation"
)
</th>
<th>
@Html.DisplayNameFor(model => model.Salary)
</th>
<th>
@Html.DisplayName(
"Department"
)
</th>
<th>
@Html.DisplayName(
"Country"
)
</th>
<th>
@Html.DisplayName(
"City"
)
</th>
<th>
@Html.DisplayName(
"Skills"
)
</th>
<th></th>
</tr>
@
foreach
(var item
in
Model) {
var skill =
""
;
<tr>
<td>
@Html.DisplayFor(modelItem => item.EmpName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.MobileNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.DesignationName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Salary)
</td>
<td>
@Html.DisplayFor(modelItem => item.DepartmentName)
</td>
<td>
@Html.DisplayFor(modelItem => item.CountryName)
</td>
<td>
@Html.DisplayFor(modelItem => item.CityName)
</td>
@
foreach
(var i
in
item.empSkillSet)
{
var emplist = (from s
in
dbEntity.Tbl_Skills
where s.SkillID == i.SkillID select s.SkillName).SingleOrDefault();
skill = skill + emplist +
","
;
}
<td>
@Html.DisplayFor(modelItem => skill)
</td>
<td>
@Html.ActionLink(
"Edit"
,
"EditEmployee"
,
new
{ EmpId = item.EmpID }) |
@Html.ActionLink(
"Details"
,
"Details"
,
new
{ id=item.EmpID }) |
@Html.ActionLink(
"Delete"
,
"DeleteEmploye"
,
new
{ EmpId = item.EmpID })
</td>
</tr>
}
</table>
Controller
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
Learning1.Models;
using
System.Data.Entity;
namespace
Learning1.Controllers
{
public
class
EmployeeController : Controller
{
// GET: Employee
LeaningOneEntities dbEntity =
new
LeaningOneEntities();
public
ActionResult Index()
{
return
View();
}
[HttpGet]
public
ActionResult List()
{
var objList1 = (from e
in
dbEntity.Tbl_employee
join d
in
dbEntity.Tbl_Department on e.DepartmentID equals d.DepartmentID
join c
in
dbEntity.Tbl_Country on e.CountryID equals c.CountryID
join ci
in
dbEntity.Tbl_City on e.CityID equals ci.CityID
// join Emps in dbEntity.Tbl_EmpSkills on e.EmpID equals Emps.EmpID
select
new
EmployeeDTO
{
EmpID = e.EmpID,
EmpName = e.EmpName,
DepartmentName = d.DepartmentName,
Email = e.Email,
MobileNumber = e.MobileNumber,
DesignationName = e.DesignationID,
Salary = e.Salary,
CountryName = c.CountryName,
CityName = ci.CityName,
empSkillSet = dbEntity.Tbl_EmpSkills.Where(w=>w.EmpID==e.EmpID).ToList()
//GetEmployeeskills(e.EmpID)
}).ToList();
return
View(objList1);
}
public
ActionResult AddNew()
{
var objEmp =
new
Tbl_employee();
objEmp.CountryList = (from c
in
dbEntity.Tbl_Country select c ).ToList();
objEmp.DepartmentList = (from d
in
dbEntity.Tbl_Department select d).ToList();
objEmp.SkillList = (from s
in
dbEntity.Tbl_Skills select s).ToList();
return
View(objEmp);
}
[HttpPost]
public
ActionResult AddNew(Tbl_employee obj)
{
dbEntity.Tbl_employee.Add(obj);
dbEntity.SaveChanges();
List<Tbl_EmpSkills> empSkills =
new
List<Tbl_EmpSkills>();
foreach
(var s
in
obj.SkillList.Where(s=>s.Checked))
{
Tbl_EmpSkills objs =
new
Tbl_EmpSkills();
objs.EmpID = obj.EmpID;
objs.SkillID = s.SkillID;
dbEntity.Tbl_EmpSkills.Add(objs);
dbEntity.SaveChanges();
}
return
RedirectToAction(
"List"
,
"Employee"
);
}
[HttpGet]
public
ActionResult EditEmployee(Int32 empID)
{
List<Tbl_Skills> objskill =
new
List<Tbl_Skills>();
var objEmp = dbEntity.Tbl_employee.Where(w=>w.EmpID == empID).SingleOrDefault();
objEmp.CountryList = (from c
in
dbEntity.Tbl_Country select c).ToList();
objEmp.DepartmentList = (from d
in
dbEntity.Tbl_Department select d).ToList();
var empskill = dbEntity.Tbl_EmpSkills.Where(w=>w.EmpID ==objEmp.EmpID).ToList();
objEmp.SkillList = dbEntity.Tbl_Skills.ToList();
foreach
(var item
in
empskill)
{
objEmp.SkillList[Convert.ToInt32(item.SkillID)-1].Checked =
true
;
}
objEmp.CityList = dbEntity.Tbl_City.Where(w=>w.CountryID == objEmp.CountryID).ToList();
return
View(objEmp);
}
public
ActionResult EditEmployee(Tbl_employee obj)
{
var EmpData = dbEntity.Tbl_employee.Where(x => x.EmpID == obj.EmpID).FirstOrDefault();
if
(EmpData !=
null
)
{
EmpData.EmpName = obj.EmpName;
EmpData.MobileNumber = obj.MobileNumber;
EmpData.Salary = obj.Salary;
EmpData.CityID = obj.CityID;
EmpData.CountryID = obj.CountryID;
EmpData.DesignationID = obj.DesignationID;
EmpData.DepartmentID = obj.DepartmentID;
dbEntity.Entry(EmpData).State = EntityState.Modified;
dbEntity.SaveChanges();
}
var emskill = dbEntity.Tbl_EmpSkills.Where(w => w.EmpID == obj.EmpID).FirstOrDefault();
if
(emskill !=
null
)
{
dbEntity.Entry(emskill).State = EntityState.Deleted;
dbEntity.SaveChanges();
}
List<Tbl_EmpSkills> empList =
new
List<Tbl_EmpSkills>();
foreach
(var s
in
obj.SkillList.Where(s => s.Checked))
{
Tbl_EmpSkills ob =
new
Tbl_EmpSkills();
ob.EmpID = obj.EmpID;
ob.SkillID = s.SkillID;
dbEntity.Tbl_EmpSkills.Add(ob);
dbEntity.SaveChanges();
}
return
RedirectToAction(
"List"
,
"Employee"
);
}
public
ActionResult DeleteEmploye(
int
EmpID)
{
if
(EmpID > 0)
{
var EmpByID = dbEntity.Tbl_employee.Where(x => x.EmpID == EmpID).FirstOrDefault();
if
(EmpByID !=
null
)
{
dbEntity.Entry(EmpByID).State = EntityState.Deleted;
dbEntity.SaveChanges();
}
}
return
RedirectToAction(
"List"
,
"Employee"
);
}
[HttpPost]
public
ActionResult GetCity(
string
CountryID)
{
Int32 CountryID1 = Convert.ToInt32(CountryID);
var objCityList = (from c
in
dbEntity.Tbl_City where c.CountryID == CountryID1 select c).ToList();
return
Json(objCityList);
}
public
List<SkillsetDTO> GetEmployeeskills(Int64 EmpID)
{
var emplist = (from s
in
dbEntity.Tbl_Skills
join ems
in
dbEntity.Tbl_EmpSkills on s.SkillID equals ems.SkillID
where ems.EmpID == EmpID
select
//ems).ToList()
new
SkillsetDTO
{
SkillID = s.SkillID,
Empskillset = s.SkillName,
EmpID = EmpID
}).ToList();
return
emplist;
}
}
}
Model
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
namespace
Learning1.Models
{
public
partial
class
Tbl_employee
{
public
string
CountryName {
get
;
set
; }
public
List<Tbl_Country> CountryList {
get
;
set
; }
public
List<Tbl_City> CityList {
get
;
set
; }
public
List<Tbl_Department> DepartmentList {
get
;
set
; }
public
List<Tbl_Skills> SkillList {
get
;
set
; }
public
List<Tbl_EmpSkills> empSkillSet {
get
;
set
; }
public
Tbl_employee()
{
CountryList =
new
List<Tbl_Country>();
CityList =
new
List<Tbl_City>();
SkillList =
new
List<Tbl_Skills>();
empSkillSet =
new
List<Tbl_EmpSkills>();
}
}
public
partial
class
Tbl_EmpSkills
{
public
string
Empskillset {
get
;
set
; }
}
public
class
EmployeeDTO : Tbl_employee
{
public
string
DepartmentName {
get
;
set
; }
public
string
DesignationName {
get
;
set
; }
public
string
CityName {
get
;
set
; }
}
public
class
SkillsetDTO:Tbl_EmpSkills
{
}
}
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Transfer the videos from One Web page to another Web page.
How to convert jsondata to model in mvc