Sunday, August 18, 2013

Declare a Predicate Delegate inline (options)

  • explicit delegate:
myObjects.RemoveAll(delegate (MyObject m) { return m.X >= 10; });

  • lambda
myObjects.RemoveAll(m => m.X >= 10);

Wednesday, May 29, 2013

List all Model ModelState Errors MVC


List<string> errorsList = new List<string>();
foreach (ModelState modelState in ViewData.ModelState.Values)
{
          foreach (ModelError error in modelState.Errors)
         {
            errorsList.Add(error.ErrorMessage);
         }
}
foreach (var item in errorsList)
{
       ModelState.AddModelError("", item);
}
     

Monday, April 1, 2013

AddThis reload on ajax load

run the code on ajax load, or put it on the end of file that is loaded


var addthis_url = "http://s7.addthis.com/js/250/addthis_widget.js#pubid=your_id";
if (window.addthis) {
    window.addthis = null;
    window._adr = null;
    window._atc = null;
    window._atd = null;
    window._ate = null;
    window._atr = null;
    window._atw = null
}
$.getScript(adthis_url)



From:
http://railsforum.com/viewtopic.php?id=50604

Wednesday, January 30, 2013

Change app behaviour when debug="true" on web.config


To check if debug="true" on web.config, check the following:

HttpContext.Current.IsDebuggingEnabled

Why should I care?

Take the example
try{
//a lot of code that makes something
}catch (Exception ex){
//Make the error handling of some sort, like log the error...
if(HttpContext.Current.IsDebuggingEnabled){
return ex.Message;
}else{
return "A error ocurred with the app, please retry again later or contact our it department";
}
}


Wednesday, January 23, 2013

Full intelisense mvc umbraco 6

From  @ twitter
Tip for   developers, when editing MVC Views in add " Umbraco.Web;" to top of cshtml for full Intellisense

Tuesday, January 8, 2013

Thursday, January 3, 2013

Url Picker uComponents

uComponents.DataTypes.UrlPicker.Dto.UrlPickerState picker = uComponents.DataTypes.UrlPicker.Dto.UrlPickerState.Deserialize(curr.GetProperty<string>("propAlias"));


string target = picker.NewWindow ? "_blank" : "_self";
string text = picker.Title;
string url = picker.Url;

Monday, November 19, 2012

Change textstring to multiple text string or richtexteditor

Just copy the data in dataNvarchar to dataNText (or vice-versa) in the table cmsPropertyData with the right  propertytypeid to have the content on the property in umbraco.

Force Republish umbraco

http://siteUrl/Umbraco/dialogs/republish.aspx?xml=true

Source:
http://our.umbraco.org/wiki/reference/api-cheatsheet/publishing-and-republishing

Thursday, November 1, 2012

Change Nodes Templates


select * from cmsDocument where nodeid in (select id from umbracoNode where parentId = 1207) and  newest = 1

update cmsDocument set templateid = 8663 where nodeid in (select id from umbracoNode where parentId = 1207 ) and  newest = 1

Tuesday, October 23, 2012

Get all Document types and Fields


select
umbracoNode.id as Id,
Text as DocumentTypeName,
cmsContentType.Alias as DocumentTypeAlias,
Name as FieldName,
cmsPropertyType.Alias as FieldAlias
from cmsPropertyType
inner join umbracoNode on cmsPropertyType.contentTypeId = umbracoNode.id
inner join cmsContentType on cmsContentType.NodeId = umbracoNode.id
order by text

Object Node Type Id's

'C66BA18E-EAF3-4CFF-8A22-41B16D66A972' - Content
'A2CB7800-F571-4787-9638-BC48539A0EFB' - Document Types
'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' - Media Cotent
'6FBDE604-4178-42CE-A10B-8A2600A2F07D' - Master Templates
'4EA4382B-2F5A-4C2B-9587-AE9B3CF3602E' - Media Types

Monday, October 22, 2012

Application_Start on umbraco


public class MyGlobal : umbraco.Global
{
    protected override void Application_Start(object sender, EventArgs e)
    {
        base.Application_Start(sender, e);

        // Insert your startup logic here
    }
}

in 

http://blog.mattbrailsford.com/2010/07/11/registering-an-application-start-event-handler-in-umbraco/

Wednesday, February 1, 2012

Friday, January 6, 2012

Get Url Left Part

HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);

Monday, December 12, 2011

Change url and title with Javascript ShareThis


addthis.update('share', 'url', url);
addthis.update('share', 'title', $("title").text());