Skip to content

Instantly share code, notes, and snippets.

@codehaks
codehaks / startup.cs
Last active September 6, 2017 20:10
Simulating app.Run with app.Use in ASP.NET Core 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace MiddlewareDemo
@codehaks
codehaks / startup.cs
Created September 15, 2017 09:22
Simulating Error handling in ASP.NET Core
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace ErrorDemo {
@codehaks
codehaks / startup.cs
Created September 25, 2017 06:47
Alternate pipeline for Error Handling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
@codehaks
codehaks / NotFoundAttribute.cs
Created December 27, 2017 09:35
ASP MVC ActionFilter to simulate NotFound result
using System.Web;
using System.Web.Mvc;
namespace MyWebProject.Common
{
public class NotFoundAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
throw new HttpException(404, "Requested page not found");
@codehaks
codehaks / LiteDbServiceExtention.cs
Created October 1, 2018 16:48
LiteDb Service for ASP.NET Core
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace BugPages.Common
{
public static class LiteDbServiceExtention
{
public static void AddLiteDb(this IServiceCollection services,string databasePath)
{
services.AddTransient<LiteDbContext, LiteDbContext>();
@codehaks
codehaks / LiteDbContext.cs
Created October 1, 2018 16:56
LiteDb Context
using LiteDB;
using Microsoft.Extensions.Options;
using System;
namespace BugPages.Common
{
public class LiteDbContext
{
public readonly LiteDatabase Context;
public LiteDbContext(IOptions<LiteDbConfig> configs)
@codehaks
codehaks / LiteDbConfig.cs
Created October 1, 2018 16:57
LiteDb Injection context
public class LiteDbConfig
{
public string DatabasePath { get; set; }
}
@codehaks
codehaks / Compare.cs
Created October 3, 2018 08:03
Comparing Strings in C#
public class Compare
{
public IActionResult ToLower()
{
var all = _db.Users.ToList();
var now = DateTime.Now;
int jacksCount = 0;
for (int i = 0; i < 1000; i++)
@codehaks
codehaks / Startup.cs
Created October 7, 2018 08:22
Setting Identity Cookie TimeSpan
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<AppDbContext>(options =>
options.UseSqlite("Data Source=app.db"));
@codehaks
codehaks / _Stars.cshtml
Created November 1, 2018 06:45
Star Rating PartialView
@model int
@for (var i = 0; i < 5; i++)
{
if (i < Model)
{
<i class="fa fa-star" style="color:#ffd800"></i>
}
else
{
<i class="fa fa-star-o"></i>