This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// sample list to test | |
var list = new ArrayList | |
{ | |
new ArrayList { | |
new ArrayList | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValidateModelAttribute : ActionFilterAttribute | |
{ | |
public override async Task OnActionExecutionAsync(ActionExecutingContext context, Action | |
{ | |
var result = new ViewResult(); | |
if (!context.ModelState.IsValid) | |
{ | |
// Usually POST action looks like: IActionResult Save(MyMode model) | |
// if validation failed we need to forward that model back to view | |
// Model is in ActionArgument[0] in this case, but you may tweak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost, ValidateAnyForgeryToken] | |
public async Task<IActionResult> Save(ProductModel model) | |
{ | |
if(!ModelState.IsValid) | |
return View(model); | |
// invoke some business logic magic that makes money | |
try | |
{ | |
await _dbContext.SaveChanges(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class LinkDecorator : IRenderable | |
{ | |
private readonly IRenderable _inner; | |
private readonly string _url; | |
public LinkDecorator(IRenderable inner, string url) | |
{ | |
_inner = inner; | |
_url = url; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal interface IRenderable | |
{ | |
string Render(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var element = new UnorderedList(new ListItem(new Link(new Content(“page 2”)))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="pagination"> | |
<li><a href="#" >«</a></li> | |
<li class="active"><a href="?page=1" >1</a></li> | |
<li><a href="?page=2" >2</a></li> | |
<li><a href="?page=3" >3</a></li> | |
<li class="disabled"><span>...</span></li> | |
<li><a href="?page=20" >20</a></li> | |
<li><a href="?page=2" >»</a></li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void User_can_write_story_when_authenticated() | |
{ | |
var controller = new HomeController(); | |
controller.ControllerContext = new ControllerContext | |
{ | |
HttpContext = new DefaultHttpContext | |
{ | |
User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] | |
{ | |
new Claim(ClaimTypes.Name, "username") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IActionResult Index() | |
{ | |
var model = new HomePageViewModel | |
{ | |
Title = "Welcome!", | |
DisplayMode = StoriesDisplayMode.FeaturedList, | |
CanWriteStory = User.Identity.IsAuthenticated | |
}; | |
return View(model); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var children = new List<Child> { new Child("Hudo", true), new Child("Genna", true), new Child("Calippio", false), new Child("Javier", false), new Child("Cristian", true)}; | |
var presents = new List<Present> { new Present("Tannoy speakers", 2), new Present("Candy", 1)}; | |
presents | |
.SelectMany(x => Enumerable.Range(1, x.Quantity).Select(c => new Present(x.Name, 1))) | |
.Zip(children.Where(x => x.WasGood), (present, child) => new Assignment(child.Name, present.Name)) |
NewerOlder