public ActionResult Create(Models.Clientes Clientes, int codigoCliente) { try { if (ModelState.IsValid) { using (var db = new Models.SOFIAContext()) { if (codigoCliente == 0) { db.Add(Clientes); db.SaveChanges(); } else { db.Update <Models.Clientes>(Clientes); db.SaveChanges(); } } return(RedirectToAction(nameof(Index))); } else { using (var db = new Models.SOFIAContext()) { ViewData["Departamentos"] = db.Departamentos.ToList(); ViewData["Municipios"] = db.Municipios.ToList(); ViewData["Pais"] = db.Pais.ToList(); ViewData["Terminos"] = db.TerminosPagos.ToList(); } return(View(Clientes)); // return RedirectToActionPreserveMethod(nameof(Create),null ,Clientes); } //Models.Clientes c = new Models.Clientes(); //var type = c.GetType(); //PropertyInfo[] properties = type.GetProperties(); //c.CodigoCliente = int.Parse(collection["CodigoCliente"]); //foreach (var key in collection.Keys) { // var value = key.ToString(); // foreach (var p in properties) { // if (p.Name == value) { // p.SetValue(c,collection["value"]); // } // } //} // TODO: Add insert logic here } catch (Exception ex) { return(View()); } }
// GET: Clientes/Delete/5 public ActionResult Delete(int id) { using (var db = new Models.SOFIAContext()) { var cliente = db.Find <Models.Clientes>(id); db.Remove <Models.Clientes>(cliente); db.SaveChanges(); } return(RedirectToAction(nameof(Index))); }