Small fixes/updates for NanisuruApp

Fixed a few things on my on-going project NanisuruApp.

Problem#1) To-Do items have the date added and completion date saved in Database as UTC. Stored, retrieved, and displayed as UTC. For a bigger scale app with many users, it is natural to have a user preference saved, and the TimeZone for each specific user kicks in to display the correct time.
I decided to simply hard code this for now, as this is an App used by 2 people…

DateTime adjustedAddedDateTime
{
    get => todoItem.Added.AddHours(9);
    set => todoItem.Added = value;
}

DateTime adjustedCompletedDateTime
{
    get => todoItem.Completed.AddHours(9);
    set => todoItem.Completed = value;
}

Problem#2) When the user adds a link with the To-Do item, if the string is missing http:// or https://, Blazor Uri directs the link to a non-existent location. I thought of messing with the root Uri in the project, but instead I countered this problem by using this code in the razor page.

 @if (!string.IsNullOrEmpty(todoItems.Url))
 {
     @if ((!todoItems.Url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) && (!todoItems.Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
     {
         modifiedUrl = "http://" + todoItems.Url;
     }
     else
     {
         modifiedUrl = todoItems.Url;
     }
     <a class="text-primary-blue" href="@modifiedUrl" target="_blank">
         <i class="fas fa-link me-3 fa-2x" title="URL"></i>
     </a>
 }

//// Code section
string modifiedUrl;

Leave a Reply

Your email address will not be published. Required fields are marked *