Skip to content

Instantly share code, notes, and snippets.

@codehaks
codehaks / StarsTagHelper.cs
Created November 1, 2018 06:49
Star rating TagHelper
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace Codehaks.TagHelpers
{
public class StarsTagHelper : TagHelper
{
public int Level { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
@codehaks
codehaks / StarRating.html
Created November 1, 2018 06:58
Stars rating HTML
<i class="fa fa-star" style="color:#ffd800"></i>
<i class="fa fa-star" style="color:#ffd800"></i>
<i class="fa fa-star" style="color:#ffd800"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
@codehaks
codehaks / UsePartialView.cshtml
Created November 1, 2018 07:04
UsePartialView.cshtml
@page "/test/partial"
@{
ViewData["Title"] = "UserPartialView";
var watch = System.Diagnostics.Stopwatch.StartNew();
int count = 10000;
}
<h2>Performance Test : Partial View</h2>
<hr />
@for (int i = 1; i < count + 1; i++)
{
@codehaks
codehaks / UseTagHelper.cshtml
Created November 1, 2018 07:05
UseTagHelper.cshtml
@page "/test/tag"
@{
ViewData["Title"] = "UserPartialView";
var watch = System.Diagnostics.Stopwatch.StartNew();
int count = 10000;
}
<h2>Performance Test : TagHelper</h2>
<hr />
@for (int i = 1; i < count+1; i++)
@codehaks
codehaks / Test
Created July 27, 2019 19:42
Test
Test
@codehaks
codehaks / TagsModelBinder.cs
Created August 9, 2019 09:16
Custom Model binder for Tags
public class TagsModelBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
var modelName = bindingContext.ModelName;
var tagsModel =
bindingContext.ValueProvider.GetValue(modelName);
@codehaks
codehaks / TagsModelBinderProvider.cs
Created August 9, 2019 17:27
TagsModelBinderProvider
public class TagsModelBinderProvider:IModelBinderProvider
{
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.Metadata.ModelType == typeof(IEnumerable<string>))
@codehaks
codehaks / EmailSender.cs
Created August 18, 2019 17:52
Send Email in ASP.NET Core 2.0+
public class EmailSender : IEmailSender
{
public Task SendEmailAsync(string email, string subject, string message)
{
SmtpClient client = new SmtpClient("mail.mysite.com")
{
UseDefaultCredentials = false
};
client.Credentials = new NetworkCredential("noreply@mysite.com", "password");
@codehaks
codehaks / program.cs
Created September 30, 2019 00:46
IAsyncEnumerable compare
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PhotoSlash
{
class Program
{
static async Task Main(string[] args)
{
@codehaks
codehaks / Program.cs
Created October 15, 2019 07:07
Dependecny injection in console app
using LinqLab.API;
using LinqLab.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MoreLinq;
using System;
using System.Linq;