コード例 #1
0
 public ActionResult AddOrEdit(Registro reg)
 {
     try
     {
         if (reg.CargarImagen != null)
         {
             string fileName  = Path.GetFileNameWithoutExtension(reg.CargarImagen.FileName);
             string extension = Path.GetExtension(reg.CargarImagen.FileName);
             fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
             reg.Foto = "~/AppFiles/Imagenes/" + fileName;
             reg.CargarImagen.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Imagenes/"), fileName));
         }
         using (DBModel5 db = new DBModel5())
         {
             if (reg.Id == 0)
             {
                 db.Registroes.Add(reg);
                 db.SaveChanges();
             }
             else
             {
                 db.Entry(reg).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
         return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllRegistro()), message = "Datos enviados con exito" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }