+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to update Record in Module with out login

How to update Record in Module with out login

2 posts, 0 answered
  1. Ajay
    Ajay avatar
    46 posts
    Registered:
    14 Nov 2013
    18 Mar 2015
    Link to this post

    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();

     

  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    21 Mar 2015
    Link to this post
    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
     
2 posts, 0 answered