Installed preview 6, then reinstalled preview 5

10 posts, 2 answers
  1. Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 19 Jun Link to this post

    preview 6 breaks things pretty badly with Telerik components.  So I uninstalled it and reinstalled preview 5, but now I am getting errors:

    SeverityCodeDescriptionProjectFileLineSuppression State
    ErrorThe type of component 'TelerikDropDownList' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'TItem', 'TValue'.ScheduledFeatureEditorC:\Code\ScheduledFeatureEditor\ScheduledFeatureEditor\Pages\ScheduledFeatures.razor145

    Which is referring to this line of code:

                                    <TelerikDropDownList Data="@ApplicationFeatureNames" TextField="Text" ValueField="Value" bind-Value="@applicationFeatureId">

     

    So everywhere I have a line similar to this, I get the same error.

    Also getting this error :

     

    SeverityCodeDescriptionProjectFileLineSuppression State
    ErrorThe type of component 'TelerikNumericTextBox' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'T'.ScheduledFeatureEditorC:\Code\ScheduledFeatureEditor\ScheduledFeatureEditor\Pages\ScheduledFeatures.razor191

    This is on lines like this:

                                                    <TelerikNumericTextBox bind-Value=@ScheduledFeatureToEdit.CustomInterval></TelerikNumericTextBox>

     

    Any ideas on how to get back to my working version of the project with preview 5?

     

    Thanks,

    Kenny

     

  2. Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 19 Jun in reply to Kenny Link to this post

    Seems to be related to the Telerik tab component with a "@ref="  If I take that out the rest of the app works.

    This is the Tab code I was testing with:

        <TelerikTabStrip TabPosition="Telerik.Blazor.Components.TabStrip.TabPosition.Top" @ref="myTabStrip">
            <TelerikTab Title="Sofia">
            </TelerikTab>
            <TelerikTab Title="London">
            </TelerikTab>
            <TelerikTab Title="Paris">
            </TelerikTab>
        </TelerikTabStrip>

    And here is how I was defining the ref variable:

        Telerik.Blazor.Components.TabStrip.TelerikTabStrip myTabStrip;

    Like I said, if I remove the tab component it all works ok.

    I attached the razor file so you can see things in context.

  3. Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 19 Jun in reply to Kenny Link to this post

    It wont let me attach the file as it is not an image, so I will paste the code here:

     

    @page "/scheduledfeatures"

    @using System.ComponentModel.DataAnnotations
    @using Newtonsoft.Json
    @using ScheduledFeatureEditor.Exceptions
    @using Telerik.Blazor.Components.Grid
    @using Telerik.Blazor.Components.Window
    @using Telerik.Blazor.Components.DatePicker
    @using Telerik.Blazor.Components.DateInput
    @using Telerik.Blazor.Components.DropDownList
    @using Telerik.Blazor.Components.Button
    @using Telerik.Blazor.Components.NumericTextBox
    @using Telerik.Blazor.Components.TabStrip

    @inject IHttpClientFactory ClientFactory
    @inject IUserContext UserContext


    <div class="container">
        <TelerikTabStrip TabPosition="Telerik.Blazor.Components.TabStrip.TabPosition.Top" @ref="myTabStrip">
            <TelerikTab Title="Sofia">
            </TelerikTab>
            <TelerikTab Title="London">
            </TelerikTab>
            <TelerikTab Title="Paris">
            </TelerikTab>
        </TelerikTabStrip>
        <TelerikGrid Data=@GridData Height="100%" EditMode="incell" Pageable="false">
            <TelerikGridToolBar>
                <TelerikButton Icon="add" OnClick="@CustomAdd">Add Scheduled Feature</TelerikButton>
            </TelerikGridToolBar>
            <TelerikGridColumns>
                <TelerikGridColumn Field=@nameof(ScheduledFeatureViewDto.ApplicationFeatureId) Title="Feature">
                    <Template Context="currentScheduledFeature">
                        @(GetApplicationFeatureNameText(currentScheduledFeature as ScheduledFeatureViewDto))
                    </Template>
                    <EditorTemplate>
                        @{
                            ScheduledFeatureToEdit = context as ScheduledFeatureViewDto;
                            <select onchange="@SetApplicationFeatureIdFromString">
                                @foreach (PickListItemDto item in ApplicationFeatureNames)
                                {
                                    if (item.Value.Equals(ScheduledFeatureToEdit.ApplicationFeatureId.ToString()))
                                    {
                                        <option value=@item.Value selected="selected">@item.Text</option>
                                    }
                                    else
                                    {
                                        <option value=@item.Value>@item.Text</option>
                                    }
                                }
                            </select>
                        }
                    </EditorTemplate>
                </TelerikGridColumn>
                <TelerikGridColumn Field=@nameof(ScheduledFeatureViewDto.HostNameId) Title="Host Name">
                    <Template Context="currentScheduledFeature">
                        @(GetHostNameText(currentScheduledFeature as ScheduledFeatureViewDto))
                    </Template>
                    <EditorTemplate>
                        @{
                            ScheduledFeatureToEdit = context as ScheduledFeatureViewDto;
                            <select onchange="@SetHostNameIdFromString">
                                @foreach (PickListItemDto item in HostNames)
                                {
                                    if (item.Value.Equals(ScheduledFeatureToEdit.HostNameId.ToString()))
                                    {
                                        <option value=@item.Value selected="selected">@item.Text</option>
                                    }
                                    else
                                    {
                                        <option value=@item.Value>@item.Text</option>
                                    }
                                }
                            </select>
                        }
                    </EditorTemplate>
                </TelerikGridColumn>
                <TelerikGridColumn Field=@nameof(ScheduledFeatureViewDto.FrequencyId) Title="Frequency">
                    <Template Context="currentScheduledFeature">
                        @(GetFrequencyNameText(currentScheduledFeature as ScheduledFeatureViewDto))
                    </Template>
                    <EditorTemplate>
                        @{
                            ScheduledFeatureToEdit = context as ScheduledFeatureViewDto;
                            <select onchange="@SetFrequencyIdFromString">
                                @foreach (PickListItemDto item in UserContext.PickLists.Frequencies)
                                {
                                    if (item.Value.Equals(ScheduledFeatureToEdit.FrequencyId.ToString()))
                                    {
                                        <option value=@item.Value selected="selected">@item.Text</option>
                                    }
                                    else
                                    {
                                        <option value=@item.Value>@item.Text</option>
                                    }
                                }
                            </select>
                        }
                    </EditorTemplate>
                </TelerikGridColumn>
                <TelerikGridColumn Field=@nameof(ScheduledFeatureViewDto.Active) Title="Active">
                    <Template>
                        @((context as ScheduledFeatureViewDto).Active ? "Active" : "Inactive")
                    </Template>
                </TelerikGridColumn>
                <TelerikGridCommandColumn>
                    <TelerikGridCommandButton Command="CustomEdit" Icon="edit" ShowInEdit="false" OnClick="@CustomEdit">Edit</TelerikGridCommandButton>
                    <TelerikGridCommandButton Command="Delete" Icon="delete">Delete</TelerikGridCommandButton>
                    <TelerikGridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</TelerikGridCommandButton>
                    <TelerikGridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</TelerikGridCommandButton>
                </TelerikGridCommandColumn>
            </TelerikGridColumns>
            <TelerikGridEvents>
                <EventsManager OnUpdate=@UpdateItem OnDelete=@DeleteItem OnCreate=@CreateItem></EventsManager>
            </TelerikGridEvents>
        </TelerikGrid>

        <TelerikWindow Width="500" Height="300" Centered="true" Visible=@ErrorWindowVisible Modal="true">
            <TelerikWindowTitle>
                <strong>Connection Error</strong>
            </TelerikWindowTitle>
            <TelerikWindowActions>
                <TelerikWindowAction Name="Close" />
            </TelerikWindowActions>
            <TelerikWindowContent>
                <p>Cannot connect to API service.</p>
                <p>Click the close button to dismiss this modal dialog.</p>
            </TelerikWindowContent>
        </TelerikWindow>

        <TelerikWindow Width="1100px" Height="840px" Centered="true" Visible=@EditWindowVisible Modal="true">
            <TelerikWindowContent>
                <EditForm Model="@ScheduledFeatureToEdit">
                    <DataAnnotationsValidator />
                    <div class="card" id="profile">
                        <div class="col-md-12">
                            <h3 class="card-header">Scheduled Feature</h3>
                            <div class="card-body">
                                <div class="form-group">
                                    <label>Application Feature</label><br />
                                    <TelerikDropDownList Data="@ApplicationFeatureNames" TextField="Text" ValueField="Value" bind-Value="@applicationFeatureId">
                                    </TelerikDropDownList>
                                </div>
                                <div class="form-group">
                                    <label class="form-check-label h6">
                                        <InputCheckbox bind-Value="@ScheduledFeatureToEdit.Active" /> Is Active
                                    </label>
                                </div>
                                <div class="form-group">
                                    <label>Host Name</label><br />
                                    <TelerikDropDownList Data="@HostNames" TextField="Text" ValueField="Value" bind-Value="@hostNameId">
                                    </TelerikDropDownList>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card" id="profile">
                        <div class="col-md-12">
                            <h3 class="card-header">Schedule</h3>
                            <div class="card-body">
                                <div class="form-group">
                                    <label>Start Date/Time</label><br />
                                    <TelerikDateInput bind-Value="@ScheduledFeatureToEdit.StartDate" Format="MM/dd/yyyy HH:mm" Min="@MinDate" Max="@MaxDate"></TelerikDateInput>
                                </div>
                                <div class="row">
                                    <div class="col">
                                        <div class="form-group">
                                            <label>Will this schedule repeat?</label><br />
                                            <TelerikDropDownList Data="@UserContext.PickLists.Frequencies" TextField="Text" ValueField="Value" bind-Value="@frequencyId">
                                            </TelerikDropDownList>
                                        </div>
                                    </div>
                                    @if (ScheduledFeatureToEdit.FrequencyId == FrequencyIds.CustomSchedule)
                                    {
                                        <div class="col">
                                            <div class="form-group">
                                                <label>Frequency</label><br />
                                                <TelerikDropDownList Data="@UserContext.PickLists.CustomFrequencies" TextField="Text" ValueField="Value" bind-Value="@customFrequencyId">
                                                </TelerikDropDownList>
                                            </div>
                                        </div>
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Hourly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>Every</label><br />
                                                    <TelerikNumericTextBox bind-Value=@ScheduledFeatureToEdit.CustomInterval></TelerikNumericTextBox>
                                                    <label>Hours</label>
                                                </div>
                                            </div>
                                        }
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Daily)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>Every</label><br />
                                                    <TelerikNumericTextBox bind-Value=@ScheduledFeatureToEdit.CustomInterval></TelerikNumericTextBox>
                                                    <label>Days</label>
                                                </div>
                                            </div>
                                        }
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Weekly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>Every</label><br />
                                                    <TelerikNumericTextBox bind-Value=@ScheduledFeatureToEdit.CustomInterval></TelerikNumericTextBox>
                                                    <label>Weeks</label>
                                                </div>
                                            </div>
                                        }
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Monthly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>Every</label><br />
                                                    <TelerikNumericTextBox bind-Value=@ScheduledFeatureToEdit.CustomInterval></TelerikNumericTextBox>
                                                    <label>Months</label>
                                                </div>
                                            </div>
                                        }
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Yearly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>Every</label><br />
                                                    <TelerikNumericTextBox bind-Value=@ScheduledFeatureToEdit.CustomInterval></TelerikNumericTextBox>
                                                    <label>Years</label>
                                                </div>
                                            </div>
                                        }
                                    }
                                </div>
                                @if (ScheduledFeatureToEdit.FrequencyId == FrequencyIds.CustomSchedule)
                                {
                                    <div class="row">
                                        <div class="col">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Weekly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>On...</label><br />
                                                    <TelerikDropDownList Data="@UserContext.PickLists.CustomDayOfWeek" TextField="Text" ValueField="Value" bind-Value="@customDayOfWeek">
                                                    </TelerikDropDownList>
                                                </div>
                                            </div>
                                        }
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Monthly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>On The...</label><br />
                                                    <TelerikDropDownList Data="@UserContext.PickLists.CustomWeekOfMonth" TextField="Text" ValueField="Value" bind-Value="@customWeekOfMonth">
                                                    </TelerikDropDownList>
                                                </div>
                                            </div>
                                        }
                                        @if (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Yearly)
                                        {
                                            <div class="col">
                                                <div class="form-group">
                                                    <label>On The...</label><br />
                                                    <TelerikDropDownList Data="@UserContext.PickLists.CustomWeekOfMonth" TextField="Text" ValueField="Value" bind-Value="@customWeekOfMonth">
                                                    </TelerikDropDownList>
                                                </div>
                                            </div>
                                        }
                                    </div>
                                }
                                @if (ScheduledFeatureToEdit.FrequencyId == FrequencyIds.CustomSchedule &&
                                    (ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Monthly ||
                                     ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Yearly))
                                {
                                    <div class="row">
                                        <div class="col">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="form-group">
                                                <TelerikDropDownList Data="@UserContext.PickLists.CustomDayOfWeek" TextField="Text" ValueField="Value" bind-Value="@customDayOfWeek">
                                                </TelerikDropDownList>
                                            </div>
                                        </div>
                                    </div>
                                }
                                @if (ScheduledFeatureToEdit.FrequencyId == FrequencyIds.CustomSchedule &&
                                     ScheduledFeatureToEdit.CustomFrequencyId == CustomFrequencyIds.Yearly)
                                {
                                    <div class="row">
                                        <div class="col">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="form-group">
                                            </div>
                                        </div>
                                        <div class="col">
                                            <div class="form-group">
                                                <label>Of...</label><br />
                                                <TelerikDropDownList Data="@UserContext.PickLists.CustomMonthOfYear" TextField="Text" ValueField="Value" bind-Value="@customMonthOfYear">
                                                </TelerikDropDownList>
                                            </div>
                                        </div>
                                    </div>
                                }
                                @if (ScheduledFeatureToEdit.FrequencyId != FrequencyIds.OnlyOnce)
                                {
                                    <div class="form-group">
                                        <label class="form-check-label h6">
                                            <InputCheckbox bind-Value="@ScheduledFeatureToEdit.HasEndDate" /> Does this schedule have an end date?
                                        </label>
                                    </div>
                                    @if (ScheduledFeatureToEdit.HasEndDate)
                                    {
                                        <div class="form-group">
                                            <label>End Date</label><br />
                                            <TelerikDatePicker bind-Value="@ScheduledFeatureToEdit.EndDate"></TelerikDatePicker>
                                        </div>
                                    }
                                }
                                <div class="row">
                                    <div class="form-group">
                                        <TelerikButton Primary="true" OnClick="@HandleValidSubmitOnEdit">Save Changes</TelerikButton>
                                        <TelerikButton OnClick="@CancelEdit">Cancel</TelerikButton>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </EditForm>
            </TelerikWindowContent>
        </TelerikWindow>
    </div>


    @functions {
        protected List<ScheduledFeatureViewDto> GridData = new List<ScheduledFeatureViewDto>();
        protected ScheduledFeatureViewDto ScheduledFeatureToEdit { get; set; }
        protected List<PickListItemDto> ApplicationFeatureNames { get; set; }
        protected List<PickListItemDto> HostNames { get; set; }
        Telerik.Blazor.Components.TabStrip.TelerikTabStrip myTabStrip;

        protected bool ErrorWindowVisible = false;
        protected bool EditWindowVisible = false;

        protected bool AddingNewRecord = false;

        protected string applicationFeatureId
        {
            get { return ScheduledFeatureToEdit.ApplicationFeatureId.ToString(); }
            set { ScheduledFeatureToEdit.ApplicationFeatureId = new Guid(value); }
        }

        protected string frequencyId
        {
            get { return ScheduledFeatureToEdit.FrequencyId.ToString(); }
            set { ScheduledFeatureToEdit.FrequencyId = new Guid(value); }
        }

        protected string customFrequencyId
        {
            get { return ScheduledFeatureToEdit.CustomFrequencyId.ToString(); }
            set { ScheduledFeatureToEdit.CustomFrequencyId = new Guid(value); }
        }

        protected string customDayOfWeek
        {
            get { return ScheduledFeatureToEdit.CustomDayOfWeekId.ToString(); }
            set { ScheduledFeatureToEdit.CustomDayOfWeekId = new Guid(value); }
        }

        protected string customWeekOfMonth
        {
            get { return ScheduledFeatureToEdit.CustomWeekOfMonthId.ToString(); }
            set { ScheduledFeatureToEdit.CustomWeekOfMonthId = new Guid(value); }
        }

        protected string customMonthOfYear
        {
            get { return ScheduledFeatureToEdit.CustomMonthOfYearId.ToString(); }
            set { ScheduledFeatureToEdit.CustomMonthOfYearId = new Guid(value); }
        }

        protected string hostNameId
        {
            get { return ScheduledFeatureToEdit.HostNameId.ToString(); }
            set { ScheduledFeatureToEdit.HostNameId = new Guid(value); }
        }

        public DateTime MaxDate = DateTime.Now.AddYears(10);
        public DateTime MinDate = DateTime.Now;

        protected override async Task OnInitAsync()
        {
            await GetScheduledFeatures();
            await GetApplicationFeatureNames();
            await GetHostNames();
        }

        private async Task GetScheduledFeatures()
        {
            try
            {
                var httpClient = ClientFactory.CreateClient("api");
                GridData = await httpClient.GetJsonAsync<List<ScheduledFeatureViewDto>>("ScheduledFeatures");
            }
            catch (Exception inner)
            {
                ErrorWindowVisible = true;
                StateHasChanged();
                var e = new ConnectionToApiException("Can't connect to ScheduledServices API", inner);
                Log.Error("Can't connect to ScheduledServices API: ", e);
            }

            foreach (ScheduledFeatureViewDto appFeature in GridData)
            {
                appFeature.Active = appFeature.StatusId == MdmStatusCodes.StatusActive;
                appFeature.StartDate = appFeature.StartDate.ToLocalTime();
                appFeature.EndDate = appFeature.EndDate.ToLocalTime();
            }
        }

        private string GetApplicationFeatureNameText(ScheduledFeatureViewDto currentScheduledFeature)
        {
            PickListItemDto currentScheduledNameItem = ApplicationFeatureNames.FirstOrDefault(x => x.Id == currentScheduledFeature.ApplicationFeatureId);
            if (currentScheduledNameItem != null)
            {
                return currentScheduledNameItem.Text;
            }
            return "unknown";
        }

        void SetApplicationFeatureIdFromString(UIChangeEventArgs e)
        {
            string selectedString = e.Value.ToString();
            Guid actualGuid = new Guid(selectedString);
            ScheduledFeatureToEdit.ApplicationFeatureId = actualGuid;
        }

        private async Task GetApplicationFeatureNames()
        {
            try
            {
                var httpClient = ClientFactory.CreateClient("api");
                ApplicationFeatureNames = await httpClient.GetJsonAsync<List<PickListItemDto>>("picklists/applicationfeatures");
            }
            catch (Exception inner)
            {
                ErrorWindowVisible = true;
                StateHasChanged();
                var e = new ConnectionToApiException("Can't connect to ScheduledServices API", inner);
                Log.Error("Can't connect to ScheduledServices API: ", e);
            }

            foreach (var name in ApplicationFeatureNames)
            {
                name.Value = name.Id.ToString();
            }
        }

        private async Task GetHostNames()
        {
            try
            {
                var httpClient = ClientFactory.CreateClient("api");
                HostNames = await httpClient.GetJsonAsync<List<PickListItemDto>>("picklists/hostnames");
            }
            catch (Exception inner)
            {
                ErrorWindowVisible = true;
                StateHasChanged();
                var e = new ConnectionToApiException("Can't connect to ScheduledServices API", inner);
                Log.Error("Can't connect to ScheduledServices API: ", e);
            }

            foreach (var name in HostNames)
            {
                name.Value = name.Id.ToString();
            }
        }

        private string GetHostNameText(ScheduledFeatureViewDto currentScheduledFeature)
        {
            PickListItemDto currentHostNameItem = HostNames.FirstOrDefault(x => x.Id == currentScheduledFeature.HostNameId);
            if (currentHostNameItem != null)
            {
                return currentHostNameItem.Text;
            }
            return "unknown";
        }

        void SetHostNameIdFromString(UIChangeEventArgs e)
        {
            string selectedString = e.Value.ToString();
            Guid actualGuid = new Guid(selectedString);
            ScheduledFeatureToEdit.HostNameId = actualGuid;
        }


        private string GetFrequencyNameText(ScheduledFeatureViewDto currentScheduledFeature)
        {
            PickListItemDto currentFrequencyNameItem = UserContext.PickLists.Frequencies.FirstOrDefault(x => x.Id == currentScheduledFeature.FrequencyId);
            if (currentFrequencyNameItem != null)
            {
                return currentFrequencyNameItem.Text;
            }
            return "unknown";
        }

        void SetFrequencyIdFromString(UIChangeEventArgs e)
        {
            string selectedString = e.Value.ToString();
            Guid actualGuid = new Guid(selectedString);
            ScheduledFeatureToEdit.FrequencyId = actualGuid;
        }

        private void CustomEdit(GridCommandEventArgs args)
        {
            ScheduledFeatureToEdit = args.Item as ScheduledFeatureViewDto;
            if (ScheduledFeatureToEdit.StartDate == DateTime.MinValue)
            {
                ScheduledFeatureToEdit.StartDate = DateTime.Now;
            }

            ScheduledFeatureToEdit.HasEndDate = (ScheduledFeatureToEdit.EndDate != DateTime.MinValue);

            AddingNewRecord = false;

            MinDate = new DateTime(Math.Min(DateTime.Now.Ticks, ScheduledFeatureToEdit.StartDate.Ticks));
            MaxDate = DateTime.Now.AddYears(10);

            EditWindowVisible = true;
            StateHasChanged();
        }

        private void CustomAdd()
        {
            ScheduledFeatureToEdit = new ScheduledFeatureViewDto
            {
                StartDate = DateTime.Now,
                HasEndDate = false,
                EndDate = DateTime.MinValue,
                FrequencyId = FrequencyIds.Hourly,
                StatusId = MdmStatusCodes.StatusActive,
                Active =  true,
                CustomInterval = 1
            };

            AddingNewRecord = true;

            MinDate = DateTime.Now;
            MaxDate = DateTime.Now.AddYears(10);

            EditWindowVisible = true;
            StateHasChanged();
        }

        async Task EnsureGridSourceUpdates()
        {
            var tmp = this.GridData;
            this.GridData = null;
            this.StateHasChanged();
            await Task.Delay(10);
            this.GridData = tmp;
            this.StateHasChanged();

        }

        async Task HandleValidSubmitOnEdit()
        {
            var evt = new GridCommandEventArgs(ScheduledFeatureToEdit);

            if (!ScheduledFeatureToEdit.HasEndDate)
            {
                ScheduledFeatureToEdit.EndDate = DateTime.MinValue;
            }

            EditWindowVisible = false;
            StateHasChanged();

            if (AddingNewRecord)
            {
                CreateItem(evt);
                await this.EnsureGridSourceUpdates();
            }
            else
            {
                UpdateItem(evt);
            }
        }

        private void CancelEdit()
        {
            EditWindowVisible = false;
            StateHasChanged();
        }

        private DateTime? FixMinDate(DateTime? date)
        {
            if (date != null)
            {
                if (date != DateTime.MinValue)
                {
                    return ((DateTime)date).ToUniversalTime();
                }
            }
            return null;
        }

        private Guid? FixEmptyGuid(Guid? guid)
        {
            if (guid != null)
            {
                if (!guid.Equals(Guid.Empty))
                {
                    return guid;
                }
            }
            return null;
        }

        private void CreateItem(GridCommandEventArgs args)
        {
            if (args.Item is ScheduledFeatureViewDto itemToAdd)
            {
                var itemForPost = Mapper.Map<ScheduledFeatureForCreationDto>(itemToAdd);
                itemForPost.UserName = UserContext.UserName;
                itemForPost.GroupName = UserContext.GroupName;
                itemForPost.StatusId = itemToAdd.Active ? MdmStatusCodes.StatusActive : MdmStatusCodes.StatusInactive;

                itemForPost.StartDate = FixMinDate(itemForPost.StartDate);
                itemForPost.EndDate = FixMinDate(itemForPost.EndDate);
                itemForPost.LastRan = FixMinDate(itemForPost.LastRan);

                itemForPost.CustomFrequencyId = FixEmptyGuid(itemForPost.CustomFrequencyId);
                itemForPost.CustomMonthOfYearId = FixEmptyGuid(itemForPost.CustomMonthOfYearId);
                itemForPost.CustomWeekOfMonthId = FixEmptyGuid(itemForPost.CustomWeekOfMonthId);
                itemForPost.CustomDayOfWeekId = FixEmptyGuid(itemForPost.CustomDayOfWeekId);
                itemForPost.HostNameId = FixEmptyGuid(itemForPost.HostNameId);

                if (itemForPost.ApplicationFeatureId.Equals(Guid.Empty))
                {
                    itemForPost.ApplicationFeatureId = ApplicationFeatureNames[0].Id;
                }

                var jsonItem = JsonConvert.SerializeObject(itemForPost);

                HttpResponseMessage response = null;
                try
                {
                    var httpClient = ClientFactory.CreateClient("api");
                    response = httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, "ScheduledFeatures")
                    {
                        Content = new StringContent(jsonItem, Encoding.UTF8, "application/json")
                    }).Result;
                }
                catch (Exception inner)
                {
                    ErrorWindowVisible = true;
                    StateHasChanged();
                    var e = new ConnectionToApiException("Can't connect to ScheduledServices API", inner);
                    Log.Error("Can't connect to ScheduledServices API: ", e);
                }

                if (response != null && response.StatusCode == HttpStatusCode.Created)
                {
                    var responseJson = response.Content.ReadAsStringAsync().Result;
                    var postResults = JObject.Parse(responseJson);
                    var idToken = postResults["id"];

                    itemToAdd = Mapper.Map<ScheduledFeatureViewDto>(itemForPost);
                    itemToAdd.Id = new Guid(idToken.ToString());
                    itemToAdd.Active = itemToAdd.StatusId == MdmStatusCodes.StatusActive;

                    GridData.Add(itemToAdd);
                }
            }
        }

        private void DeleteItem(GridCommandEventArgs args)
        {
            if (args.Item is ScheduledFeatureViewDto itemToDelete)
            {
                var userName = new UserNameDto() { UserName = UserContext.UserName };
                var jsonUserName = Json.Serialize(userName);

                HttpResponseMessage response = null;
                try
                {
                    var httpClient = ClientFactory.CreateClient("api");
                    response = httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Delete, $"ScheduledFeatures/{itemToDelete.Id}")
                    {
                        Content = new StringContent(jsonUserName, Encoding.UTF8, "application/json")
                    }).Result;
                }
                catch (Exception inner)
                {
                    ErrorWindowVisible = true;
                    StateHasChanged();
                    var e = new ConnectionToApiException("Can't connect to ScheduledServices API", inner);
                    Log.Error("Can't connect to ScheduledServices API: ", e);
                }

                if (response != null && response.StatusCode == HttpStatusCode.NoContent)
                {
                    GridData.Remove(itemToDelete);
                }
            }
        }

        private void UpdateItem(GridCommandEventArgs args)
        {
            var itemToUpdate = args.Item as ScheduledFeatureViewDto;
            string stringId = itemToUpdate.Id.ToString();
            var item = GridData.FirstOrDefault(c => c.Id == itemToUpdate.Id);

            itemToUpdate.CustomFrequencyId = FixEmptyGuid(itemToUpdate.CustomFrequencyId);
            itemToUpdate.CustomMonthOfYearId = FixEmptyGuid(itemToUpdate.CustomMonthOfYearId);
            itemToUpdate.CustomWeekOfMonthId = FixEmptyGuid(itemToUpdate.CustomWeekOfMonthId);
            itemToUpdate.CustomDayOfWeekId = FixEmptyGuid(itemToUpdate.CustomDayOfWeekId);
            itemToUpdate.HostNameId = FixEmptyGuid(itemToUpdate.HostNameId);

            if (item != null)
            {
                itemToUpdate.StatusId = itemToUpdate.Active ? MdmStatusCodes.StatusActive : MdmStatusCodes.StatusInactive;

                var scheduledFeatureForPut = Mapper.Map<ScheduledFeatureForUpdateDto>(itemToUpdate);
                scheduledFeatureForPut.StartDate = FixMinDate(itemToUpdate.StartDate);
                scheduledFeatureForPut.EndDate = FixMinDate(itemToUpdate.EndDate);

                var httpClient = ClientFactory.CreateClient("api");
                var jsonItem = JsonConvert.SerializeObject(scheduledFeatureForPut);
                try
                {
                    var response = httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Put, $"ScheduledFeatures/{itemToUpdate.Id}")
                    {
                        Content = new StringContent(jsonItem, Encoding.UTF8, "application/json")
                    }).Result;

                    if (response.StatusCode == HttpStatusCode.NoContent)
                    {
                        Mapper.Map<ScheduledFeatureViewDto, ScheduledFeatureViewDto>(itemToUpdate, item);
                    }
                }
                catch (Exception inner)
                {
                    ErrorWindowVisible = true;
                    StateHasChanged();
                    var e = new ConnectionToApiException("Can't connect to ScheduledServices API", inner);
                    Log.Error("Can't connect to ScheduledServices API: ", e);
                }
            }
        }

        public void UpdateStatus(UIChangeEventArgs args)
        {
            var a = args;
        }
    }

  4. Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 19 Jun in reply to Kenny Link to this post

    I tried the bind-Value instead of ref as well, like this:

       <TelerikTabStrip TabPosition="Telerik.Blazor.Components.TabStrip.TabPosition.Top" bind-Value="@myTabStrip">

  5. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    4931 posts

    Posted 20 Jun Link to this post

    Hello Kenny,

    What is currently valid for Blazor is .NET Core 3 Preview 6, and you should upgrade to it, and you should also upgrade the Telerik UI for Blazor to 1.2.0, which brings compatibility with Preview 6. There are some breaking changes in the framework, most notably @functions is now @code and the way attributes are used on elements. You can find examples of this migration in the following commits from our docs, for example, and, of course, from the official blog post

    You need to apply those changes to your application code as well.

    What I see in the provided code is a mix and match between the syntax for Preview 5 and the syntax for Preview 6, and you must migrate all of it to the current standards (Preview 6).

    With that said, I tested the @ref="variable" approach for refrencing a tab strip from the first snippet of its docs (https://docs.telerik.com/blazor-ui/components/tabstrip/overview) and it seemed to work fine for me. Could you try performing the migration to Preview 6 and let me know how it goes? It does not require any changes to the Telerik-related code, only standard Blazor syntax changes are needed, and they can be done with a relatively simple find+replace.


    Regards,
    Marin Bratanov
    Progress Telerik UI for Blazor
  6. Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 21 Jun in reply to Marin Bratanov Link to this post

    That worked!  I didn't notice the 1.2.0 release, thanks for pointing that out.

    I had about 70 errors that were mostly the syntax change on bind-Value and the event syntax change.

    Everything seems to be working now.

  7. Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 21 Jun Link to this post

    I don't think this is Telerik specific issue, but my razor page code has tons of errors marked on it.  It compiles and runs just fine.

     

    For example the following line give the error "cannot resolve symbol 'code'"

    @code {

     

    This line give me the error "Tag 'ScheduledFeatureDto' is not closed"

        protected List<ScheduledFeatureViewDto> GridData = new List<ScheduledFeatureViewDto>();

     

    I'm not sure if something isn't quite right about my environment.  I am running preview 6, the latest preview version of VS2019 and the latest version of the Blazor plugin.

     

    Are you seeing similar results?  Any thoughts?

     

    Thanks,

    Kenny

  8. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4931 posts

    Posted 24 Jun Link to this post

    Hello Kenny,

    I saw such behavior in two cases:

    • Just after I installed Preview 6, but before I restarted the PC (so, a restart may help).
    • When I accidentally opened a Blazor project in VS 2019 RTM, and not in Preview. The double-click on the .sln defaults to the RTM version, so it's a very easy omission.

    If neither is the case, I'd suggest re-installing or at least repairing the VS 2019 Preview installation.

    If anyone else has seen similar issues, please chime in.


    Regards,
    Marin Bratanov
    Progress Telerik UI for Blazor
  9. Answer
    Kenny
    Kenny avatar
    24 posts
    Member since:
    Jan 2015

    Posted 08 Jul in reply to Marin Bratanov Link to this post

    The problem is ReSharper!  I disabled it and everything is fine.  I downloaded the EAP version and it is much better, but they are still having some issues parsing the razor page format.
  10. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4931 posts

    Posted 08 Jul Link to this post

    Thank you for sharing this with the community, Kenny. I marked your last post as an answer to this thread as well.

    --Marin

Back to Top