public void save(RuteTol dbitem, int id) { var query = ""; if (dbitem.Id == 0) //create { context.RuteTol.Add(dbitem); } else //edit { context.RuteTol.Attach(dbitem); var entry = context.Entry(dbitem); entry.State = EntityState.Modified; query += "DELETE FROM dbo.\"TolBerangkat\" WHERE \"IdRuteTol\" = " + dbitem.Id + ";"; query += "DELETE FROM dbo.\"TolPulang\" WHERE \"IdRuteTol\" = " + dbitem.Id + ";"; } context.SaveChanges(); foreach (Context.TolBerangkat tp in dbitem.ListTolBerangkat) { query += "INSERT INTO dbo.\"TolBerangkat\" (\"IdRuteTol\", \"IdTol\") VALUES (" + tp.IdRuteTol + ", " + tp.IdTol + ");"; } foreach (Context.TolPulang tp in dbitem.ListTolPulang) { query += "INSERT INTO dbo.\"TolPulang\" (\"IdRuteTol\", \"IdTol\") VALUES (" + tp.IdRuteTol + ", " + tp.IdTol + ");"; } var auditrail = new Auditrail { Actionnya = dbitem.Id == 0 ? "Add" : "Edit", EventDate = DateTime.Now, Modulenya = "Rute Tol", QueryDetail = query, RemoteAddress = AppHelper.GetIPAddress(), IdUser = id }; context.Auditrail.Add(auditrail); context.SaveChanges(); }
public ActionResult Edit(int id) { Context.RuteTol dbitem = RepoRuteTol.FindByPK(id); RuteTol model = new RuteTol(dbitem); ViewBag.name = model.NamaRute; return(View("Form", model)); }
public ActionResult Edit(RuteTol model) { if (ModelState.IsValid) { Context.RuteTol dbitem = RepoRuteTol.FindByPK(model.Id); model.setDb(dbitem); RepoRuteTol.save(dbitem, UserPrincipal.id); return(RedirectToAction("Index")); } TolPP[] resultBerangkat = JsonConvert.DeserializeObject <TolPP[]>(model.strBerangkat); TolPP[] resultPulang = JsonConvert.DeserializeObject <TolPP[]>(model.strPulang); model.ListTolBerangkat = resultBerangkat.ToList(); model.ListTolPulang = resultPulang.ToList(); return(View("Form", model)); }
public void delete(RuteTol dbitem) { context.RuteTol.Remove(dbitem); context.SaveChanges(); }
public ActionResult Add() { RuteTol model = new RuteTol(); return(View("Form", model)); }