Update an Umbraco document's CreateDateTime in Razor? - razor

I'm trying to change the CreateDateTime for a node/document, but it doesn't appear to be having any effect. This is what I'm trying to far:
dynamic node = new DynamicNode(1065);
Document n = new Document(node.Id);
n.CreateDateTime = node.articlePublishedDate;
n.Save();
n.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(n.Id);
Am I going about this in the right way? And also, am I correct in assuming that it can even be changed? The API seems to suggest the CreateDateTime has get/set, so it should work? Running the code through with breakpoints, it updates the CreateDateTime, but something with the save/publish seems to revert it back?

Your code is deprecated, so you need to use the "new" ContentService in umbraco:
https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService
It should be something like this:
var cs = Services.ContentService;
var node = cs.GetById(1065);
node.CreateDate = DateTime.Now;
cs.SaveAndPublish(node);

Related

Umbraco MediaById not working as expected

Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
foreach (var id in #Model.sliders) {
var media = Model.MediaById(id.InnerText);
if (media != null){
var url = media.umbracoFile;
<p>name = #media.Name</p>
<p>alt = #media.altText</p>
<p>url = #media.umbracoFile</p>
<p>url = #url</p>
}
}
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
<img src="#Model.Media("topRightImage", "umbracoFile")" alt="#Model.Media("topightImage", "altText")" />
But that will only help if with the media picker data type, not mntp. It shouldnt' be that difficult, should it?
I can get the images to load if I rebuild the internal search index, but they're gone again on subsequent refreshes.
I've seen others having similar problems, and would really appreciate a solution...
ta
Nathan
This looks like a bug that was fixed in 4.7.2. See the following codeplex item:
http://umbraco.codeplex.com/workitem/30778

Start or End of week in Actionscript

I am looking for a way of getting the start of the week relative to today in Actionscript using (and currently stuck with) Flex 4.1. In Java I would do this using the Calendar class via:-
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.DAY_OF_WEEK,
1);
return cal.getTime();
I can't seem to find any solution that is anywhere as elegant - am I missing something?
There are two classes, of the same name, DateTimeFormatter. One is a pure Actionscript class, the other is a new class added to Flex 4.5 that wraps the Actionscript version. The Flex version does some of the heavy lifting for you.
There is a getFirstWeekday() method, it will be respective of the locale you specify.
[Edit]
I got carried away, didn't answer your question specifically. I'm not aware of anything more elegant than the DateTimeFormatter. But from there you can use a Date object to get the current time, and get what you're after.
There are a handful of date utilities, but I'm not aware of this particular solution. Are you looking for something like this:
var timeFormatter:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.NONE, DateTimeStyle.SHORT);
var firstDay:int = timeFormatter.getFirstWeekday()
var now:Date = new Date();
var dayDelta:int = now.day - firstDay;
var firstDayInMillis:Number = now.time - (dayDelta * 86400 * 1000);
// you can construct a new Date from here: var first:Date = new Date(firstDayInMillis);

How can I remove a contact CompleteName.Title with EWS managed api v1.1?

Using EWS managed api v1.1, I can successfully save/set the contact "Title" or honorific (if you prefer) to a non-empty value, but I can't figure out how to remove or set it back to an empty string/null.
I've tried to set an empty value and I've tried to remove the extended property. Here is relevant code.
var titleDef = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);
// works when set to a non-empty string value
ewsContact.SetExtendedProperty(titleDef, "Mr.");
// throws null argument exception when set to String.Empty or null
ewsContact.SetExtendedProperty(propDefinition, String.Empty);
// isRemoved is equal to false and the value doesn't change
var isRemoved = ewsContact.RemoveExtendedProperty(titleDef);
I've also tried to use a different overload on the ExtendedPropertyDefinition as mentioned in this very similar question, but it didn't change my end result for removing the property. I'm not sure I understand the difference in the two signatures for the constructor.
var titleDef = new ExtendedPropertyDefinition(new Guid("{00062004-0000-0000-C000-000000000046}"), 0x3A45, MapiPropertyType.String);
// isRemoved is equal to false and the value doesn't change
var isRemoved = ewsContact.RemoveExtendedProperty(titleDef);
Brute Force Work-Around
I suppose I could take a complete copy of the contact (without the title) and delete the original, but that seems a bit over the top and would probably cause other bugs.
EWS lets you assign Extended Properties without first binding them. However, to remove an Extended Property - you need to include it in your initial binding call PropertySet. The following worked for me...
var titleDef = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);
Contact contact = Contact.Bind(service, id, new PropertySet(titleDef));
contact.RemoveExtendedProperty(titleDef);
contact.Update(ConflictResolutionMode.AutoResolve);
It is also strange that you can retrieve the Title as a first-class property, but you cannot assign it (since it's a complex type). They could have made this easier for us.
var title = contact.CompleteName.Title;

AS3 How to make a kind of array that index things based on a object? but not being strict like dictionary

How to make a kind of array that index things based on a object? but not being strict like dictionary.
What I mean:
var a:Object = {a:3};
var b:Object = {a:3};
var dict:Dictionary = new Dictionary();
dict[a] = 'value for a';
// now I want to get the value for the last assignment
var value = dict[b];
// value doesn't exits :s
How to make something like that. TO not be to heavy as a lot of data will be flowing there.
I have an idea to use the toString() method but I would have to make custom classes.. I would like something fast..
Why not make a special class that encapsulates an array, put methods in there to add and remove elements from the array, and then you could make a special method (maybe getValueByObject(), whatever makes sense). Then you could do:
var mySpecialArrayClass:MySpecialArrayClass = MySpecialArrayClass();
var a:Object = {a:3};
var b:Object = {a:3};
mySpecialArrayClass.addElement(a,'value for a');
var value = mySpecialArrayClass.getValueByObject(a);
I could probably cook up a simple example of such a class if you don't follow.
Update:
Would something like this help?
http://snipplr.com/view/6494/action-script-to-string-serialization-and-deserialization/
Update:
Could you use the === functionality? if you say
if ( object === object )
it compares the underlying memory address to see if two objects are the same reference...

Linq to SQL : How do I get the property values from a query's results?

I m just starting with microsoft (MVC,C#, LINQ), so far so good, but i have a question about LINQ uses, How do i get the value form a LINQ like this one?
var x = from a in db.tablex
where a.eventID == eventID
select new
{
owner = a.owner,
shipper = a.shipper,
consignee = a.consignee
};
I try something like "r.owner" inside a foreach to get the value retrieved from DB
foreach (var r in x)
but its not working.. i dont get intellisense either.. how do i get the value??. I saw several examples and it seems to work like this, but for some reason its not working.. Thanks
Ok guys here was the thing, (it wasnt the typo it was just in the post), i was missing a using :
using System.Reflection;
with this C# automatically creates a class from them, and now it works
What a noob of me =).
foreach (var r in x)
{
var owner = r.owner;// not x.owner
}