Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aman 3 posts 73 karma points
    Aug 04, 2016 @ 14:08
    Aman
    0

    CRUD operation in umbraco using surface controller

    Hi, i am just new to umbraco please any one can help me. how can i perform Insert ,update and delete operation in umbraco using surfacecontroller.

  • David Peck 690 posts 1896 karma points c-trib
    Aug 05, 2016 @ 06:04
    David Peck
    0

    They are all exposed as services: Application.Services.ContentService Application.Services.xxx

  • David Peck 690 posts 1896 karma points c-trib
    Aug 05, 2016 @ 06:05
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 8x admin c-trib
    Aug 05, 2016 @ 06:29
    Dave Woestenborghs
    0

    Hi Amit,

    Do you mean CRUD operations on content or on a custom database ?

    For content you can use the content service : https://our.umbraco.org/documentation/reference/management/services/contentservice

    If it's a database CRUD you can use thisblogposts a a starting point : https://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/

    Dave

  • Nazir 1 post 71 karma points
    Aug 10, 2018 @ 03:39
    Nazir
    0

    Import -> Umbraco.Web.Mvc or use Umbraco.Web.Mvc.SurfaceController

        private DemoDbEntities db = new DemoDbEntities();
    
        // GET: Products
        public ActionResult Index()
        {
            return View(db.Products.ToList());
        }
    
        // GET: Products/Details/5
        public ActionResult Details(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Product product = db.Products.Find(id);
            if (product == null)
            {
                return HttpNotFound();
            }
            return View(product);
        }
    
        // GET: Products/Create
        public ActionResult Create()
        {
            return View();
        }
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ProductID,Name,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                product.ProductID = Guid.NewGuid();
                db.Products.Add(product);
                db.SaveChanges();
                return Redirect("~/Umbraco/Surface/Products/Index");
                //return RedirectToAction("Index");
            }
    
            return View(product);
        }
    
        // GET: Products/Edit/5
        public ActionResult Edit(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Product product = db.Products.Find(id);
            if (product == null)
            {
                return HttpNotFound();
            }
            return View(product);
        }
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "ProductID,Name,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return Redirect("~/Umbraco/Surface/Products/Index");
                //return RedirectToAction("Index");
            }
            return View(product);
        }
    
        // GET: Products/Delete/5
        public ActionResult Delete(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Product product = db.Products.Find(id);
            if (product == null)
            {
                return HttpNotFound();
            }
            return View(product);
        }
        // POST: Products/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(Guid id)
        {
            Product product = db.Products.Find(id);
            db.Products.Remove(product);
            db.SaveChanges();
            return Redirect("~/Umbraco/Surface/Products/Index");
            //return RedirectToAction("Index");
        }
    
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    
    }
    

    }

    Hope it helps.

  • Tim 66 posts 89 karma points
    Mar 04, 2023 @ 09:46
    Tim
    0

    Hi

    Would you be able to show what the view would look like please. I’m especially interested in how you call each action from the front end. Thanks

Please Sign in or register to post replies

Write your reply to:

Draft