using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using Saadhvi_Services.Models;
using PagedList;
using PagedList.Mvc;
namespace Saadhvi_Services.Controllers
{
[HandleError]
public class ASLController : Controller
{
private saadhviEntities2 db = new saadhviEntities2();
// private saadhviEntities db = new saadhviEntities();
// GET: /ASL/
public ActionResult ASLInvoice()
{
if (Session["role"] == "admin")
{
return View(db.ASLs.Where(x => x.verified == true).OrderByDescending(x => x.Id).ToList());
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
[HttpPost]
public ActionResult ASLInvoice(DateTime? d1, DateTime? d2, string invoiceno = null)
{
if (Session["role"] == "admin")
{
return View(db.ASLs.Where(x => x.verified == true && x.aslinvoicenumber == invoiceno || x.ShipmentNo == invoiceno).OrderByDescending(x => x.Id).ToList());
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
public ActionResult Index(int? page)
{
if (Session["role"] == "admin" || Session["role"] == "user")
{
return View(db.ASLs.OrderByDescending(x => x.Id).ToList().ToPagedList(page ?? 1 ,10));
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
public ActionResult asllist()
{
if (Session["role"] == "admin")
{
return View(db.ASLs.OrderByDescending(x => x.Id).Where(x=>x.verified==false).ToList());
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
public ActionResult list()
{
if (Session["role"] == "user" || Session["role"] == "admin")
{
return View(db.ASLs.ToList());
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
public ActionResult list2()
{
if (Session["role"] == "user" || Session["role"] == "admin")
{
return View(db.ASLs.ToList());
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
[HttpPost]
public ActionResult EditList(ASL asl)
{
if (Session["role"] == "admin")
{
try
{
if (ModelState.IsValid)
{
db.Entry(asl).State = EntityState.Modified;
db.SaveChanges();
}
else
{
var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
}
}
catch (Exception ex)
{
throw;
}
return Json(JsonRequestBehavior.AllowGet);
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
[HttpPost]
public ActionResult EditMultiList(List asl)
{
if (Session["role"] == "admin")
{
var lastnumber = db.aslinvoicenoes.Select(x => x.aslinvoiceno1).Max();
var nextnumber = lastnumber + 1;
aslinvoiceno ino = new aslinvoiceno();
ino.aslinvoiceno1 = nextnumber;
db.aslinvoicenoes.Add(ino);
db.SaveChanges();
var no = "AL"+ nextnumber;
try
{
if (ModelState.IsValid)
{
foreach (var item in asl)
{
if (item.verified == true)
{
item.aslinvoicenumber = no;
db.Entry(item).State = EntityState.Modified;
db.SaveChanges();
}
}
}
else
{
var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
}
}
catch (Exception ex)
{
throw;
}
return Json(no,JsonRequestBehavior.AllowGet);
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
//public ActionResult EditList(List asl)
//{
// if (Session["role"] == "admin")
// {
// foreach (var item in asl)
// {
// try
// {
// if (ModelState.IsValid)
// {
// db.Entry(item).State = EntityState.Modified;
// db.SaveChanges();
// }
// else
// {
// var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList();
// }
// }
// catch (Exception ex)
// {
// throw;
// }
// }
// return Json(JsonRequestBehavior.AllowGet);
// }
// else
// {
// return RedirectToAction("notauthorized", "Users");
// }
//}
[HttpPost]
public ActionResult datesresult(DateTime d1, DateTime d2)
{
if (Session["role"] == "admin")
{
DateTime d22 = d2.Add(new TimeSpan(23, 59, 0));
var result = db.ASLs.Where(x => x.Date >= d1 && x.Date <= d22 && x.verified==true).OrderByDescending(x => x.Id).ToList();
return View("asllist", result);
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
// GET: /ASL/Create
public ActionResult Create()
{
if (Session["role"] == "user" || Session["role"] == "admin")
{
return View();
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
// POST: /ASL/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="Id,Date,ShipmentNo,DestinationCode,LrNo,Destination,Transportername,contactno,vehicletype,actualamount,loadingunloading,adv,podbalance,remarks")] ASL asl)
{
if (Session["role"] == "user" || Session["role"] == "admin")
{
if (ModelState.IsValid)
{
// asl.Date = DateTime.Now;
asl.verified = false;
db.ASLs.Add(asl);
db.SaveChanges();
TempData["asldatasaved"] = "Data";
return RedirectToAction("Index");
}
return View(asl);
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
// POST: /ASL/Delete/5
[HttpPost]
public ActionResult Deleteasl(int id)
{
if (Session["role"] == "admin")
{
ASL asl = db.ASLs.Find(id);
db.ASLs.Remove(asl);
db.SaveChanges();
return Json(JsonRequestBehavior.AllowGet);
}
else
{
return RedirectToAction("notauthorized", "Users");
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
ASLList.cshtml: @model IEnumerable@{ ViewBag.Title = "asllist"; } ASL List
@using (Html.BeginForm("datesresult", "ASL", FormMethod.Post)) {}
@if (Model != null) { int j = 1; foreach (var item in Model) { @Html.Label("Id") @Html.Label("ShipmentNo") @Html.Label("Date") @Html.Label("Destination Code") @Html.Label("Destination") @Html.Label("Vehicle No") @Html.Label("Vehicle Type") @Html.Label("Bill Amount") @Html.Label("Waiting Charge") @Html.Label("Extra Point") @Html.Label("Total Amount") @Html.Label("Select Shipment") @Html.Label("Invoice No") j++; } } @j @Html.DisplayFor(modelItem => item.ShipmentNo)
@Html.DisplayFor(modelItem => item.Date)
@Html.DisplayFor(modelItem => item.DestinationCode)
@Html.DisplayFor(modelItem => item.Destination)
@Html.DisplayFor(modelItem => item.Transportername)
@Html.DisplayFor(modelItem => item.vehicletype)
@Html.DisplayFor(modelItem => item.actualamount)
@Html.DisplayFor(modelItem => item.waitingcharge)
@Html.DisplayFor(modelItem => item.extrapoint)
@Html.DisplayFor(modelItem => item.totalamount)
@if (item.verified == true) { } else { } @Html.DisplayFor(modelItem => item.aslinvoicenumber)
@* *@ @**@ @**@
ASLInvoice.cshtml: @model IEnumerable@{ ViewBag.Title = "ASLInvoice"; } @if (Model.Count() != 0) {
@if (Model != null) { int j = 1; foreach (var item in Model) { @Html.Label("Id") @Html.Label("ShipmentNo") @Html.Label("Date") @Html.Label("Destination Code") @Html.Label("Destination") @Html.Label("Vehicle No") @Html.Label("Vehicle Type") @Html.Label("Bill Amount") @Html.Label("Waiting Charge") @Html.Label("Extra Point") @Html.Label("Total Amount") @*@Html.Label("Invoice No") *@j++; } } @j @Html.DisplayFor(modelItem => item.ShipmentNo) @Html.DisplayFor(modelItem => item.Date)
@Html.DisplayFor(modelItem => item.DestinationCode) @Html.DisplayFor(modelItem => item.Destination) @Html.DisplayFor(modelItem => item.Transportername) @Html.DisplayFor(modelItem => item.vehicletype) @Html.DisplayFor(modelItem => item.actualamount) @Html.DisplayFor(modelItem => item.waitingcharge) @Html.DisplayFor(modelItem => item.extrapoint) @* @Html.DisplayFor(modelItem => item.totalamount)
@Html.DisplayFor(modelItem => item.aslinvoicenumber) *@Sub Total: } else {Sorry No Records Found
} Index.cshtml; @using PagedList @using PagedList.Mvc @model IPagedList@{ ViewBag.Title = "Index"; } @**@ Index
@if (TempData["asldatasaved"] != null) { } else { }@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), new PagedListRenderOptions { DisplayPageCountAndCurrentLocation=true,ItemSliceAndTotalFormat="ss"})
@foreach (var item in Model) { @Html.Label("CreatedDate") @Html.Label("Shipment No") @Html.Label("Destination Code") @Html.Label("LrNo") @Html.Label("Destination") @Html.Label("Transporter Name") @Html.Label("Contact Number") @Html.Label("Vehicle Type") @Html.Label("Actual Amount") @Html.Label("Loading /Unloading") @Html.Label("ADV") @Html.Label("POD Balance") @Html.Label("Remarks") @Html.Label("Waiting Charge") @Html.Label("Extra Point") @Html.Label("Total Amount") } @Html.DisplayFor(modelItem => item.Date)
@Html.DisplayFor(modelItem => item.ShipmentNo) @Html.DisplayFor(modelItem => item.DestinationCode) @Html.DisplayFor(modelItem => item.LrNo) @Html.DisplayFor(modelItem => item.Destination) @Html.DisplayFor(modelItem => item.Transportername) @Html.DisplayFor(modelItem => item.contactno) @Html.DisplayFor(modelItem => item.vehicletype) @Html.DisplayFor(modelItem => item.actualamount) @Html.DisplayFor(modelItem => item.loadingunloading) @Html.DisplayFor(modelItem => item.adv) @Html.DisplayFor(modelItem => item.podbalance) @Html.DisplayFor(modelItem => item.remarks) @Html.DisplayFor(modelItem => item.waitingcharge) @Html.DisplayFor(modelItem => item.extrapoint) @Html.DisplayFor(modelItem => item.totalamount) @*@Html.ActionLink("Edit", "Edit", new { id = item.Id }) | @Html.ActionLink("Details", "Details", new { id = item.Id }) | @Html.ActionLink("Delete", "Delete", new { id = item.Id })*@ Create.cshtml: @model Saadhvi_Services.Models.ASL @{ ViewBag.Title = "Create"; } View ASL ListCreate ASL
@using (Html.BeginForm()) { @Html.AntiForgeryToken()} @section Scripts { @Scripts.Render("~/bundles/jqueryval") }@Html.ValidationSummary(true)@Html.Label("Date", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.Date, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.Date)@Html.LabelFor(model => model.ShipmentNo, new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.ShipmentNo, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.ShipmentNo)@Html.LabelFor(model => model.DestinationCode, new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.DestinationCode, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.DestinationCode)@Html.LabelFor(model => model.LrNo, new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.LrNo, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.LrNo)@Html.LabelFor(model => model.Destination, new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.Destination, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.Destination)@Html.LabelFor(model => model.Transportername, new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.Transportername, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.Transportername)@Html.Label("Contact Number", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.contactno, new { @required = "required", @type = "number", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.contactno)@Html.ValidationSummary(true)@Html.Label("Vehicle Type", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.vehicletype, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.vehicletype)@Html.Label("Actual Amount", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.actualamount, new { @required = "required", @type = "number", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.actualamount)@Html.Label("Loading/Unloading", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.loadingunloading, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.loadingunloading)@Html.Label("Adv", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.adv, new { @required = "required", @type = "number", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.adv)@Html.Label("POD Balance", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.podbalance, new { @required = "required", @type = "number", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.podbalance)@Html.Label("Remarks", new { @class = "control-label col-md-6" })@Html.TextBoxFor(model => model.remarks, new { @required = "required", autocomplete = "off", @class = "form-control" }) @Html.ValidationMessageFor(model => model.remarks)