Business ERP Part 43 Stock Categories in ASP.NET MVC

 Business ERP Part 43 Stock Categories 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 stock categories to retrieve from tblCategory, 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 AllCategories()
        {
            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 list = new List<CategoryMV>();
            var categories = DB.tblCategories.Where(c=>c.CompanyID == companyid && c.BranchID == branchid).ToList();
            foreach (var category in categories)
            {
                var username = category.tblUser.UserName;
                list.Add(new CategoryMV()
                {
                    BranchID = category.BranchID,
                    CategoryID = category.CategoryID,
                    categoryName = category.categoryName,
                    CompanyID = category.CompanyID,
                    UserID = category.UserID,
                    CreatedBy = username
                });
            }
            return View(list);
        }
    }
}
View Code :
@model IEnumerable<ERP_App.Models.CategoryMV>

@{
    ViewBag.Title = "Stock Categories";
}

<div class="card">
<div class="card-header">
    <div class="card-title">Stock Categories</div>

</div>
<div class="card-body">
    <div>@Html.ActionLink("New Category", "CreateCategory", 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.categoryName)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedBy)
                </th>

                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.categoryName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.CreatedBy)
                    </td>

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

Comments