Skip to content

Instantly share code, notes, and snippets.

@codehaks
codehaks / roadmap.md
Last active July 23, 2020 03:13
Roadmap

RoadMap

C# Programming

C# 6.0 -> C# 9.0 new features

ASP.NET Core

  • MVC
  • Razor Pages
  • Web API
@codehaks
codehaks / HomeController.cs
Created July 1, 2020 08:24
Expression-Bodied Members
using Microsoft.AspNetCore.Mvc;
using MyProfile.Common;
using PeopleApp.Common;
using PeopleApp.Data;
using System;
using System.Linq;
using System.Linq.Expressions;
namespace PeopleApp.Controllers
{
using System;
using static Domain.Result;
namespace Domain
{
public readonly struct Result
{
private readonly Result<int, StringError> _result => new Result<int, StringError>(0);
public int Value => _result.Value;
@codehaks
codehaks / Test.cs
Last active March 27, 2020 07:54
test
.class public auto ansi beforefieldinit MyApp.IndexModel
extends [Microsoft.AspNetCore.Mvc.RazorPages]Microsoft.AspNetCore.Mvc.RazorPages.PageModel
{
// Nested Types
.class nested private auto ansi sealed beforefieldinit '<OnGet>d__0'
extends [System.Runtime]System.Object
implements [System.Runtime]System.Runtime.CompilerServices.IAsyncStateMachine
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
@codehaks
codehaks / LocalizeNumbers.cs
Created January 27, 2020 20:25
Farsi numbers
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace Portal.Infrastructure.Extentions
{
public static class StringExtentions
{
private const int ZeroCharCode = '0';
private const int LocalizedZeroCharCode = '۰';
@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;
@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 / 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 / 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 / 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);