Skip to content

Instantly share code, notes, and snippets.

@derans
derans / Foreach Post - Original Code.cs
Created March 12, 2012 05:41
Move Items Old School
protected void moveItems(ListControl sendingLB, ListControl receivingLB)
{
ListBox temp = new ListBox();
List<ListItem> tempList = new List<ListItem>();
Comparison<ListItem> compare = new Comparison<ListItem>(CompareListItems);
foreach (ListItem li in sendingLB.Items)
if (li.Selected && receivingLB.Items.FindByText(li.Text) == null)
receivingLB.Items.Add(li);
else
@derans
derans / ForeachRefactor.cs
Created March 12, 2012 06:12
Move Items using LINQ
protected void moveItems(ListControl source, ListControl destination)
{
var getListItemsFrom = new Func<ListControl, List<ListItem>>
(x => x.Items.Cast<ListItem>().ToList());
var selectedItems = getListItemsFrom(source).Where(x => x.Selected);
var nonSelectedItems = getListItemsFrom(source).Where(x => !x.Selected);
var currentDestinationItems = getListItemsFrom(destination);
//Thanks Ryan for the .Except instead of the .Where(not)
@derans
derans / l2s_repository.cs
Last active October 2, 2015 00:08
L2S Repository
public abstract class LinqToSqlRepository : IDisposable
{
private readonly DataContext _dc;
protected LinqToSqlRepository()
{
_dc = DataContext;
}
public T Load<T>(object id) where T : class
@derans
derans / l2s_repository_sample_usage.cs
Created March 20, 2012 05:16
L2S Repository Sample Usage
public class SampleClass
{
public SampleObject GetById(int id)
{
using(var repository = new LinqToSqlRepository<SampleDataContext>())
{
var result = repository.Load<SampleDataModel>(id);
return Mapper.Map<SampleObject>(result);
}
[TestFixture]
public class ControllerTester : TestBase
{
private IEnumerable<Type> ControllerTypes
{
get
{
var assembly = Assembly.GetAssembly(typeof(HomeController));
return assembly.GetTypes()
.Where(controller => controller.IsSubclassOf(typeof(Controller))
@derans
derans / SampleControllers.cs
Created May 10, 2012 02:49
Sample Controllers
public class HomeController : Controller
{
private readonly IUserSession _userSession;
public HomeController(IUserSession userSession)
{
_userSession = userSession;
}
}
@derans
derans / SampleTestBase.cs
Created May 10, 2012 02:52
Sample Test Base
public class TestBase
{
public TestBase()
{
ObjectFactory.Initialize(x => x.Configure(
pluginGraph => pluginGraph.Scan(scanner =>
{
scanner.AssemblyContainingType<HomeController>();
scanner.WithDefaultConventions();
})));
@derans
derans / Styles_for_file_extensions.css
Created May 22, 2012 04:41
Styles for File Extensions
/*Icons used here are from famfamfam.com*/
<style type="text/css">
a.with-icon
{
padding-left: 20px;
background-position: top left;
background-repeat: no-repeat;
}
a.with-icon[href$='.gif'],a.with-icon[href$='.png'],a.with-icon[href$='.jpg']
@derans
derans / Links_to_files_with_icons.html
Created May 22, 2012 04:53
Links to files with icons
@derans
derans / classification.html
Created June 12, 2012 03:05
Classification_html_markup_example
<fieldset id="classification_radio_wrapper">
<legend>Classification</legend>
<input type="radio" name="classification" id="Freshman" value="Freshman" checked />
<label for="Freshman" class="Freshman">Freshman</label>
<input type="radio" name="classification" id="Sophomore" value="Sophomore" />
<label for="Sophomore" class="Sophomore">Sophomore</label>
<input type="radio" name="classification" id="Junior" value="Junior" />
<label for="Junior" class="Junior">Junior</label>
<input type="radio" name="classification" id="Senior" value="Senior" />
<label for="Senior" class="Senior">Senior</label>