예제 #1
0
        public ActionResult Nuevo(ClienteViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (crudnetEntities db = new crudnetEntities())
                    {
                        var oTabla = new Cliente();
                        oTabla.Id       = model.Id;
                        oTabla.Nit      = model.Nit;
                        oTabla.Nombre   = model.Nombre;
                        oTabla.Apellido = model.Apellido;
                        oTabla.Edad     = model.Edad;
                        oTabla.Fecha    = model.Fecha;
                        db.Cliente.Add(oTabla);
                        db.SaveChanges();
                    }

                    return(Redirect("~/Cliente/"));
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #2
0
        public ActionResult Editar(ClienteViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (crudnetEntities db = new crudnetEntities())
                    {
                        var oTabla = db.Cliente.Find(model.Id);
                        oTabla.Id       = model.Id;
                        oTabla.Nit      = model.Nit;
                        oTabla.Nombre   = model.Nombre;
                        oTabla.Apellido = model.Apellido;
                        oTabla.Edad     = model.Edad;
                        oTabla.Fecha    = model.Fecha;
                        db.Cliente.Add(oTabla);

                        db.Entry(oTabla).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }

                    return(Redirect("~/Cliente/"));
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #3
0
 public ActionResult Eliminar(int Id)
 {
     using (crudnetEntities db = new crudnetEntities())
     {
         var oTabla = db.Cliente.Find(Id);
         db.Cliente.Remove(oTabla);
         db.SaveChanges();
     }
     return(Redirect("~/Cliente/"));
 }