Posts

Showing posts with the label C#

Setting up QunitJs for Asp.net MVC Debugging

    Using  QUnit  is important for me on some of my projects that are more front-end driven. So developing, debugging and testing all need to happen in javascript but without being in the final production. One thing I do not want to do is include the QunitJs in my bundles and would serve no purpose because the bundling and minifying does not happen for debugging. Instead what I did was create an extension method and return a bool, like the one shown in the resources. //Location ../Helpers/IsDebugging public static bool IsDebugging(this HtmlHelper helper) { #if DEBUG return true; #else return false; #endif } //Location ../Views/Shared/_Layout.cshtml //These two files are not apart of any bundled packages. @ if(Html.IsReleaseBuild()) { @ Scripts.Render( "~/Scripts/qunit-1.14.0.js" ) @ Styles.Render( "~/Content/qunit-1.14.0.css" ) } Side Notes The intellisense will do some weird things with the coloring for code inside the else sta

Using Entity Framework and a Storage Procedure with Parameters

    So I was stuck sometime ago on a problem I had where I was using my sql store procedure with the Entity Framework. Eventually found what I needed and the purpose of this article is just to write out a small example. I've come up with  multiple  ways to achieve the same thing now but this is the most basic form of it. public IList<KeyValuePair> GetIds (string id) { using (var db = DBFactory. GetDB ()) { return db.Database.SqlQuery<KeyValuePair>( "EXEC db.MyDatabase @id", new SqlParameter("id", id)); } } Resources How to pass parameters to DbSet.SqlQuery Method in Entity Framework How to use DbContext.Database.SqlQuery (sql, params) with stored procedure? EF Code First CTP5 The data reader has more than one field. Multiple fields are not valid for EDM primitive types KeyValuePair(TKey, TValue) Structure (System.Collections.Generic)

Orchard: Filter out Content Types From Restricted Users.

I want to be very clear I did not write this code but it was provided to me and I was given permission by a colleague of mine to submit it.. To respect his privacy I will not be able to provide his name but on his behalf I did submit the code to help improve the orchard project. To explain it a little bit what the purpose of this code edit, it is to filter out content that is editable but the user does not have the permissions to create them. Normal what Orchard would do is display all creatable content and if a user clicks on a particular content type that is restricted it simply replies to the user that they do not have access to it. However with a lot of CMS projects I have developed it is sometimes better to simply hide what the user can not or should not be able to do. Less questions come up and even less problems are seen from the user's perspective. This is what I consider to be a best practice to provide the user with a good experience. The Location : \ orchard

Unauthorized Ajax Handler for Asp.net MVC

Image
Requirements      I need respond to users that they are unauthorized, and I need it to not return a redirect to them from a ajax call which Asp.net MVC does by default. A even better solution would be that I also do not force users to refresh page they are currently on and instead give them the ability to re-login via ajax on that current screen. This would allow users to save any  information they are currently working on. I should warn the user that it they are no longer logged in and if possible prompt them and within that same prompt allow them a way to login back in all without refreshing or a redirect. For now I'm going to just focus on the first problem which is suppressing Asp.Net's default behavior with unauthorized calls and do this just for Ajax calls. An Example I can see while using Blogger Solution - Thanks to Joe Harrison for missing pieces!  //C# code override an Authorization Attribute create a customized one. protected virtual void HandleUnautho

At the Start of My C# Research

This article is a list of resources that I used way back at the start of my career with C#. Since there are a lot of C# tutorials already out I just wanted to write out some of my experiences and topics that I was curious to learn when starting out. The main reason why I wanted to used C# for programming was for Asp.net MVC applications and toward the second year I discovered XNA. Getting Ready at the Start!     If you're a Java Developer the  using Statement  is much like a import and include in C++. Having experience with both languages doesn't hurt and speaking from my own experiences with both languages, C# is probably the easiest compared to all of them. And for multiple reasons, but mostly because of Visual Studio's Intellisense in my opinion.  C# language itself Random resources that I used, for multiple projects. Visual C# Resources Delegates Tutorial C# Short Type  - Sometimes its just good to compare  ( Java , C++ ) . Creating Custom Routes

MVC Excel Email Attachment with NPOI

    The First Question I had after successfully creating a Excel sheet was  how do I create an attachment from a stream?  A second to be more specific was  how do I add an attachment to an email using System.Net.Mail?  Ultimately I wanted to have the  Excel Exports in C# using NPOI  but I started small and thankfully others had already asked and answered these questions. After which was just a matter of knowing  What the correct content-type for excel files was? First Attempt MailMessage mail = new MailMessage(); HSSFWorkbook workbook = CreateExcel(OrderId); MemoryStream ms = new MemoryStream(workbook.GetBytes()); mail.Attachments.Add(new Attachment(ms, "example.xls", "application/vnd.ms-excel")); _emailService.SendEmail("example@example.com", "Email test", "Testing 123"); Changed it to.. MemoryStream ms = new MemoryStream(); workbook.Write(ms); This was based on the QA " NPOI -

MVC Data Exported to Excel with NPOI

This is an article for just writing an Excel file using  NPOI  and I want the quickest and easiest way to export a excel file from Asp.net MVC. To keep everything in work fluid motion I will keep the user on the same page and do a forced download within that page. This is a setup that I have seen in multiple times and I think works great in today's modern website designs. Creates excel files Leniel Macaferi's blog: Creating Excel spreadsheets .XLS and .XLSX in C# Create Excel Spreadsheets Using NPOI var workbook = new HSSFWorkbook(); var ExampleSheet = workbook.CreateSheet("Example Sheet"); var rowIndex = 0; var row = ExampleSheet.CreateRow(rowIndex); row.CreateCell(0).SetCellValue("Example in first cell(0,0)"); rowIndex++; Problems I faced XLS is not the same as CVS which is obvious but truthfully I did not know the difference between the two file types (other than their different extensions). So I asked myself what is the  Difference between CS

C# vs. Javascript Foreach

     This article is about a certain style of writing in Javascript that I like use when iterating through an array combined with a foreach which looks something like the following... var someArray = ["1", "2", "3"]; $.foreach(someArray, function(key, value){ console.log(key + " , " + value); });      Ultimately when I tried to take this same concept over to C# the style did not convert over in the exact same way. I found that the temp variable being used to iterate with did not have any values that tracked where it was in place of the iteration. I found myself asking a similar question in  how do you get the index of the current iteration of a foreach loop?  To see what I tried you can look at another person's  problem  where I had attempted in the same manner. Attempting to use the "current" value in the  GetEnumerator()  sadly does not work. Solution      To summarize the answer for this problem the "foreach&

A Static DropDownList for ASP.Net MVC

Image
     When creating a static dropdowns list in Asp.net MVC, I have a two approaches that I like to commonly use. I know there are many ways to achieve this UI structure and I don't consider either one of the following approaches to be the final solution. However for awhile now  I have been using these two approaches  and I think they are  much  simpler  and easier to maintain  compared to other ways that I have seen . Rather than writing out the HTML select tag and all the options I take advantage of the Html Helper Dropdownlist. I avoid model bind since it is static and I don't want create the list outside of the view. I think this would only create more work to maintain and confusion for other coders if they new to my applications.  I did not come up with either solution  completely on my own and I actually forget where I saw them since it did take a while to find these approach in my research.   What's  important to take away in this article is that if you look carefull

XNA Resources

Downloads Source for XNA Dev Kits Forums: MSDN Forum Gamedev stackexchange Library : XNA Game Studio 4.0 Refresh Advanced Topics Advanced Xbox 360 Programming Cross Platform Ability Currently only project that I know of that allow you to use C# on multiple platforms is MonoGame . Use Visual Studio 2012 How to install XNA Research from others : 2D Collision Detection Matrices XNA tutorials XNA Series 1: Collision Detection - Code for Cake If you into game development you probably at some point want to know how to do 3D programming. A great resource that I use and that shows how to use a camera in multiple ways can be found on  dhpoware  t he have many examples such as first shooter and 3rd person as well as free roam camera examples. XNA Series 1: Collision Detection - Code for Cake 2D Development Changing the frequency for the update and draw Networking Creating a Network Session Finished Car Gam

What is the Rust Spot?

Image
The Idea     A lot of times When I try to explain an Idea, I find it increasingly difficult to explain the more complex it is. So I will begin to explain it here in a nutshell. I want to create 3D models of my car and all the parts that it is made of. Simple right? Now I won't go into details of why just yet but I will say you have no idea how many parts making up your car. So the complex idea is this, I want to create a website that not only creates a 3D model of all the parts on a car but compares the parts for compatibility with other makes and models. To go further with at by give a complete break down of the car and instruction on installation or remove of parts. Still with me? Good here is a example of what a normal diagram of a car part... Air Cleaner 2013 Honda Accord The Problem     Now from the picture you have a general idea of what your parts look like, but what about the placement of where it is in your car? Maybe your looking at the wrong model? Cars have

Popular posts from this blog

UI-Bootstrap Collapsible Sticky Footer

Installing Windows on Acer chromebook 15 cb3-532

Aspetcore: NLog with Postgresql