Пример #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));
        }
Пример #2
0
 public void SetDbTruckHistory(Context.DataTruckGPSHistory dbitem, string user)
 {
     dbitem.NoGPS          = NoGPS;
     dbitem.Vehicle        = VehicleNo;
     dbitem.strVendor      = Vendor;
     dbitem.ModelGps       = ModelGps;
     dbitem.NoDevice       = NoDevice;
     dbitem.SensorSuhu     = SensorSuhu;
     dbitem.SensorPintu    = SensorPintu;
     dbitem.Tahun          = Tahun;
     dbitem.TanggalPasang  = TanggalPasang;
     dbitem.TanggalGaransi = TanggalGaransi;
     dbitem.Tanggal        = DateTime.Now;
     dbitem.Username       = user;
 }
Пример #3
0
 public DataGPS(Context.DataTruckGPSHistory dbitem)
 {
     Id             = dbitem.Id;
     NoGPS          = dbitem.NoGPS;
     VehicleNo      = dbitem.Vehicle;
     Vendor         = dbitem.strVendor;
     ModelGps       = dbitem.ModelGps;
     NoDevice       = dbitem.NoDevice;
     SensorSuhu     = dbitem.SensorSuhu;
     SensorPintu    = dbitem.SensorPintu;
     Tahun          = dbitem.Tahun;
     TanggalPasang  = dbitem.TanggalPasang;
     TanggalGaransi = dbitem.TanggalGaransi;
     Tanggal        = dbitem.Tanggal;
     username       = dbitem.Username;
 }
Пример #4
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));
        }