Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This file explains how Visual Studio created the project.

The following steps were used to generate this project:
- Create new ASP\.NET Core Web API project.
- Update project file to add a reference to the frontend project and set SPA properties.
- Update `launchSettings.json` to register the SPA proxy as a startup assembly.
- Add project to the startup projects list.
- Write this file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using Grid_SQLite.Server.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Syncfusion.EJ2.Base;

namespace Grid_SQLite.Server.Controllers
{
[Route("api/[controller]")]
public class AssetController : ControllerBase
{
private readonly AssetDbContext _db;

public AssetController(AssetDbContext db)
{
_db = db;
}

// READ
[HttpPost("url")]
public IActionResult UrlDataSource([FromBody] DataManagerRequest dm)
{
IQueryable<Asset> query = _db.Assets.AsNoTracking();
var op = new DataOperations();

if (dm.Search?.Count > 0)
query = op.PerformSearching(query, dm.Search).Cast<Asset>().AsQueryable();

if (dm.Where?.Count > 0)
query = op.PerformFiltering(query, dm.Where, dm.Where[0].Operator)
.Cast<Asset>()
.AsQueryable();

if (dm.Sorted?.Count > 0)
query = op.PerformSorting(query, dm.Sorted).Cast<Asset>().AsQueryable();
else
query = query.OrderBy(a => a.Id);

var count = query.Count();

if (dm.Skip > 0)
query = query.Skip(dm.Skip);

if (dm.Take > 0)
query = query.Take(dm.Take);

return dm.RequiresCounts
? Ok(new { result = query.ToList(), count })
: Ok(query.ToList());
}

// CREATE
[HttpPost("insert")]
public IActionResult Insert([FromBody] CRUDModel<Asset> value)
{
var asset = value.Value;

// Identity handled automatically
asset.Id = 0;

_db.Assets.Add(asset);
_db.SaveChanges();

return Ok(asset);
}

// UPDATE
[HttpPost("update")]
public IActionResult Update([FromBody] CRUDModel<Asset> value)
{
var asset = value.Value;

_db.Entry(asset).State = EntityState.Modified;
_db.SaveChanges();

return Ok(asset);
}

// DELETE
[HttpPost("remove")]
public IActionResult Remove([FromBody] CRUDModel<Asset> value)
{
int key;
if (value.Key is System.Text.Json.JsonElement jsonElement)
{
key = jsonElement.GetInt32();
}
else
{
key = Convert.ToInt32(value.Key);
}
var asset = _db.Assets.First(a => a.Id == key);

_db.Assets.Remove(asset);
_db.SaveChanges();

return Ok(value);
}

// BATCH
[HttpPost("batch")]
public IActionResult Batch([FromBody] CRUDModel<Asset> value)
{
if (value.Changed != null)
{
foreach (var asset in value.Changed)
{
_db.Assets.Attach(asset);
_db.Entry(asset).State = EntityState.Modified;
}
}

if (value.Added != null)
{
foreach (var asset in value.Added)
{
asset.Id = 0;
_db.Assets.Add(asset);
}
}

if (value.Deleted != null)
{
foreach (var asset in value.Deleted)
{
var existing = _db.Assets.Find(asset.Id);
if (existing != null)
_db.Assets.Remove(existing);
}
}

_db.SaveChanges();
return Ok(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;

namespace Grid_SQLite.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries =
[
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
];

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.ComponentModel.DataAnnotations;

namespace Grid_SQLite.Server.Data
{
/// <summary>
/// Represents an asset record mapped to the 'asset' table in the database.
/// This model defines the structure of asset-related data used throughout the application.
/// </summary>
public class Asset
{
/// <summary>
/// Gets or sets the unique identifier for the Asset record.
/// </summary>
[Key]
public int Id { get; set; }

/// <summary>
/// Gets or sets the unique asset reference generated by the system.
/// Format: AST-XXXXX (e.g., AST-001, AST-002)
/// </summary>
public string AssetID { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the Name/description of the asset
/// </summary>
public string AssetName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the Type/category of the asset (Laptop, Desktop, Monitor, Printer, etc.)
/// </summary>
public string AssetType { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the Model/specification of the asset
/// </summary>
public string? Model { get; set; }

/// <summary>
/// Gets or sets the Serial number/unique identifier from manufacturer
/// </summary>
public string SerialNumber { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the Invoice/purchase order number
/// </summary>
public string? InvoiceID { get; set; }

/// <summary>
/// Gets or sets the Name/person the asset is assigned to
/// </summary>
public string? AssignedTo { get; set; }

/// <summary>
/// Gets or sets the Department that owns/uses the asset
/// Values: IT, Finance, Marketing, HR, Design, Sales, Operations, Executive, Training
/// </summary>
public string? Department { get; set; }

/// <summary>
/// Gets or sets the Date when the asset was purchased
/// </summary>
public DateTime? PurchaseDate { get; set; }

/// <summary>
/// Gets or sets the Purchase cost in currency units
/// Stored with 2 decimal places
/// </summary>
public decimal? PurchaseCost { get; set; }

/// <summary>
/// Gets or sets the Date when the warranty expires
/// </summary>
public DateTime? WarrantyExpiry { get; set; }

/// <summary>
/// Gets or sets the Current condition of the asset
/// Values: New, Good, Fair, Poor
/// </summary>
public string? Condition { get; set; } = "New";

/// <summary>
/// Gets or sets the Date of the last maintenance performed
/// </summary>
public DateTime? LastMaintenance { get; set; }

/// <summary>
/// Gets or sets the Current status of the asset
/// Values: Active, In Repair, Retired, Available
/// </summary>
public string Status { get; set; } = "Available";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Microsoft.EntityFrameworkCore;
using System.Reflection.Emit;

namespace Grid_SQLite.Server.Data
{
/// <summary>
/// DbContext for Asset entity
/// Manages database connections and entity configurations for SQLite
/// </summary>
public class AssetDbContext : DbContext
{
public AssetDbContext(DbContextOptions<AssetDbContext> options)
: base(options)
{
}

/// <summary>
/// DbSet for Asset entities
/// </summary>
public DbSet<Asset> Assets => Set<Asset>();

/// <summary>
/// Configures the entity mappings and constraints
/// </summary>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Asset>(entity =>
{
// Primary Key
entity.HasKey(e => e.Id);

entity.Property(e => e.Id)
.ValueGeneratedOnAdd();

entity.Property(e => e.AssetID)
.HasMaxLength(20)
.IsRequired(true);

entity.Property(e => e.AssetName)
.HasMaxLength(255)
.IsRequired(true);

entity.Property(e => e.AssetType)
.HasMaxLength(100)
.IsRequired(true);

entity.Property(e => e.Model)
.HasMaxLength(150)
.IsRequired(false);

entity.Property(e => e.SerialNumber)
.HasMaxLength(100)
.IsRequired(true);

entity.Property(e => e.InvoiceID)
.HasMaxLength(100)
.IsRequired(false);

entity.Property(e => e.AssignedTo)
.HasMaxLength(150)
.IsRequired(false);

entity.Property(e => e.Department)
.HasMaxLength(50)
.IsRequired(false);

entity.Property(e => e.PurchaseDate)
.HasColumnType("DATE")
.IsRequired(false);

entity.Property(e => e.PurchaseCost)
.HasPrecision(12, 2)
.IsRequired(false);

entity.Property(e => e.WarrantyExpiry)
.HasColumnType("DATE")
.IsRequired(false);

entity.Property(e => e.Condition)
.HasMaxLength(50)
.IsRequired(false)
.HasDefaultValue("New");

entity.Property(e => e.LastMaintenance)
.HasColumnType("DATE")
.IsRequired(false);

entity.Property(e => e.Status)
.HasMaxLength(50)
.IsRequired(true)
.HasDefaultValue("Available");

entity.ToTable("asset");
});
}
}
}
Loading