Posts

Microsoft Deserves Some Credit

I am the first to point out system deficiencies and am happy to let you know that this morning I am ragging on no one. I have a new Surface Pro 3 and am loving it as McDonalds might say, this morning I am very happy with Microsoft for a different reason. At work we are using Team Visual Studio - phenomenal product, especially for remote workers.  My work computer, which is a mean laptop with 16 gigs of ram and a kick butt processor has Visual Studio 2012.  This morning I wanted to revisit a project I was working on so decided to try and connect my surface with VS 2013 to the project.  It was so absolutely seamless that it put a happy spin on the day ahead! Congrats to the Visual Studio Online team. So after investigating it looks like with VS 2012 Microsoft did something brilliant - they made the Visual Studio interface backward compatible thus not forcing an office to upgrade all developer software at once but more importantly allowing me to work at 5 in the mornin...

Membership and Looping through the Site Users in MVC with Razor

There are so few examples of this out there - it took me forever to find it but it was such a simple, elegant solution that I thought I would share. So in your Action you don't want to use the MembershipCollection directly as it will return a string that will not be IENumerable - instead you will want to use your UsersContext This will go in your Controller     [Authorize(Roles = "Admin")]         public ActionResult MembersIndex()         {             using (var ctx = new UsersContext())             {                 return View(ctx.UserProfiles.OrderBy(x => x.UserId).ToList());             }         } Then in your Razor MVC Page you will do something like this:       @foreach ( var user in Model){         @user.UserName  - @...

An Open Letter to Microsoft

Dearest Microsoft, We have been the best of friends for many years.  I have built my career around your technologies, been an advocate for your software, shared information on your hardware and participated in your MVP program (twice!).  It is out of this deep appreciation for you that I write to you today. I just purchased the Surface Pro 3 - and I love it - but that is not what this letter is about. Your store (microsoftstore.com) could use a revamp.. The deficiencies as I see them are primarily with the customer specific pages, once the customer is signed in. The view on the primary page and the order page is not in a grid as one might expect when supplying this type of information nor is it laid out in a manner easily read, in fact the page is so poorly designed that if you have three orders with 3 items each you have to actually go to the next page to see the third order,  I can't imagine the difficulty if someone had 10 or more orders.  Not only is th...

Data Entity Random Database Record

You've seen those random quotes on pages, probably most of them are done with Javascript.  This one is done using a database table (three fields, id, linenumber,linetext) and a data entity call and features the SKIP method. You have to have an orderby in your query to be able to use SKIP So put a label on the page or webcontrol and format it as you wish From the page load call the function to get the data lblRandom.InnerText = getrandomvalue();  public string getrandomvalue()         {             using (my_maintenanceEntities context = new my_maintenanceEntities())             {                 var query = (from c in context.tbl_texttable                              orderby c.LineNumber                       ...

Another Conditional Linq for int values

I have a dropdown list where the first selection is to return ALL Records and the value is 0 otherwise they make a selection and it returns the equivalent integer. Here is how I worked it out in my Linq query The dropdown is passing into a variable called ClassCodeID  && (ClassCodeID.Equals(0) || s.ClassCodeID >= ClassCodeID || s.ClassCodeID == ClassCodeID) And that seemed to work... however when returning values it did not roll up the values as I expected since classcodeID was not in the groupby.. it only returned a record for a specific code but the values from all codes were rolled into the returned data.  I added an additional where statment and this seemed to have fixed the issue . where (ClassCodeID.Equals(0) || s.ClassCodeID == ClassCodeID

Linq Conditional Selection - handling 'like' in Linq

So the first request was to use  two date fields one optional dropdown value an optional textbox  value  Below is the first query I created which satisfied this request.   But scope creep raised its ugly head and the requirements were changed..  Now I need to provide results for either an 'empty' textbox or any entry such as the first couple of letter with  results similar to a "Like" statement - the second example shows how I changed to accommodate.  var dbRecords = (from c in context.tbl_mydata                             where (c.DateRan >= startdate && c.DateRan <= enddate)                                  && (string.IsNullOrEmpty(mnum) || string.Compare(c.MNumber, mnum, true) == 0)                     ...

Linq - Data Entities - Records by Max Date with CASE

Image
 I needed to get essentially a summary by case statement for a given date.  As you can see I have defined the MAX date into a variable.  This example also shows using a substring of the first character in a LET statement  DateTime? maxDate =                 (from a in context.tbl_tslog                 orderby a.CurrentTime                 select (DateTime?) a.CurrentTime ).Max(); var dbRecords = (from c in context.tbl_testlog                            where (c.CurrentTime >=maxDate)                                         let range = (  c.Usr.ToUpper().Substring(0,1) == "B" ? "US" :                     ...