How to update Record in Module with out login

Posted by Community Admin on 04-Aug-2018 13:29

How to update Record in Module with out login

All Replies

Posted by Community Admin on 18-Mar-2015 00:00

Hi All,

I'm Using Sitefinity 7.0 , i created Module with Module Builder,

Updating the Record Using Code , Its working if login to dashboard

otherwise it showing Error,

How to Update Record with Out Login?

Is there any way to pass Credentials to DynamicModuleManager in Coding?

 

here my code

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type contestantType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Student");
            DynamicContent contestantItem = new DynamicContent();
            contestantItem = dynamicModuleManager.GetDataItems(contestantType).Where("Visible==True").FirstOrDefault();
            DynamicContent master = dynamicModuleManager.Lifecycle.Edit(contestantItem) as DynamicContent;
            DynamicContent temp = dynamicModuleManager.Lifecycle.CheckOut(master) as DynamicContent;
            temp.SetValue("Age", 25);
            master = dynamicModuleManager.Lifecycle.CheckIn(temp) as DynamicContent;
            dynamicModuleManager.Lifecycle.Publish(master);
            dynamicModuleManager.SaveChanges();

 

Posted by Community Admin on 21-Mar-2015 00:00

Hello Ajay,

The way you can bypass Sitefinity's security is via wrapping your code inside an ElevatedModeRegion attribute. The code needed should go something like the following:

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
           using (new ElevatedModeRegion(dynamicModuleManager))
           
               Type contestantType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Student");
               DynamicContent contestantItem = new DynamicContent();
               contestantItem = dynamicModuleManager.GetDataItems(contestantType).Where("Visible==True").FirstOrDefault();
               DynamicContent master = dynamicModuleManager.Lifecycle.Edit(contestantItem) as DynamicContent;
               DynamicContent temp = dynamicModuleManager.Lifecycle.CheckOut(master) as DynamicContent;
               temp.SetValue("Age", 25);
               master = dynamicModuleManager.Lifecycle.CheckIn(temp) as DynamicContent;
               dynamicModuleManager.Lifecycle.Publish(master);
               dynamicModuleManager.SaveChanges();
           


Regards,
Ivan D. Dimitrov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed