Skip to content

Instantly share code, notes, and snippets.

View MoienTajik's full-sized avatar
👾

Moien Tajik MoienTajik

👾
View GitHub Profile
@MoienTajik
MoienTajik / Post.cs
Last active September 18, 2017 09:51
Post class for TinyMCE
public class Post
{
public string Title { get; set; }
[AllowHtml]
[UIHint("tinymce_jquery_full")]
public string Description { get; set; }
}
public class PostsController : Controller
{
public ActionResult Create()
{
return View();
}
}
@model TinyMCE.Models.Post
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@model TinyMCE.Models.Post
<h2>Details</h2>
@Html.Raw(Model.Description)
@MoienTajik
MoienTajik / iranian-phone-numbers-regex.md
Last active May 11, 2025 11:51
Regex For Iranian Mobile Phone Numbers

Regex For Iranian Phone Numbers

This regex supports all kinds of Iranian mobile phone numbers :

^(\+98|0)?9\d{9}$


Regex Visualized

@MoienTajik
MoienTajik / EFWildcardSearch.md
Last active December 13, 2017 11:18
Wildcard Search Helper Entity Framework

Wildcard Search Helper Entity Framework

You can build a LIKE statement with wildcard characters in LINQ to Entities with this Helper.

WildCard

@MoienTajik
MoienTajik / SiteSettings.cs
Last active February 17, 2018 10:12
Using Google reCAPTCHA in ASP.NET MVC - Site Settings
public static class SiteSettings
{
public const string GoogleRecaptchaSecretKey = "6Lea1EYUAAAAACn3pDs7EL8msJh0h0KgH-ajakZ_";
public const string GoogleRecaptchaSiteKey = "6Lea1EYUAAAAAHvvT5xIFXt1UknyKUf1C1w5Ko77";
}
@MoienTajik
MoienTajik / GoogleCaptchaHelper.cs
Last active February 17, 2018 12:32
Using Google reCAPTCHA in ASP.NET MVC - reCAPTCHA Generator
public static class GoogleCaptchaHelper
{
public static IHtmlString GoogleCaptcha(this HtmlHelper helper)
{
const string publicSiteKey = SiteSettings.GoogleRecaptchaSiteKey;
var mvcHtmlString = new TagBuilder("div")
{
Attributes =
{
@MoienTajik
MoienTajik / InvalidGoogleCaptchaLabel.cs
Created February 17, 2018 12:38
Using Google reCAPTCHA in ASP.NET MVC - Invalid reCAPTCHA Label
public static class InvalidGoogleCaptchaHelper
{
public static IHtmlString InvalidGoogleCaptchaLabel(this HtmlHelper helper, string errorText)
{
var invalidCaptchaObj = helper.ViewContext.Controller.TempData["InvalidCaptcha"];
var invalidCaptcha = invalidCaptchaObj?.ToString();
if (string.IsNullOrWhiteSpace(invalidCaptcha)) return MvcHtmlString.Create("");
var buttonTag = new TagBuilder("span")
@MoienTajik
MoienTajik / ValidateGoogleCaptchaAttribute.cs
Created February 17, 2018 12:48
Using Google reCAPTCHA in ASP.NET MVC - Validate reCAPTCHA Attribute
public class ValidateGoogleCaptchaAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
const string urlToPost = "https://www.google.com/recaptcha/api/siteverify";
const string secretKey = SiteSettings.GoogleRecaptchaSecretKey;
var captchaResponse = filterContext.HttpContext.Request.Form["g-recaptcha-response"];
if (string.IsNullOrWhiteSpace(captchaResponse)) AddErrorAndRedirectToGetAction(filterContext);