Saltar al contenido

operaciones de crud en web api sin usar el ejemplo de código de framework de entidad

Ejemplo 1: operación crud sin marco de entidad en mvc

using System.Web.Mvc;using CRUDinMVC.Models; namespace CRUDinMVC.Controllers{    public class StudentController : Controller    {                // 1. *************RETRIEVE ALL STUDENT DETAILS ******************        // GET: Student        public ActionResult Index()        {            StudentDBHandle dbhandle = new StudentDBHandle();            ModelState.Clear();            return View(dbhandle.GetStudent());        }         // 2. *************ADD NEW STUDENT ******************        // GET: Student/Create        public ActionResult Create()        {            return View();        }         // POST: Student/Create        [HttpPost]        public ActionResult Create(StudentModel smodel)        {            try            {                if (ModelState.IsValid)                {                    StudentDBHandle sdb = new StudentDBHandle();                    if (sdb.AddStudent(smodel))                    {                        ViewBag.Message = "Student Details Added Successfully";                        ModelState.Clear();                    }                }                return View();            }            catch            {                return View();            }        }         // 3. ************* EDIT STUDENT DETAILS ******************        // GET: Student/Edit/5        public ActionResult Edit(int id)        {            StudentDBHandle sdb = new StudentDBHandle();            return View(sdb.GetStudent().Find(smodel => smodel.Id == id));        }         // POST: Student/Edit/5        [HttpPost]        public ActionResult Edit(int id, StudentModel smodel)        {            try            {                StudentDBHandle sdb = new StudentDBHandle();                sdb.UpdateDetails(smodel);                return RedirectToAction("Index");            }            catch            {                return View();            }        }         // 4. ************* DELETE STUDENT DETAILS ******************        // GET: Student/Delete/5        public ActionResult Delete(int id)        {            try            {                StudentDBHandle sdb = new StudentDBHandle();                if (sdb.DeleteStudent(id))                {                    ViewBag.AlertMsg = "Student Deleted Successfully";                }                return RedirectToAction("Index");            }            catch            {                return View();            }        }    }}

Ejemplo 2: operación crud sin marco de entidad en mvc

Create procedure [dbo].[DeleteStudent]  (     @StdId int  )  as   begin     Delete from StudentReg where [email protected]  End
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *