Skip to content

Instantly share code, notes, and snippets.

Avatar

John Ojo JIOO-phoeNIX

View GitHub Profile
View Account.cs
using System.ComponentModel.DataAnnotations;
namespace CockroachDbLib.Models
{
public class Account
{
[Key]
public int id { get; set; }
public int balance { get; set; }
View CockroachDbContext.cs
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
namespace CockroachDbLib.Models
{
public class CockroachDbContext : DbContext
{
public CockroachDbContext(DbContextOptions<CockroachDbContext> options) : base(options)
View IAccountRepository.cs
using CockroachDbLib.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace CockroachDbLib.Repository
{
public interface IAccountRepository
{
List<Account> GetAllAccounts();
View AccountRepository.cs
using CockroachDbLib.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CockroachDbLib.Repository
{
public class AccountRepository : IAccountRepository
{
View AccountController.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using CockroachDbLib.Models;
using CockroachDbLib.Repository;
using Microsoft.AspNetCore.Mvc;
namespace BlazorAppWithCockroachDB.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
View Account.cs
namespace BlazorAppWithCockroachDB.Model
{
public class Account
{
public int id { get; set; }
public int balance { get; set; }
public string name { get; set; }
View AccountModel.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace BlazorAppWithCockroachDB.Model
{
public class AccountModel
{
[Required(ErrorMessage = "Balance is required")]
[Range(minimum: 1, 99999999, ErrorMessage = "Minimum allowed balance is $1")]
public int balance { get; set; }
View Accounts.razor
@page "/Accounts"
@using BlazorAppWithCockroachDB.Model;
@inject HttpClient Http
@inject NavigationManager NavigationManager
@inject IJSRuntime js
<h3>All Accounts</h3>
View CreateAccount.razor
@page "/CreateAccount"
@using BlazorAppWithCockroachDB.Model;
@using Newtonsoft.Json
@inject NavigationManager NavigationManager
@inject HttpClient Http
<h3>Create an Account</h3>
View EditAccount.razor
@page "/EditAccount/{Id:int}"
@using BlazorAppWithCockroachDB.Model;
@using Newtonsoft.Json
@inject NavigationManager NavigationManager
@inject HttpClient Http
<h3>Edit Account</h3>