Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

CRUD configuration MVC with Firebase

public string TimestampUtc { get; set; }
Comment

CRUD configuration MVC with Firebase

public async Task<ActionResult> About()
{
  //Simulate test user data and login timestamp
  var userId = "12345";
  var currentLoginTime = DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss");

  //Save non identifying data to Firebase
  var currentUserLogin = new LoginData() { TimestampUtc = currentLoginTime };
  var firebaseClient = new FirebaseClient("yourFirebaseProjectUrl");
  var result = await firebaseClient
    .Child("Users/" + userId + "/Logins")
    .PostAsync(currentUserLogin);

  //Retrieve data from Firebase
  var dbLogins = await firebaseClient
    .Child("Users")
    .Child(userId)
    .Child("Logins")
    .OnceAsync<LoginData>();

  var timestampList = new List<DateTime>();

  //Convert JSON data to original datatype
  foreach (var login in dbLogins)
  {
      timestampList.Add(Convert.ToDateTime(login.Object.TimestampUtc).ToLocalTime());
  }

  //Pass data to the view
  ViewBag.CurrentUser = userId;
  ViewBag.Logins = timestampList.OrderByDescending(x => x);
  return View();
}
Comment

CRUD configuration MVC with Firebase

@{
    ViewBag.Title = "About";
}
<h2>@ViewBag.Title</h2>

<h3>Login History</h3>
<p>Current user: @ViewBag.CurrentUser</p>
<ul>
    @foreach(var timestamp in ViewBag.Logins)
    {
        <li>Login at @timestamp</li>
    }
</ul>
Comment

PREVIOUS NEXT
Code Example
Csharp :: Delegates in UntiyC# 
Csharp :: add getenumerator to class c# 
Csharp :: get patht bim 360 revit api 
Csharp :: hacking 
Csharp :: scale curve revit api 
Csharp :: ip validation .net core 
Csharp :: wait for threadpool to complete with decrement 
Csharp :: Avoid auto-filling persian time picker 
Csharp :: c# compare char arrays 
Csharp :: c# webbrowser control append 
Csharp :: Unity Scale per code ändern 
Csharp :: screenshot c# WinForms 
Csharp :: how to save checkbox value in database in c# 
Csharp :: remove tag anchor and inside tag from html raw text c# 
Csharp :: Difference between Math.Floor() and Math.Truncate() 
Csharp :: Reading a date from xlsx using open xml sdk 
Csharp :: how to make infinite loop in c# 
Csharp :: draw table in console c# 
Csharp :: access audio source from gameobject unity 
Csharp :: Insertion sort in c# 
Csharp :: unity3d sort list 
Csharp :: unity public script 
Csharp :: how do i repeat a button on visual studio code 
Csharp :: flsa itextsharp 
Html :: qs cdn 
Html :: open link in new tab 
Html :: how to stop download option in video tag of HTML 
Html :: input type file accept only images 
Html :: html input type file accept text and word files 
Html :: tailwind cdn 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =