Business ERP Part 37 Branch Employees in ASP.NET MVC

 Business ERP Part 37 Branch Employees in ASP.NET MVC

Hi, Dear's here we learn how to implement Auto Time Table Generator in Visual Studio using C# Windows Form. Ilyasoft software company provide full project step by step training on our YouTube Channel ilyasoft software company so now subscribe, share and like for more project base tutorials




In this part we are going to Implement to show Branch employees from tblEmployeeTable, so now follow below code.

Source Code: 
Action C# Code :
using DatabaseLayer;
using ERP_App.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ERP_App.Controllers
{
    public class AdminConfigController : Controller
    {
        private BusinessERPDbEntities DB = new BusinessERPDbEntities();
          public ActionResult BranchEmployees()
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
            {
                return RedirectToAction("Login", "Home");
            }
            var userid = 0;
            var usertypeid = 0;
            var companyid = 0;
            var branchid = 0;
            var branchtypeid = 0;
            int.TryParse(Convert.ToString(Session["UserID"]), out userid);
            int.TryParse(Convert.ToString(Session["UserTypeID"]), out usertypeid);
            int.TryParse(Convert.ToString(Session["CompanyID"]), out companyid);
            int.TryParse(Convert.ToString(Session["BranchID"]), out branchid);
            int.TryParse(Convert.ToString(Session["BranchTypeID"]), out branchtypeid);
            var employees = DB.tblEmployees.Where(e=>e.CompanyID == companyid && e.BranchID == branchid).ToList();
            var list = new List<EmployeeMV>();
            foreach (var employee in employees)
            {
                list.Add(new EmployeeMV() { 
                Address = employee.Address,
                BranchID = employee.BranchID,
                CNIC = employee.CNIC,
                CompanyID = employee.CompanyID,
                ContactNo = employee.ContactNo,
                Description = employee.Description,
                Designation = employee.Designation,
                Email = employee.Email,
                EmployeeID = employee.EmployeeID,
                MonthlySalary = employee.MonthlySalary,
                Name = employee.Name,
                Photo = employee.Photo,
                UserID = employee.UserID
                });
            }
            return View(list);
        }
    }
}

View Code :
@model IEnumerable<ERP_App.Models.EmployeeMV>

@{
    ViewBag.Title = "Employees";
}

<div class="card">
    <div class="card-header">
        <div class="card-title">Branch Employees</div>
    </div>
    <div class="card-body">
        <div>@Html.ActionLink("New Employee", "CreateBranchEmployee", null, new { @class = "btn btn-primary" })</div>
        <hr />
        <table class="table table-striped my-4 w-100" id="datatable2">
            <thead>
                <tr>
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.ContactNo)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Photo)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Email)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Address)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.CNIC)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.MonthlySalary)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Designation)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Description)
                    </th>


                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Name)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.ContactNo)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Photo)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Email)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Address)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.CNIC)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.MonthlySalary)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Designation)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Description)
                    </td>

                    <td>
                        @Html.ActionLink("Edit", "EditBranchEmployee", new { employeeid = item.EmployeeID }, new { @class = "btn btn-warning" })
                    </td>
                </tr>
                }
            </tbody>
        </table>
    </div>
</div>

Comments