Skip to content
✔ [ SIOH ] Swastika I/O Heart is the Special Code Base for every startup ASP.NET Core / Dotnet Core systems
C# PowerShell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src
.gitignore
.project
.travis.yml
LICENSE
README.md
git-reset-hard.bat
mix2swa.ps1

README.md

Swastika-Heart

CodeFactor FOSSA Status Build Status

License

FOSSA Status

Reference

https://github.com/Swastika-IO/Swastika-IO-Heart-Sample

Sample Code

Create Models

using System;

namespace SimpleBlog.Data.Blog
{
    public class Post
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public string SeoName { get; set; }
        public string Excerpt { get; set; }
        public string Content { get; set; }
        public string Author { get; set; }
        public DateTime CreatedDateUTC { get; set; }
    }
}

public class BlogContext : DbContext
{
    public DbSet<Post> Post { get; set; }
    public BlogContext()
    { }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlite("Data Source=blogging.db");
            //optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=demo-heart.db;Trusted_Connection=True;MultipleActiveResultSets=true");

        }
    }
}

Using Heart

Create ViewModel Class

namespace SimpleBlog.ViewModels
{
    // Create ViewModel using Heart 
    public class PostViewModel: ViewModelBase<BlogContext, Post, PostViewModel>    
    {
        //Declare properties that this viewmodel need         
        public string Id { get; set; }
        [Required(ErrorMessage = "Title is required")]        
        public string Title { get; set; }        
        public DateTime CreatedDateUTC { get; set; }
        
        //Declare properties need for view or convert from model to view        
        public DateTime CreatedDateLocal { get { return CreatedDateUTC.ToLocalTime(); } }        
        
        public PostViewModel()
        {
        }

        public PostViewModel(Post model, BlogContext _context = null, IDbContextTransaction _transaction = null) : base(model, _context, _transaction)
        {
        }
    }

Using

Save

var saveResult = await post.SaveModelAsync();

Get Single

var getPosts = await PostViewModel.Repository.GetSingleModelAsync(p=>p.Id==1);
return View(getPosts.Data);

Get All

var getPosts = await PostViewModel.Repository.GetModelListAsync();
return View(getPosts.Data);

Get All with predicate

var getPosts = await PostViewModel.Repository.GetModelListByAsync(p=>p.Title.Contains("some text"));
return View(getPosts.Data);

Get Paging

var getPosts = await PostViewModel.Repository.GetModelListAsync("CreatedDate", OrderByDirection.Descending, pageSize, pageIndex);
return View(getPosts.Data);

Get Paging with predicate

var getPosts = await PostViewModel.Repository.GetModelListByAsync(p=>p.Title.Contains("some text"), "CreatedDate", OrderByDirection.Descending, pageSize, pageIndex);
return View(getPosts.Data);
You can’t perform that action at this time.