Copied to clipboard

Flag this post as spam?

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


  • Moran 285 posts 934 karma points
    Jul 12, 2016 @ 06:52
    Moran
    0

    Updating doc type property using date time

    Hi I got a property called "dateNow" that I am updating using the the current date. After the property is updated I get an error message on a dictionary value that is missing, but is actually there.

    I have two views HomePage.cshtml and ContactForm.cshtml, which is a partial view for the contact form.

    This is the HomePage.cshtml:

    @using Umbraco72.BL;
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    @{
        var root = Model.Content.AncestorOrSelf(1);
    
        var slideId = Model.Content.GetPropertyValue<string>("pageImage");
        var toDayField = Model.Content.GetPropertyValue<string>("dateNow");
        var flyWithUsCount = Model.Content.GetPropertyValue<string>("flyWithUs");
    
        var employees = Model.Content.GetPropertyValue<ArchetypeModel>("employeesList").ToArray();
    
    
        var contactPageId = root.Descendant("ContactPage").Id;
        Services.UpdateCounter(contactPageId);
    }
    
    
    <div class="b-slidercontainer">
        <div class="b-slider j-fullscreenslider">
            <ul>
                <li data-transition="3dcurtain-vertical" data-slotamount="7">
                    <div class="tp-bannertimer"></div>
                    @if (!string.IsNullOrEmpty(slideId))
                    {
                        <img src="@Umbraco.Media(slideId).Url"  alt="@Model.Content.GetVortoValue("headerName", Culture, false, Model.Content.Name)"/>
                    }
                </li>
            </ul>
        </div>
    </div>
    
    <section class="b-section-info homeTop">
        <div class="container">
            <div class="row">
                <div class="b-section-info__text f-section-info__text col-sm-6 col-xs-12">
                    <div class="homeContact contact_box">
                        <h2 class="f-primary-b">@Model.Content.GetVortoValue("contactTitle")</h2>
                        <p class="f-section-info__text_short f-primary-sb">
                            @Model.Content.GetVortoValue("contactHeader")
                        </p>
                        @Html.Action("CommonContact", "ContactSurface")
                    </div>
                    <div class="homeContact thank_box">
                        @Html.Raw(Model.Content.GetVortoValue("contactThanks"))
                    </div>
                </div>
                <div class="b-section-info__text f-section-info__text col-sm-6 col-xs-12">
                    <div class="homeInfo">
                        <h2 class="f-primary-b">@Model.Content.GetVortoValue("aboutTitle")</h2>
                        <div class="f-section-info__text_short">
                            @Html.Raw(Model.Content.GetVortoValue("bodyTextWelcome"))
                        </div>
                        <div class="numberOfPass">
                            <span class="number">2169</span>
                            <span class="text1">
                                <span>@Model.Content.GetVortoValue("flyWithUsTitle")</span>
                                @Model.Content.GetVortoValue("flyWithUsSecondTitle")
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="arrow_image">
            <!--arrow image-->
        </div>
    </section>
    

    This is the CommonContactForm.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco72.Models.CommonContactViewModel>
    @using Umbraco72.Controllers
    
    @if (TempData["success"] == null)
    {
        using (Html.BeginUmbracoForm("CommonContactFormSubmit", "ContactSurface"))
        {
            <div class="b-form-group">
            <div class="b-form-row">
                @Html.TextBoxFor(m => m.Name, new {@class="form-control", @placeholder = Umbraco.GetDictionaryValue("Name") })
                @Html.ValidationMessageFor(m => m.Name)
            </div>
            <div class="b-form-row">
                @Html.TextBoxFor(m => m.Phone, new {@class="form-control",  @placeholder = Umbraco.GetDictionaryValue("Phone") })
                @Html.ValidationMessageFor(m => m.Phone)
            </div>
            <div class="b-form-row">
                @Html.TextBoxFor(m => m.Email, new {@class="form-control",  @placeholder = Umbraco.GetDictionaryValue("Email") })
                @Html.ValidationMessageFor(m => m.Email)
            </div>
            <div class="b-form-row">
                <input type="submit" id="submit" value="@Umbraco.GetDictionaryValue("Send")" class="b-btn f-btn b-btn-md b-btn-default f-primary-b b-btn__w100"/>
            </div>
            </div>
        }
    }
    else
    {
        <script src="~/js/jquery/jquery-1.11.1.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $(".contact_box").css("display", "none");
                $(".thank_box").css("display", "block");
            });
        </script>
    }
    

    This is the update time function:

     public static class Services
        {
            public static void UpdateCounter(int pageId)
            {
                DateTime toDay = DateTime.Today;
                var page = ApplicationContext.Current.Services.ContentService.GetById(pageId);
                page.Properties["dateNow"].Value = toDay.ToString("g");
                ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(page);
            }
        }
    

    This is the error message I get link

Please Sign in or register to post replies

Write your reply to:

Draft