public ActionResult Create(DepotVM v)
        {
            tblDepot a = new tblDepot();

            if (ModelState.IsValid)
            {
                // a.CountryID = 1;// v.CountryID;
                //a.CityID = 19;// v.CityID;
                a.CountryName = v.CountryName;
                a.CityName    = v.CityName;
                a.Depot       = v.Depot;
                a.CompanyID   = 1;
                a.BranchID    = Convert.ToInt32(Session["CurrentBranchID"].ToString());
                a.IsOwn       = v.IsOwn;
                if (v.IsOwn == false)
                {
                    a.AgentID = v.AgentID;
                }

                db.tblDepots.Add(a);
                db.SaveChanges();
                TempData["SuccessMsg"] = "You have successfully added Depot.";
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public JsonResult SetDepotDetails(int Id, string DepotName, int Order)
        {
            var invoice = new DepotVM();

            invoice.ID      = Id;
            invoice.Depot   = DepotName;
            invoice.AgentID = Order + 1;
            return(Json(new { InvoiceDetails = invoice }, JsonRequestBehavior.AllowGet));
        }
        //
        // GET: /Depot/Edit/5

        public ActionResult Edit(int id = 0)
        {
            tblDepot tbldepot = db.tblDepots.Find(id);

            //ViewBag.Country = db.CountryMasters.ToList();
            //ViewBag.Hubs = (from c in db.CityMasters where c.IsHub == true && c.CountryID==tbldepot.CountryID select c).ToList();
            ViewBag.Agent = db.AgentMasters.ToList();

            DepotVM v = new DepotVM();

            if (tbldepot == null)
            {
                return(HttpNotFound());
            }
            else
            {
                v.ID = tbldepot.ID;
                //v.CountryID = tbldepot.CountryID.Value;
                //v.CityID = tbldepot.CityID.Value;
                //a.CityID = 19;// v.CityID;
                v.CountryName = tbldepot.CountryName;
                v.CityName    = tbldepot.CityName;

                v.CompanyID = tbldepot.CompanyID;
                v.Depot     = tbldepot.Depot;
                v.IsOwn     = tbldepot.IsOwn.Value;
                v.AgentID   = tbldepot.AgentID;

                if (v.IsOwn == true)
                {
                    v.Own = "True";
                }
                else
                {
                    v.Own = "False";
                }
            }
            return(View(v));
        }
        public ActionResult Edit(DepotVM v)
        {
            tblDepot a = new tblDepot();

            if (ModelState.IsValid)
            {
                a.ID          = v.ID;
                a.CompanyID   = v.CompanyID;
                a.BranchID    = Convert.ToInt32(Session["CurrentBranchID"].ToString());
                a.CityID      = 19;// v.CityID;
                a.CountryName = v.CountryName;
                a.CityName    = v.CityName;
                a.IsOwn       = v.IsOwn;
                a.AgentID     = v.AgentID;
                a.Depot       = v.Depot;

                db.Entry(a).State = EntityState.Modified;
                db.SaveChanges();
                TempData["SuccessMsg"] = "You have successfully Updated Depot.";
                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public JsonResult GetRouteDetails(int Id)
        {
            var Route = (from d in db.RouteMasters
                         join o in db.LocationMasters on d.OrginLocationID equals o.LocationID
                         join de in db.LocationMasters on d.DestinationLocationID equals de.LocationID
                         where d.RouteID == Id
                         select new { d = d, o = o, de = de }).FirstOrDefault();

            var list        = new List <DepotVM>();
            var RouteOrders = (from d in db.RouteOrders

                               where d.RouteID == Route.d.RouteID select d).ToList();

            foreach (var item in RouteOrders)
            {
                var invoice = new DepotVM();
                invoice.ID      = Convert.ToInt32(item.DepotID);
                invoice.Depot   = db.tblDepots.Find(item.DepotID).Depot;
                invoice.AgentID = item.StopOrder;
                list.Add(invoice);
            }
            return(Json(new { InvoiceDetails = list, Origin = Route.o.Location, Destination = Route.de.Location }, JsonRequestBehavior.AllowGet));
        }