Skip to content

Instantly share code, notes, and snippets.

View pawelel's full-sized avatar

Paweł Przytuła pawelel

  • Poland, Poznań
View GitHub Profile
@pawelel
pawelel / clock.html
Last active October 16, 2021 11:49
Simple clock in html with JS
<html lang="en">
<head>
<meta charset="UTF-8">
<title>clock</title>
<script>
function counting() {
"use strict";
var today = new Date(),
day = today.getDay(),
@pawelel
pawelel / StaticDataBase.cs
Last active October 16, 2021 11:58
return static list
public class DataBase
{
public static List<Product> GetProducts()
{
List<Product> products = new List<Product>
{
new Product
{
Id=1,
Name= "Nice dress",
@pawelel
pawelel / RangeUntilCurrentYearAttribute.cs
Last active October 16, 2021 11:56
Custom Range attribute for System.ComponentModel.DataAnnotations
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class RangeUntilCurrentYearAttribute : RangeAttribute
{
public RangeUntilCurrentYearAttribute(int minimum) : base(minimum, DateTime.Now.Year)
{
}
}
// And use it like this:
//public class Foo
// {
@pawelel
pawelel / _Imports.razor
Created April 5, 2021 16:44
test imports for bUnit (blazor)
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using Microsoft.Extensions.DependencyInjection
@using AngleSharp.Dom
@using Bunit
@using Bunit.Xunit
@using Bunit.TestDoubles
<MudContainer Class="pa-4" style="border:1px solid grey">
@foreach(var c in chips){
<MudChip Text="@c" OnClose="Remove"></MudChip>
}
<MudTextField T="string" TextChanged="Add"/>
</MudContainer>
@code {
private List<string> chips {get;set;} = new();
@pawelel
pawelel / MudHorizontalNavMenu.razor
Created October 16, 2021 11:44
MudBlazor horizontal menu alternative
<style>
.mud-expand-panel, .muudstrap-navbar-expand{
color: var(--mud-palette-appbar-text);
background-color: var(--mud-palette-appbar-background);
}
.muudstrap-navbar .mud-button{
text-transform: none;
}
@pawelel
pawelel / File.razor
Last active November 11, 2021 16:42
How to get multiselect
<MudTable Items="@(GetPlaces())" T="AreaPlace" Dense="true" @bind-SelectedItem="selectedItem1" Filter="new Func<AreaPlace,bool>(FilterFunc1)">
<ToolBarContent>
<MudItem xs="12" md="5">
<MudTextField @bind-Value="searchString1" Placeholder="@L["Search"]" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"></MudTextField>
</MudItem>
<MudSpacer/>
<MudItem xs="12" md="4">
<MudSelect T="string" @bind-SelectedValues="Options" @bind-Value="@tempArea" MultiSelection="true" Label="@L["Select Areas"]">
@foreach (var area in areas)
/// <summary>
/// Gets the first or default entity based on a predicate, orderby delegate and include delegate. This method default no-tracking query.
/// </summary>
/// <param name="selector">The selector for projection.</param>
/// <param name="predicate">A function to test each element for a condition.</param>
/// <param name="orderBy">A function to order elements.</param>
/// <param name="include">A function to include navigation properties</param>
/// <param name="disableTracking"><c>True</c> to disable changing tracking; otherwise, <c>false</c>. Default to <c>true</c>.</param>
/// <returns>An <see cref="IPagedList{TEntity}"/> that contains elements that satisfy the condition specified by <paramref name="predicate"/>.</returns>
/// <remarks>This method default no-tracking query.</remarks>
/// <summary>
/// Generic Data Manager Class
/// Uses an Entity Framework Data Context to do CRUD operations
/// on ANY entity.
/// Customize to your own liking.
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TDataContext"></typeparam>
public class DataManager<TEntity, TDataContext> : IRepository<TEntity>
where TEntity : class
@if (areas==null)
{
<p>wait</p>
}
else
{
<MudTable Items="@locations" T="AreaPlace" Dense="true" @bind-SelectedItem="selectedItem1" Filter="new Func<AreaPlace,bool>(FilterFunc1)">
<ToolBarContent>
<MudItem xs="12" md="5">