Posts

Simple Breadcrumbs in Razor

If you wish to add Breadcrumb navigation to your site. This is a quick and easy way to do it.  This is only effective if every controller has an Index view and if you are passing route variables such as 'acct=xxx' then this will not accommodate those values so you have to make sure your app is able to manage without the variables and offer another option. @Html.ActionLink("Home", "Index", "Home") @if(ViewContext.RouteData.Values["controller"].ToString() != "Home") { @Html.ActionLink(ViewContext.RouteData.Values["controller"].ToString(), "Index", ViewContext.RouteData.Values["controller"].ToString()) } @if(ViewContext.RouteData.Values["action"].ToString() != "Index"){     @Html.ActionLink(ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["action"].ToString(), ViewContext.RouteData.Values["controller"].ToString()...

PDF from MVC Razor - with heading

Image
Today I was tasked with creating a PDF from a report that had two queries - a header section and detail section. After looking at all the viable options I was tempted by iTextSharp but was faced with the challenge of implementing it in razor.  I then came across this nifty dll written specifically for that purpose and it utilizes iTextSharp to do it. RazorPDF  was the answer.  Al Nyveldt did an excellent job with it and includes a github download with great samples.  The one challenge he didn't cover was my example of two queries to make a more comprehensive report. As shown in the example (screenshot of my pdf generated using this tool) I have header information as well as additional data laid out in a table. To accomplish this I created a ViewModel in my Data project with a simple class that incorporated two references.  One to the header data and one to the Zipcode detail.     public class Fran_Zip_ViewModel     {   ...

#MakeItHappen

Microsoft is making New Years Resolutions come true.  Mine are so big that I am not sure how they could help but thought I would lay it out here for you. 2015 New Years Resolution To get out of debt enough that I can concentrate on bringing my ideas to fruition.  For years I have been making software for my employers while never seeming to have the time to develop my own ideas.  Over the years I have supported domains that I one day will have the time to work on. Some of my domains: ItsaBigDeal.com I envision a daily deal (similar to Woot) and a subscription site combined  If you don't know what a subscription site is - they are becoming a big deal (see mysubscriptionaddiction.com ) ReportMinder.com Wow software out there for daycares/elderly care centers has some deficiencies and I think I can build a better web/app based software UltimateSpaces.com Not sure what I want to do with this domain but it is a great domain. Some o...

Case Statement within Linq

var numberText = ( from n in numbers where n > 0 select new { Number = n , Text = ( n == 1 ? "One" : n == 2 ? "Two" : n == 3 ? "Three" : "Unknown" ) } );

Single Value from Data Entity - not in entity collection

Example of a single computed value from database, not a declared entity type  private decimal getTuneupAmount(DateTime dateCompleted,int classid, int  id)         {        string sql = @"SELECT  (count(ow.orderworkid) * (select tuneupamount from mastertable)) as TuneupAmount";                         sql += " from tbl_o o ";                         sql += " join tbl_work ow on o.orderid=ow.orderid ";                         sql += " join _setup s on ow.taskcodenumber=s.TaskCodeNumber and s.typeid =2 ";                         sql += " WHERE   ow.soldbyid =" + id + "  and ow.solddate ='" + dateCompleted+ "' and o.classcodeid=" + classid + " ";       ...

Merging Data with LINQ

var terms = from t in HRSystemDB . Terminations select new { Month = t . TerminationDate . Month , Year = term1 . TerminationDate . Year , IsHire = false }; var hires = from emp in HRSystemDB . Persons . OfType < Employee >() select new { Month = emp . HireDate . Month , Year = emp . HireDate . Year IsHire = true }; // Now we can merge the two inputs into one var summary = terms . Concat ( hires ); // And group the data using month or year var res = from s in summary group s by new { s . Year , s . Month } into g select new { Period = g . Key , Hires = g . Count ( info => info . IsHire ), Terminations = g . Count ( info => ! info . IsHire ) }

C#, MVC Tips and Stuff

A list of things that I have found handy to know... Tip #1 Boolean Enum Comparison Not to return an enum value from say an abbreviation to a long string but just to determine if your value is a valid value in the enum list.  So you have your Enums declared in a base class or some other class something like this:  public enum MyCustomEnumGroup     {         ABC,         MQP,         RAD,         STY     } Then wherever you need  to check your string to see if the string you are passing in is in the Enum Group call it as shown below, this returns a boolean based on the match to the enumgroup.   if (Enum.IsDefined(typeof(MyCustomEnumGroup),mystringtopassin))