Posts

How can I create a generic data repository for my Entity Framework solution?

I recently created a quick console application that required CRUD activities on a SQL database. I had a few tables to update and did not want the headache of creating multiple items in my DAL. Enter a generic data repository. The code is pretty simple: 1. Create a base interface for the CRUD operations public interface IGenericDataRepository<T> where T : class     {         List<T> GetAll(params Expression<Func<T, object>>[] navigationProperties);         List<T> GetList(Func<T, bool> where, params Expression<Func<T, object>>[] navigationProperties);         T GetSingle(Func<T, bool> where, params Expression<Func<T, object>>[] navigationProperties);         void Add(params T[] items);         void Update(params T[] items);         void Remove(params T[] items);     ...

Azure: How do I create an MVC site to load files to BLOB storage?

I recently created a simple POC site to load files to blob storage containers in Azure. Here is how I achieved it. My code is based on the sample provided  here After creating a simple MVC web project, I added the following nuget packages: DropZone WindowsAzure.Storage Microsoft.WindowsAzure.ConfigurationManager The code is pretty simple: Here is Index.cshtml: @model List<string> <script src="~/Scripts/dropzone/dropzone.min.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <link href="~/Scripts/dropzone/dropzone.min.css" rel="stylesheet" /> <div class="jumbotron">     <h2>FILE UPLOAD</h2>     <form action="~/Home/Upload"           class="dropzone"           id="dropzoneJsForm"           style="background-color:#00BFFF"></form>         <button id="refresh" onc...

CSS: How do I create a spinning 'loading' icon using an image

Image
The icon can be created using the following simple classes .loading{background:url(../img/loading-purple.gif) no-repeat center} .loading > div{display:none} Here is a sample image that could be used. Too easy. However, this is old school. You can create a simpler one using CSS and HTML5. Here is the CSS: .loading-container{display:block;width:100%;min-height:45%;margin-top:60px;text-align:center} .loader {margin:0 auto;text-align:center;width:200px;min-height:100%;display:block;vertical-align:middle} .loader:hover{opacity:1} .loading-spinning-bubbles{position:relative;margin:auto;min-height:1px} .loading-spinning-bubbles .bubble-container {position:absolute;top:calc(50% - 10px/2);left:calc(50% - 10px/2);transform-origin:-150% 50%;-webkit-transform-origin:-150% 50%;-moz-transform-origin:-150% 50%} .loading-spinning-bubbles .bubble-container .bubble {background:#00ac00;width:10px;height:10px;border-radius:50%;animation:bubble 1s infinite;-webkit-animation:bubble ...

Web API: How do I clean up the data in my HttpResponse?

There are some very simple web.config settings that can be applied to reduce the amount on unnecessary data returned in an HttpReponse and to minimise ways that hackers can hijack system information. Here is a quick snippet of web.config settings that may be useful. <Config> <system.web>  <httpRuntime enableVersionHeader="false" /> </system.web> <system.webServer> <httpProtocol>  <customHeaders> <add name="Strict-Transport-Security" value="778000; includeSubdomains" /> <add name="X-Content-Type-Options" value="nosniff" /> <add name="X-Permitted-Cross-Domain-Policies" value="none" /> <add name="X-XSS-Protection" value="1; mode=block" /> <add name="Cache-Control" value="no-store" /> <add name="Pragma" value="no-cache" /> <remove name...

C#: What is the difference between IQueryable vs IEnumerable?

The main difference between the two is the location of the query execution. The following example demonstrates the difference: IQueryable<Model> models = ... models.Where(x => x.ID ...) IQueryable is used from LINQ-to-Anything (such as SQL). In this case, the query filter will be executed on the SQL server. This is great for reducing the amount of data returned from the data store. However, if the code looks as follows: IEnumerable<Model> models = ... models.Where(x=> x.ID ...) The results might be the same but using IEnumerable will cause the query results to be loaded in the memory and the predicate will be executed on the entire result set.

C#: How can I get my Selemium test to log into Azure?

I have been writing some entry level Selenium tests for my Azure website that authenticates using Azure AD. The biggest issue is trying to get the WebDriver to authenticate into the solution. After a lot of learning (read: failed attempts) I have the following solution (read: hack) that seems to work. 1. In my [TestInitialize] method, I load JQuery to the created page public static class Common     {         public static string GetEval(IWebDriver driver, string script)         {             IJavaScriptExecutor js = driver as IJavaScriptExecutor;             return (string)js.ExecuteScript(script);         }         public static string GetFile(string path)         {             using (var reader = new StreamReader(path))             {   ...

CSS: How do I create a single 'back to top' button?

A little CSS and JQuery can produce a lot of magic in an application. Here is the code. 1. Start with a simple html page. The important item here is to have an 'ID' to navigate to. In my case, I called it 'top'. <html> <head>     <base href="/" />     <title>Test Page</title>     <meta charset="UTF-8" />     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <script src=”//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js”></script>     <link href="css/myStuff.css" rel="stylesheet" /> </head> <body>     <div>         <!-- Start Body Content -->         <div ng-view role="main" id="top"></div>         <!-- End Body Content --> ...