Quantcast
Channel: Kentico CMS for ASP.NET - DevNet - Forums - Version 7.x - API
Viewing all 660 articles
Browse latest View live

Setting up a custom event handler to delete a customer when a user is deleted

$
0
0
SYDA Developer LV
The only customers that should exist on our site should be attached to a user account. At present, when an account is deleted in CMS Desk, the customer that was attached to the user is not deleted.

This is not a problem.

The problem is that we have attempted to write a custom global event handler to delete the customer when a user is deleted. Unfortunately, the customer's CustomerUserID property is given a value of null before an event handler that triggers on UserInfo.TYPEINFO.Events.Delete.Before can fire, and so we are unable to find the customer associated with the user using CustomerInfoProvider.GetCustomerInfoByUserID. While a conversation with Kentico support has convinced me that our only options are to add a column to the CMS_User table and/or customer table OR to use CustomerInfoProvider.GetCustomers, I was wondering if anyone had been able to find another solution to the problem. I'd prefer to not use either method, to be honest, but I may end up using GetCustomers if I have to.

RE:Setting up a custom event handler to delete a customer when a user is deleted

$
0
0
SYDA Developer LV
Full code of our event handler:

private void UserInfo_Delete_Before(object sender, ObjectEventArgs e)
{
if (e.Object != null)
{
UserInfo userInfo = (UserInfo)e.Object;
int userID = userInfo.UserID;

CustomerInfo customerInfo = CustomerInfoProvider.GetCustomerInfoByUserID(userID);

if (customerInfo != null)
{
CustomerInfoProvider.DeleteCustomerInfo(customerInfo.CustomerID);
LogMessage("Customer id " + customerInfo.CustomerID + " has been deleted with User:" + userID);
}
}
}

getting author information in app code

$
0
0
yogasukma
hi guys,

i want to make notifier to user author when document update using custom event handler (full post here http://devnet.kentico.com/Forums/f65/fp5/t40917/notify-author-when-his-post-updated.aspx)

now i am success to send email when document updated, bot now the problem is i can't get author of document.

i use CMS.CMSHelper.CMSContext.CurrentUser.UserName but it give me username of user active, i want to get the email of author document so i can send email to him.

anyone have idea?

Question about external authentification

$
0
0
robert.siklenka-syzag
Hello, I need to integrate external authentification to my Kentico Project. I want to do some http request on Logon Form after logon button click that validate my credentials and then when my Response OK is do logon or Registration if it is a new user. Have you any ideas how to do this?
Thanks Robert

RE:Question about external authentification

$
0
0
Kentico_RichardS
Hi,

Thank you for your message.

In this case I would recommend you to create your own webpart as per http://devnet.kentico.com/docs/devguide/index.html?developing_web_parts.htm which will have some input text boxes and log in button which on click fire your code. You will need to code this webpart as per your needs.

Once you have your authentication sorted out you can insert/authenticate the user using our API in UserInfo, UserInfoProvider and AuthenticationHelper classes. You can see examples of all those actions at http://devnet.kentico.com/docs/devguide/membership_api_examples_managing_users.htm

Let us know for further assisance.

Kind regards,
Richard Sustek

RE:Question about external authentification

$
0
0
Robert-SYZ
Hello Richard,
thanks for your answer it was very helpful.
Best regards Robert

Indexing: how to Exclude linked Documents

$
0
0
Luca
Hi,

I have a structure that looks like this:

- User1
--- Documents
--- LinkedDocuments
- User2
- Documents
--- LinkedDocuments
...

Documents folders contain documents while LinkedDocuments folder contain linked documents

I need to define a search index only for documents

1) I tried to set a selection path like this "/%/Documents/%" but it didn't work (any suggestions?)

2) I could also set the path "/%" but i need a way to exclude Linked documents so as the smart search won't list linked documents. How can i perform it?


Thank you

RE:Indexing: how to Exclude linked Documents

$
0
0
Luca
I'm sorry

I've done a mistake, the expression "/%/Documents/%" works

Luca

Checkbox list Custom CMS Form user control

$
0
0
rooossone
Hi All,

I have used the following two sources to try and achieve what I need:

http://devnet.kentico.com/Forums.aspx?forumid=62&threadid=28842
&
http://devnet.kentico.com/docs/devguide/index.html?developing_form_controls.htm

I am trying to populate the list with a collection of values I draw from a Db table. I then want the selected values to be stored by ketico for later use via the API.

The page_load event ensures that the checkbox list contains items. I think where I start getting confused is how I need to override Value and IsValid to created this comma separated list of selected values to store in kentico.

I have been able to build it and add the control in kentico, I am also confused and unable to find much information on the meaning and context of the control scope fields and also the properties on the next tab.

I followed what was described in the documentation and added the control to a doc type's form. when i goto edit data i just get a message saying there was an error loading the control and i get no further info, I also tried debugging kentico to run through it step by step and no luck in tracking my problems....

My question is essentially, I Know I am doing something wrong so how do i set up a checkboxlist user control in kentico? can anybody provide some demo code dealing with this or point me in the right direction?

How to uncheck inherit in metadata page setting

$
0
0
dm
I have a page (menu item) with child docs in them. From page I originally had inherit page description and page keywords checked so all child docs are inheriting these. I no longer want this I would like to set page description and keyword on parent Page but do not want existing or new child docs to inherit. I tried unchecking inherit from parent page but existing child docs still inherits from page. I do not want to manually uncheck inherit from all child docs since I have 200+ child docs. Any ideas on how I can uncheck inherit on child docs programmatically? Or alternative solutions?

RE:MVC route priority

$
0
0
kentico_zdenekc
Cheryl,

The current plan to include route/alias priorities is still open in the longer term, but it will require more demand from Kentico CMS developers and users in order to be added in the next version. Hereby, I'd like to kindly ask you to add a feature requirement to the Kentico UserVoice page - I believe others will join, supporting the required attention.
Thank you in advance for your cooperation.

Kind regards,
Zdenek

RE:Web service return as JSON

$
0
0
kentico_zdenekc
Hi,

You need to serialize the data first. In our REST service, we use
public static string ToJSON(this DataSet ds, bool includeName)

from CMS.GlobalHelper.Extensions namespace

This method exports DataSet to JSON string, ds is DataSet to export and includeName indicates, if name of the dataset and names of the tables should be included in the result.
Hope this will help.

Regards,
Zdenek

document status field in dbo.CMS_Document

$
0
0
yogasukma
hi all, i've used qlHelperClass.ExecuteQuery() to query direct to database.
i want to make conditional with where statement.

my problem is i cant find which one of field in dbo.CMS_Document tabel that signed the document was approved or not?

anyone has known it before me?

thx

RE:GetSearchedContent in API

$
0
0
kentico_romank
Hi,

Could you please check the following file ~/CMSModules/SmartSearch/Controls/SearchResults.ascx.cs. In that file around the line 1401 there is "DataSet results = SearchHelper.Search(parameters);", this dataset contains records from index, that means it contains fields marked as searchable plus some internal fields. If you want to render the results, you can use the dataset and get the real objects from database via this dataset or you can use repeater and aply transformation to it, this transformation will generate JSON format as you need.

Please note, when you perform the search through API it is important to set search parameters (see line 1378).

Best Regards,
Roman Konicek

Role with a space

$
0
0
kelly-lion
Dealing with a database that has been upgraded from 6 to 7. Consultant created a role with a space in it and provided us with tools to manage membership in that role.

Now, on version 7, the tool errors out with

Unhandled Exception: CMS.DataEngine.CodeNameNotValidException: The object code n
ame 'Active Member' is not valid. The code name can contain only alphanumeric ch
aracters, some special characters (_, -, .) and cannot start or end with '.'.
at CMS.DataEngine.AbstractInfoProvider`2.SetInfo(InfoType info)
at CMS.SiteProvider.RoleInfoProvider.SetRoleInfoInternal(RoleInfo roleInfoObj)
at CMS.SiteProvider.RoleInfo.SetObject()
at CMS.SettingsProvider.BaseInfo.SetParent(GeneralizedInfo parent)
at CMS.SettingsProvider.BaseInfo.TouchParent()
at CMS.Synchronization.SynchronizationHelper.TouchParent(BaseInfo infoObj, TaskTypeEnum taskType)
at CMS.Synchronization.SynchronizedInfo`1.DeleteData(Boolean logObjectChange)
at CMS.DataEngine.AbstractInfoProvider`2.DeleteInfo(InfoType infoObj)
at CMS.SiteProvider.UserRoleInfoProvider.DeleteUserRoleInfoInternal(UserRoleInfo infoObj)
at CMS.SiteProvider.UserRoleInfoProvider.RemoveUserFromRole(UserInfo ui, RoleInfo ri)
at CMS.SiteProvider.UserRoleInfoProvider.RemoveUserFromRole(Int32 userId, Int32 roleId)

Any quick way to fix this since the role is still in use on the site?
Thanks,
Kelly

Authentication in Kentico using REST API

$
0
0
poplooukhin-gmail
Hi all

I'm a newbie in Kentico
I have a ASP.NET Services with REST API. I want use Kentico's authentication in my services using REST API of Kentico.

I cannot find sample of request to REST API of Kentico for authentication.

Also, I want to know how I can restore a password for user using REST API of Kentico

Thanks

RE:Setting up a custom event handler to delete a customer when a user is deleted

$
0
0
kentico_edwardh
Hello,

There is no UserID for the E-commerce customers; there is only the CustomerID which has no relation to the actual UserID since users and customers are two separate objects. You can use the methods below to delete both the Customer and the User records for a given user which doesn’t rely on there ID.

private bool DeleteCustomer()
{
// Prepare the parameters
string where = "CustomerLastName LIKE N'My New%'";

// Delete user
UserInfo user = UserInfoProvider.GetUserInfo("My new user");
UserInfoProvider.DeleteUser(user);

// Get the data
DataSet customers = CustomerInfoProvider.GetCustomers(where, null);
if (!DataHelper.DataSourceIsEmpty(customers))
{
foreach (DataRow customerDr in customers.Tables[0].Rows)
{
// Create object from DataRow
CustomerInfo deleteCustomer = new CustomerInfo(customerDr);

// Delete the customer
CustomerInfoProvider.DeleteCustomerInfo(deleteCustomer);
}
return true;
}
return false;
}


private bool DeleteUser()
{
// Get the user
UserInfo deleteUser = UserInfoProvider.GetUserInfo("MyNewUser");

// Delete the user
UserInfoProvider.DeleteUser(deleteUser);

return (deleteUser != null);


Otherwise, you could consider using the ObjectEvents.Delete.Before event instead of the UserInfo.TYPEINFO.Events.Delete.Before event as you have planned, since both the User and Customer are objects. The CustomerUserID should still be available in this handler.

RE:Role with a space

$
0
0
FroggEye
Is the role dependent on a 3rd party or external system? If not, I'd simply make the modification to the role name and code name and fix any code behind if needed. That would be a more robust fix/solution than attempting to work around the broken code someone else created.

RE:document status field in dbo.CMS_Document

$
0
0
FroggEye
There isn't approved info in that table. Those are version and workflow records you are looking for. I wouldn't use the .ExecuteQuery() method as you can use the API for Versioning and Workflow to get that information based on a document or node. I'd suggest downloading the API documentation as it will have what you need. Also check out the API Examples within your local install, you can find examples of how to use the API to get Version and Workflow data.

RE:CMS Repeaters & LINQ

$
0
0
pnmcosta
Any update on this?

I have a similar scenario, where previously we used a CMSRepeater with a Path query.

However, now we want to manually filter the data, so I though that constructing a TreeNode from the DataRow would solve it, but unfortunately keep getting:

[CMSAbstractTransformation.DataBind]: Object reference not set to an instance of an object.

Probably cause the transformation methods (e.g. GetDocument) are not working.

The helper method that queries for the next property:
public static object GetNextProperty(TreeNode currentProperty)
{
TreeProvider tree = new TreeProvider();
var ds = tree.SelectNodes(CMSContext.CurrentSiteName, currentProperty.Parent.NodeAliasPath + "%",
CMSContext.CurrentDocumentCulture.CultureCode, true, "Custom.Property");
if (!DataHelper.DataSourceIsEmpty(ds)
&& ds.Tables[0].Rows.Count > 1)
{
int i = 0;
foreach (DataRow item in ds.Tables[0].Rows)
{
if (item["NodeAliasPath"].ToString() == currentProperty.NodeAliasPath)
break; // current!
i++;
}

i = i + 1; // next!

if (i >= ds.Tables[0].Rows.Count) // last?
i = 0; // first!

return new TreeNode[] { TreeNode.New(ds.Tables[0].Rows, "Custom.Property", tree) };
}
return null;
}

The repeater in a web part
     <cms:CMSRepeater ID="repRelated" runat="server" 
TransformationName="Custom.Property.propertylistitem_other"
DelayedLoading="true" DataBindByDefault="false" />

The method to bind the repeater invoked in the web parts Page_Load event
private void BindRepeater()
{
repRelated.DataSource = PropertyFunctions.GetNextProperty(CurrentDocument);
repRelated.ReloadData(true);
}

The transformation "Custom.Property.propertylistitem_other":

<div class="property-other">
<a href="<%# GetPropertyDetailUrl(true) %>"><%# IfImage("PropertyThumbnail", GetImage("PropertyThumbnail", 220), "<img src=\"~/App_Themes/Custom/Images/property_no_image.jpg\" alt=\"" + HTMLEncode(Eval("PropertyTitle").ToString()) + "\" />") %></a>
<div class="clearfix">
<%# IfId(Eval("PropertyAreaId"), "<h3 class='left'>" + GetPropertyAreaName(Eval("PropertyAreaId")) + "</h3>") %>
<h3 class="right"><%# GetPropertyPriceFormatted()%></h3>
</div>
<h2><a href="<%# GetPropertyDetailUrl(true) %>"><%# HTMLEncode(Eval("PropertyTitle").ToString()) %></a></h2>

</div>

Any help on trying to get the transformations to work on a manually bound repeater would be great!
Viewing all 660 articles
Browse latest View live