Business ERP Part 35 Branches List in ASP.NET MVC

 Business ERP Part 35 Branches List 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 show branches list in part 35, 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 AllCompanyBranchs()
        {
            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 branchs = DB.tblBranches.Where(b => b.BrchID == branchid && b.CompanyID == companyid).ToList();
            var list = new List<BranchMV>();
            foreach (var branch in branchs)
            {
                var addbranch = new BranchMV();
                addbranch.BranchID = branch.BranchID;
                addbranch.BranchTypeID = branch.BranchTypeID;
                addbranch.BranchType = branch.tblBranchType.BranchType;
                addbranch.BranchName = branch.BranchName;
                addbranch.BranchContact = branch.BranchContact;
                addbranch.BranchAddress = branch.BranchAddress;
                addbranch.CompanyID = branch.CompanyID;
                var company = DB.tblCompanies.Find(branch.CompanyID).Name;
                addbranch.Company = company;
                addbranch.BrchID = branch.BrchID;
                list.Add(addbranch);
            }
            return View(list);
        }
    }
}

View Code :
@model IEnumerable<ERP_App.Models.BranchMV>
@{
    ViewBag.Title = "All Branch's";
}
<div class="card">
    <div class="card-header">
        <div class="card-title">All Branch's</div>

    </div>
    <div class="card-body">
        <div>@Html.ActionLink("New Branch", "CreateCompanyBranch", 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.BranchType)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.BranchName)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Company)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.BranchContact)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.BranchAddress)
                    </th>

                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.BranchType)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.BranchName)
                    </td>
                    <th>
                        @Html.DisplayFor(modelItem => item.Company)
                    </th>
                    <td>
                        @Html.DisplayFor(modelItem => item.BranchContact)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.BranchAddress)
                    </td>

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

Comments