Exemple #1
0
        public ActionResult Edit(DataGPS model)
        {
            if (ModelState.IsValid)
            {
                if (RepoDataGps.IsBoxExist(model.IdDataTruck.Value, model.Id))
                {
                    ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang gps, harap ganti dengan truck yang lain");
                    return(View("Form", model));
                }
                Context.DataGPS dbitem = RepoDataGps.FindByPK(model.Id);
                model.SetDb(dbitem);
                Context.DataGPSHistory dbitemHistory = new Context.DataGPSHistory();
                model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                dbitem.DataGPSHistory.Add(dbitemHistory);
                Context.DataTruckGPSHistory dbtruckHistory = new Context.DataTruckGPSHistory();
                model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                RepoDataGps.save(dbitem, UserPrincipal.id, dbitemHistory);

                Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value);
                dbtruck.DataTruckGPSHistory.Add(dbtruckHistory);
                RepoDataTruck.save(dbtruck, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Exemple #2
0
        public ActionResult Add(DataGPS model)
        {
            if (ModelState.IsValid)
            {
                if (RepoDataGps.IsBoxExist(model.IdDataTruck.Value))
                {
                    ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang gps, harap ganti dengan truck yang lain");
                    return(View("Form", model));
                }
                Context.DataGPS dbitem = new Context.DataGPS();
                model.SetDb(dbitem);
                //generate code
                dbitem.urutan = RepoDataGps.getUrutan() + 1;
                dbitem.NoGPS  = RepoDataGps.generateCode(dbitem.urutan);

                Context.DataGPSHistory dbitemHistory = new Context.DataGPSHistory();
                model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                dbitemHistory.Vehicle   = RepoDataTruck.FindByPK(dbitem.IdDataTruck.Value).VehicleNo;
                dbitemHistory.NoGPS     = dbitem.NoGPS;
                dbitemHistory.strVendor = dbitem.IdVendor.HasValue ? RepoVendorGPS.FindByPK(dbitem.IdVendor.Value).Nama : "";
                dbitem.DataGPSHistory.Add(dbitemHistory);
                Context.DataTruckGPSHistory dbtruckHistory = new Context.DataTruckGPSHistory();
                model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                RepoDataGps.save(dbitem, UserPrincipal.id, dbitemHistory);

                Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value);
                dbtruckHistory.Vehicle   = dbtruck.VehicleNo;
                dbtruckHistory.NoGPS     = dbitem.NoGPS;
                dbtruckHistory.strVendor = dbitem.IdVendor.HasValue ? RepoVendorGPS.FindByPK(dbitem.IdVendor.Value).Nama : "";
                dbtruck.DataTruckGPSHistory.Add(dbtruckHistory);
                RepoDataTruck.save(dbtruck, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }