Not able to insert the customer SeName in UrlRecord Table in nopcommerce - nopcommerce

Currently i am stucked in one point that when the customer completes its registration process what i want to do is Create a SeName from customers email address and store it in UrlRecord Table so that i can enable navigation to customers profile page. Below is the code that i had tried till now.
string CustomerSeName = "";
var CustomerModel=_customerService.GetCustomerById(_workContext.CurrentCustomer.Id);
if (CustomerModel != null)
{
CustomerSeName = customer.ValidateSeName(CustomerSeName, CustomerModel.Email, true);
_urlRecordService.SaveSlug(CustomerModel, CustomerSeName, 0);
}
in above code i am getting all the value in CustomerModel and CustomerSeName but when it executes SaveSlug() method it throws an Object reference not set error. I dont know which value it missing.Please help me out if someone knows the solution. Thanks in advance..!

I tried your code and couldn't compile.
After adding ISlugSupported to Customer entity and using this code all worked
private void GenerateCurrentCustomerSlug()
{
var slug = _workContext.CurrentCustomer.ValidateSeName(seName: "", name: _workContext.CurrentCustomer.Email, ensureNotEmpty: true);
_urlRecordService.SaveSlug(_workContext.CurrentCustomer, slug, languageId: 0);
}
The above code also works if there is no email set for current customer.

Related

Inconsistent results when listing groups an external account belongs to

Our Google domain has groups (synced copies of our Active Directory email listservs/distribution groups) that have a lot of external accounts (currently kept as contacts in Active Directory).
As part of an intranet site I'm building I'm trying to be able to do mass search and replace of individual contact email address when for example a school district changes its domain name. One of the visual/verification steps I'm working on is to list the Google group membership of any selected external account, but I'm getting mixed results. For some accounts it seems to list the groups properly, and for others it doesn't seem to pull any. I have verified the external account's group membership in both Active Directory and in Google Admin group management, but when I query Google via code I don't get valid results every time... What am I missing? Code below.
-- in Global.asax
public static List<string> GOOGLE_GetListOfUsersGroups(string useremail)
{
List<string> groupList = new List<string>();
try
{
///stripped out credential/service stuff...
var groups = service.Groups.List();
groups.UserKey = useremail;
Groups gs = groups.Execute();
if (gs != null)
{
foreach (Google.Apis.Admin.Directory.directory_v1.Data.Group g in gs.GroupsValue)
groupList.Add(g.Email);
}
}
catch (Exception ex)
{
SendERROREmail("GLOBAL<HR>GOOGLE_GetListOfUsersGroups()<HR>useremail:" + useremail + "<HR>" + ex.ToString());
}
return groupList;
}
and the consuming function:
--- in Page.aspx
protected void ddlADExternalContacts_SelectedIndexChanged(object sender, EventArgs e)
{
lbContactsGoogleGroups.Items.Clear();
if (ddlADExternalContacts.SelectedIndex > 0)
{
//show what google has for same group
List<string> memberList = Global.GOOGLE_GetListOfUsersGroups(ddlADExternalContacts.SelectedValue);
if (memberList != null)
{
foreach (string s in memberList)
lbContactsGoogleGroups.Items.Add(new ListItem(s, s));
}
}
}
Also, does anyone have a good example how to handle this in Google's 'preferred' JSON format rather then the API route?
UPDATE: Ok, its not my code, its something with the group/Google. When I use the 'try it' functionality on the sdk admin site I get the same results for groups that work (in my code and their site) and no results from the same groups that should be showing results...
{
"kind": "admin#directory#groups",
"etag": "\"HKdfSgTnCxrWl3RtRnlZSCPY3NjdWJxz53nrhwSz7ob4/oMWMqbsluP5m2PCo8Y7WmWeHGP4\""
}
Not that that helps me any, as there's no error or anything, just the 'no groups' result as if it can't find the external account...
UPDATE2: Ok, based on what I'm seeing after some testing, I have a sneaky suspicion that Google is doing some validation of emails before checking for group membership and reporting anything. I.E. if the email being searched for is no longer valid (client's server doesn't responds that the account is reachable/enabled/exists...), it won't bother going any further... will try it out with a few more email addresses that I know should be invalid and update....later.
It looks like what you are experiencing might be a bug.
This has been reported on Google Issue Tracker here.
What you can do in this situation is to star the issue above and eventually add a comment saying that you are affected by it.

Changelog method based on project tracker template

Based on the project tracker I have integrated a changelog into my app that relates my UserSettings model to a UserHistory model. The latter contains the fields FieldName, CreatedBy, CreatedDate, OldValue, NewValue.
The relation between both models works fine. Whenever a record is modified, I can see the changes in a changelog table. I now want add an "undo"-button to the table that allows the admin to undo a change he clicks on. I have therefore created a method that is handled by the widget that holds the changelog record:
function undoChangesToUserRecord(changelog) {
if (!isAdmin()) {
return;
}
var fieldName = changelog.datasource.item.FieldName;
var record = changelog.datasource.item.UserSettings;
record[fieldName] = changelog.datasource.item.OldValue;
}
In theory method goes the connection between UserHistory and UserSettings up to the field and rewrites its value. But when I click on the button, I get a "Failed due to circular reference" error. What am I doing wrong?
I was able to repro the issue with this bit of code:
google.script.run.ServerFunction(app.currentPage.descendants.SomeWidget);
It is kinda expected behavior, because all App Maker objects are pretty much complex and Apps Script RPC has some limitations.
App Maker way to implement it would look like this:
// Server side script
function undoChangesToUserRecord(key) {
if (!isAdmin()) {
return;
}
var history = app.models.UserHistory.getRecord(key);
if (history !== null) {
var fieldName = history.FieldName;
var settings = history.UserSettings;
settings[fieldName] = history.OldValue;
}
}
// Client side script
function onUndoClick(button) {
var history = widget.datasource.item;
google.script.run
.undoChangesToUserRecord(history._key);
}

Panel using stored procedure - Code not reacting as expected

I have hit a small issue and hoping someone might be able to assist. I am using a panel - On the page load, it should list all the products as no category has been selected as per stored procedure (this works perfectly).
When a user clicks on a specific category, it should only show the products that have the specific CategoryID. When I run the code in SQL, it works a dream for this part too, so assume the stored procedure is ok.
At
CategoryID = CategoryID
in GetProducts, I get
Warning: Assignment made to same variable; did you mean to assign something else?
However I am following a tutorial video and this works fine. Is there another silly error that is preventing it from working?
I think I have included all the required code - sorry if its a bit overkill!!
Thanks as ever in advance - Jack
Code behind pnlCategories:
private void GetProducts(int CategoryID)
{
ShoppingCart k = new ShoppingCart();
{
CategoryID = CategoryID;
};
Error identified - additional ";" added at following line:
ShoppingCart k = new ShoppingCart();
Code now reads
ShoppingCart k = new ShoppingCart()
{
CategoryID = CategoryID
};
and functions as expected!
that looks like a c# error and not a SQL Server error.
The problem is here in your GetProducts method. CategoryID = CategoryID;
C# is case sensitive. If you check your tutorial carefully, one of these will probably be lower case. Make sure you type that carefully.
try code change below and see where the compiler complains.
CategoryID = categoryID;
private void GetProducts(int CategoryID)
{
ShoppingCart k = new ShoppingCart();
{
CategoryID = CategoryID;
};
dlProducts.DataSource = null;
dlProducts.DataSource = k.GetProdcuts();
dlProducts.DataBind();
}

How to get all user list from orchard

I need to get all of users with their Ids whose are created by orchard admin panel. Now I need all list and I will use it in another service.
Or, I want to get Orchard user table "[Orchard_Users_UserPartRecord]" from entity framework like this code
public IList<UserAttendance> ShowAllUserAttendance()`enter code here`
{
using (UserAttendanceDbContext _db = new UserAttendanceDbContext())
{
return _db.UserAttendances.ToList();
}
}
How can I do it?
Thanks,
kibria
See following.
var userProfiles = _contentManager.Query<UserPart, UserPartRecord>() .List() .Select(user => ((dynamic) user).ProfilePart) .Select(user => new {user.FirstName, user.LastName});
For more details visit following link.
http://orchardprofile.codeplex.com/discussions/271879

Data Format Error in Asp.net

I want to set my Salary field value into $23,000.00 and send that value into my database ,i created below code inside my model class but it has some errors need some one help to fix that errors,I am new to Asp.net MVC4 Please help me to solve that problems.
when i save data it goes to database like that way- $23000
but actually i want to send like that way -$23,000.00
when i view my results in my view page it seems $$23000
But i want that way - $23,000.00
Please help me to solve that problems.
Thanks .
public string Salary
{
get
{
return SalaryFormat;
}
set
{
StringBuilder sb = new StringBuilder();
SalaryFormat = Convert.ToString(sb.AppendFormat("${0: #,###.00}", value));
//SalaryFormat = value;
}
}
Thanks!

Resources