Business EPR Part 29 New Purchase ASP.NET MVC
Source Code : NewPurchase.cshtml
@model IEnumerable<DatabaseAccess.tblPurchaseCartDetail>
@{
ViewBag.Title = "Purchasing";
}
<script src="~/Scripts/jquery-3.3.1.js"></script>
@using (Html.BeginForm("AddItem", "PurchaseCart", FormMethod.Post, null))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Purchase Details</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<label class="control-label col-md-2">Select Product</label>
<div class="col-md-6">
<select class="form-control" id="PID" name="PID" required></select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Quantity</label>
<div class="col-md-6">
<input type="number" class="form-control" id="Qty" name="Qty" placeholder="Enter Purchase Quantity..." required />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Unit Price</label>
<div class="col-md-6">
<input type="number" class="form-control" id="Price" step=".01" name="Price" placeholder="Enter Unit Price..." required />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Add Item" class="btn btn-success" />
</div>
</div>
</div>
}
<div class="card">
<div class="card card-flat">
<div class="card-header">
<h3 class="text-bold">Item's List</h3>
<h4 class="text-success">@{if (ViewBag.Message != null)
{ @ViewBag.Message; } else { @Session["ErrorMessagePur"]; } }</h4>
<input type="text" id="search" name="search" class="form-control col-md-3" style="float:right;" placeholder="search here" />
</div>
<div class="card-body">
<!-- START table-responsive-->
<div class="table-responsive">
<table class="table table-striped table-hover" id="dataTable">
<thead style="background-color:lightgray;">
<tr>
<th> Item's </th>
<th> Quantity </th>
<th> Unit Price </th>
<th> User </th>
<th>Action</th>
</tr>
</thead>
<tbody id="allitem">
@foreach (var item in Model)
{
<tr>
<td> @Html.DisplayFor(modelItem => item.tblStock.ProductName) </td>
<td> @Html.DisplayFor(modelItem => item.PurchaseQuantity) </td>
<td> @Html.DisplayFor(modelItem => item.purchaseUnitPrice) </td>
<td> @Html.DisplayFor(modelItem => item.tblUser.UserName) </td>
<td> @Html.ActionLink("Delete", "DeleteConfirm", new { id = item.PurchaseCartDetailID }, new { @class = "btn btn-danger" }) </td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td style="background-color:aqua;"><input value="Finilize" class="form-control btn btn-success" /></td>
<td>@Html.ActionLink("Cancel", "CancelPurchase", null, new { @class = "btn btn-danger"})</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#search").on("keyup", function () {
var value = $(this).val().toLowerCase();
$("#allitem tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
$.ajax({
url: '@Url.Action("GetProduct", "PurchaseCart")',
type: 'GET',
data: "{}",
success: function (response) {
for(var i = 0; i < response.data.length; i++)
{
$('#PID').append("<option value=" + response.data[i].ProductID + ">" + response.data[i].Name + "</option>");
}
},
error: function () {
}
});
});
</script>
Source Code : PurchaseCartController
@Html.ActionLink("Delete", "DeleteConfirm", new { id = item.PurchaseCartDetailID }, new { @class = "btn btn-danger" })
public ActionResult DeleteConfirm(int? id)
{
if (string.IsNullOrEmpty(Convert.ToString(Session["CompanyID"])))
{
return RedirectToAction("Login", "Home");
}
int companyid = 0;
int branchid = 0;
int userid = 0;
branchid = Convert.ToInt32(Convert.ToString(Session["BranchID"]));
companyid = Convert.ToInt32(Convert.ToString(Session["CompanyID"]));
userid = Convert.ToInt32(Convert.ToString(Session["UserID"]));
var product = db.tblPurchaseCartDetails.Find(id);
if (product != null)
{
db.Entry(product).State = System.Data.Entity.EntityState.Deleted;
db.SaveChanges();
ViewBag.Message = "Deleted Successfully.";
return RedirectToAction("NewPurchase");
}
ViewBag.Message = "Some Unexptected issue is occure, please contact to concern person!";
var find = db.tblPurchaseCartDetails.Where(i => i.BranchID == branchid && i.CompanyID == companyid && i.UserID == userid);
return View(find.ToList());
}
public ActionResult CancelPurchase()
{
if (string.IsNullOrEmpty(Convert.ToString(Session["CompanyID"])))
{
return RedirectToAction("Login", "Home");
}
int companyid = 0;
int branchid = 0;
int userid = 0;
branchid = Convert.ToInt32(Convert.ToString(Session["BranchID"]));
companyid = Convert.ToInt32(Convert.ToString(Session["CompanyID"]));
userid = Convert.ToInt32(Convert.ToString(Session["UserID"]));
var list = db.tblPurchaseCartDetails.Where(p=>p.BranchID == branchid && p.CompanyID == companyid &&p.UserID == userid).ToList();
bool cancelstatus = false;
foreach (var item in list)
{
db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
int noofrecords = db.SaveChanges();
if (cancelstatus == false)
{
if (noofrecords > 0)
{
cancelstatus = true;
}
}
}
if (cancelstatus == true)
{
ViewBag.Message = "Purchase is Canceled.";
return RedirectToAction("NewPurchase");
}
ViewBag.Message = "Some Unexptected issue is occure, please contact to concern person!";
var find = db.tblPurchaseCartDetails.Where(i => i.BranchID == branchid && i.CompanyID == companyid && i.UserID == userid);
return View(find.ToList());
}
Comments
Post a Comment