Business ERP Part 23 Edit Branch Types 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 edit Branch Types, so now follow below code.
Source Code:
Action C# 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 EditBranchType(int? branchtypeid)
{
if (string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
{
return RedirectToAction("Login", "Home");
}
var userid = 0;
var UserTypeID = 0;
int.TryParse(Convert.ToString(Session["UserID"]), out userid);
int.TryParse(Convert.ToString(Session["UserTypeID"]), out UserTypeID);
if (UserTypeID != 1)
{
return RedirectToAction("Admin", "Dashboard");
}
var editbranchtype = DB.tblBranchTypes.Find(branchtypeid);
var branchtypemv = new BranchTypeMV();
branchtypemv.BranchTypeID = editbranchtype.BranchTypeID;
branchtypemv.BranchType = editbranchtype.BranchType;
return View(branchtypemv);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult EditBranchType(BranchTypeMV branchtypemv)
{
if (string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
{
return RedirectToAction("Login", "Home");
}
var userid = 0;
var usertypeid = 0;
int.TryParse(Convert.ToString(Session["UserID"]), out userid);
int.TryParse(Convert.ToString(Session["UserTypeID"]), out usertypeid);
if (usertypeid != 1)
{
return RedirectToAction("Admin", "Dashboard");
}
if (ModelState.IsValid)
{
var checkbranchtype = DB.tblBranchTypes.Where(bt => bt.BranchType == branchtypemv.BranchType.Trim() && bt.BranchTypeID != branchtypemv.BranchTypeID).FirstOrDefault();
if (checkbranchtype == null)
{
var editbranchtype = new tblBranchType();
editbranchtype.BranchType = branchtypemv.BranchType;
editbranchtype.BranchTypeID = branchtypemv.BranchTypeID;
DB.Entry(editbranchtype).State = System.Data.Entity.EntityState.Modified;
DB.SaveChanges();
return RedirectToAction("AllBranchTypes");
}
else
{
ModelState.AddModelError("BranchType", "Already Exist!");
}
}
return View(branchtypemv);
}
}
}
Edit View Code :
@model ERP_App.Models.BranchTypeMV
@{
ViewBag.Title = "Edit Branch Type";
}
<div class="col-lg-6">
<div class="card card-default mb-6">
<div class="card-header">Edit Branch Type</div>
<div class="card-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.BranchTypeID)
<div class="form-group">
@Html.LabelFor(model => model.BranchType, htmlAttributes: new { @class = "control-label col-md-6" })
<div class="col-md-10">
@Html.EditorFor(model => model.BranchType, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BranchType, "", 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", "AllBranchTypes", null, new { @class = "btn btn-outline-default" })
</div>
</div>
</div>
}
</div>
</div>
</div>
Comments
Post a Comment