Business ERP Part 36 Edit Branch 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 Edit Branch in tblBranchTable, 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 EditCompanyBranch(int? branchID)
{
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 editbranch = DB.tblBranches.Find(branchID);
var branch = new BranchMV();
branch.BranchID = editbranch.BranchID;
branch.BranchTypeID = editbranch.BranchTypeID;
branch.BranchType = editbranch.tblBranchType.BranchType;
branch.BranchName = editbranch.BranchName;
branch.BranchContact = editbranch.BranchContact;
branch.BranchAddress = editbranch.BranchAddress;
branch.CompanyID = editbranch.CompanyID;
var company = DB.tblCompanies.Find(editbranch.CompanyID).Name;
branch.Company = company;
branch.BrchID = editbranch.BrchID;
ViewBag.BranchTypeID = new SelectList(DB.tblBranchTypes.Where(bt => bt.BranchTypeID > branchtypeid), "BranchTypeID", "BranchType", editbranch.BranchTypeID);
return View(branch);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditCompanyBranch(BranchMV branchmv)
{
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);
if (ModelState.IsValid)
{
var editbranch = new tblBranch();
editbranch.BranchID = branchmv.BranchID;
editbranch.BranchName = branchmv.BranchName;
editbranch.BranchTypeID = branchmv.BranchTypeID;
editbranch.BranchAddress = branchmv.BranchAddress;
editbranch.BranchContact = branchmv.BranchContact;
editbranch.CompanyID = branchmv.CompanyID;
editbranch.BrchID = branchmv.BrchID;
DB.Entry(editbranch).State = System.Data.Entity.EntityState.Modified;
DB.SaveChanges();
return RedirectToAction("AllCompanyBranchs");
}
ViewBag.BranchTypeID = new SelectList(DB.tblBranchTypes.Where(bt => bt.BranchTypeID > branchtypeid), "BranchTypeID", "BranchType", branchmv.BranchTypeID);
return View(branchmv);
}
}
}
View Code :
@model ERP_App.Models.BranchMV
@{
ViewBag.Title = "Edit Branch";
}
<div class="col-lg-6">
<div class="card card-default mb-6">
<div class="card-header">Edit Branch</div>
<div class="card-body">
@using (Html.BeginForm("EditCompanyBranch", "Branch", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(u => u.CompanyID)
@Html.HiddenFor(u => u.BranchID)
@Html.HiddenFor(u => u.BrchID)
<div class="form-group">
@Html.LabelFor(model => model.BranchTypeID, "Select Branch Level", htmlAttributes: new { @class = "control-label col-md-6" })
<div class="col-md-10">
@Html.DropDownList("BranchTypeID", null, "Select Level", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.BranchTypeID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BranchName, htmlAttributes: new { @class = "control-label col-md-6" })
<div class="col-md-10">
@Html.EditorFor(model => model.BranchName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BranchName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BranchContact, htmlAttributes: new { @class = "control-label col-md-6" })
<div class="col-md-10">
@Html.EditorFor(model => model.BranchContact, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BranchContact, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BranchAddress, htmlAttributes: new { @class = "control-label col-md-6" })
<div class="col-md-10">
@Html.EditorFor(model => model.BranchAddress, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BranchAddress, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" class="btn btn-outline-success" />
@Html.ActionLink("Back", "AllCompanyBranchs", null, new { @class = "btn btn-outline-default" })
</div>
</div>
</div>
}
</div>
</div>
</div>
Comments
Post a Comment