Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 590 posts 805 karma points
    Jun 03, 2015 @ 16:06
    Fredrik Esseen
    0

    Working with custom database tables in Umbraco 7

    Hi all!

    Its been a while since I made some more advance stuff in Umbraco, I mostly create simple pages but now Im back to making a new application for handling bookings.

    Im not so familiar yet with the mvc way of connecting to custom tables in Umbraco 7 but I found this article:

    http://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/

    Is that "the way to go"? Im saving data from a form to a custom created table and I need to create, edit and delete as always.

    Any other hints on best practice?

     

  • Alex Skrypnyk 5367 posts 19805 karma points MVP 3x admin c-trib
    Jun 03, 2015 @ 17:02
    Alex Skrypnyk
    100

    Hi Froad,

    Yes, this article is the right way to start using custom data tables in Umbraco projects. Also it would be great to read about WepApi controllers, they are convenient for CRUD operations.

    https://our.umbraco.org/documentation/Reference/WebApi/

    Thanks, Alex

  • Fredrik Esseen 590 posts 805 karma points
    Jun 04, 2015 @ 15:24
    Fredrik Esseen
    0

    A follow up questions to the above:

    Ive managed to create a form and saving the result to a custom table using SurfaceController and so on.

    But Im not really sure how to solve one thing:

    I have a model with something like this:

     public class BookingFormViewModel
        {
            public int CampId { get; set; }
            [Required]
            public string Name { get; set; }
            [Required]
            public string Address { get; set; }
            [Required]
            public string Postal { get; set; }
            [Required]
            public string City { get; set; }

     And a view loing like this:

    @model UmbracoDemo3.Models.BookingFormViewModel
    
    
    @using (Html.BeginUmbracoForm<UmbracoDemo3.Controllers.BookingsSurfaceController>("HandleFormSubmit"))
    <div class="row"> @Html.TextBoxFor(m => m.Name, new {placeholder = "Name" }) @Html.ValidationMessageFor(m => m.Name)
    @Html.TextBoxFor(m => m.Address, new { @class = "col-md-6", placeholder = "Adress" }) @Html.ValidationMessageFor(m => m.Address) @Html.TextBoxFor(m => m.Postal, new { @class = "col-md-6", placeholder = "Postnr" }) @Html.ValidationMessageFor(m => m.Postal) @Html.TextBoxFor(m => m.City, new { @class = "col-md-6", placeholder = "Postort" }) @Html.ValidationMessageFor(m => m.City)
     </div>

    But now I also want to list all available "camps" that is sub nodes to the current node and let the user select one camp. I want to make a table with a radiobutton so that I can display info about each camp. The problem is that i dont know how to send the selected radiobutton to my surfaceController..? I would like to populate the models CampId with the selected camp.

       var currentNode = UmbracoContext.Current.PublishedContentRequest.PublishedContent;

    <table> <thead> <tr> <th></th> <th>Start date</th> <th>End date</th> <th>Name</th> <th>Information</th> <th>Price</th> </tr> </thead> <tbody> @foreach (var child in currentNode.Children) { <tr> <td><input type="radio" name="radiobuttons" value=@child.Id /></td> <td>@child.GetProperty("startdate").Value</td> <td>@child.GetProperty("stopdate").Value</td> <td>@child.Name</td> <td>@child.GetProperty("extra").Value</td> <td>@child.GetProperty("price").Value</td> </tr> } </tbody> </table> 
Please Sign in or register to post replies

Write your reply to:

Draft