I'm trying to figure out some code I got at one point that uses Ajax to get contacts from my feed, but I'm not sure how to access the group membership of said contacts to display that info elsewhere.
Here's a little snippet of my code:
//user is a specific contact
//options is an array var
//names is an array var
//phones is an array var
//groups is an array var
if (user.gd$email == null) options.push("");
else options.push(user.gd$email[0].address);
if (user.title.$t == null || user.title.$t == "" ) names.push(options[i]);
else names.push(user.title.$t);
if (user.gd$phoneNumber == null) phones.push("0");
else phones.push(user.gd$phoneNumber[0].$t);
//this is the code I added based on the 3 existing if-elses above
if (user.gd$groupMembershipInfo == null) groups.push("");
else groups.push(user.gd$groupMembershipInfo[0].$t);
Related
I've tried a few different ways to do this and each way has a piece of code I am just not getting right. I need to update a custom field UsrCustomerShipAccount in Customer Locations if it is updated in the Customer Delivery Tab. I tried SetValueExt and creating a graph instance. Sorry about the dumb question.
The way that seemed to get me the closest is below:
protected void LocationExtAddress_UsrCustomerShipAccnt_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (LocationExtAddress)e.Row;
if (row == null) return;
PXSelectBase<Location> locationObj = new PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>(Base);
Location deliveryLocation = locationObj.Select(row.LocationBAccountID);
var locationExt = PXCache<Location>.GetExtension<LocationExt>(location); <-- This generates error that there is no LocationExt.
deliveryLocation.Cache.SetValueExt(deliveryLocation, "UsrCustomerShipAccount", -->This needs to be the value that changed LocationExtAddress.UsrCustomerShipAccount but I don't see how to get this<--);
deliveryLocation.Cache.IsDirty = true;
deliveryLocation.Update(deliveryLocation); <--I don't know if this doesn't work because it is wrong or if it is because "UsrCustomerShipAccount" is not in deliverLocation.
}
You have
var locationExt = PXCache<Location>.GetExtension<LocationExt>(location);
shouldn't this be
var locationExt = PXCache<Location>.GetExtension<LocationExt>(deliveryLocation );
?
I am consuming wcf service into angular js application. I wrote linq query to check user information . If the is not null then query should catch the information and return true otherwise its should return false . But the problem is its always returns false and catch values null
Here is the linq Query .
public bool CreateCurrentAccountCheck(Current_Account_Holder_Details current_Account_Details)
{
using (HalifaxDatabaseEntities context =new HalifaxDatabaseEntities())
{
var query = (from x in context.Current_Account_Holder_Details
where x.Account_Holder_First_Name == current_Account_Details.Account_Holder_First_Name && x.Account_Holder_Last_Name == current_Account_Details.Account_Holder_Last_Name
&& x.Account_Holder_DOB == current_Account_Details.Account_Holder_DOB && x.Account_Holder_House_No == current_Account_Details.Account_Holder_House_No
&& x.Account_Holder_Street_Name == current_Account_Details.Account_Holder_Street_Name && x.Account_Holder_Post_Code == current_Account_Details.Account_Holder_Post_Code
select x).FirstOrDefault();
if (query!=null)
{
return true;
}
else
{
return false;
}
}
}
Here is the screen shot on debugging Mode .
The problem is pretty clear that there is no matched record with the where clauses. Also, you want to check the record and you should check it with using an unique id instead of other required or not required fields. It is the exact way to apply it. You should have some kind of unique AccountDetailId or other name which applies unique info for the records.
var query = (from x in context.Current_Account_Holder_Details
where x.AccountDetailId == current_Account_Details.AccountDetailId
select x).FirstOrDefault();
The code I use to filter my objects is like:
var dynamicdataentrances = db.DynamicDataEntrances.OrderByDescending(d => d.ID)
.AsQueryable();
if (TypeID != null)
dynamicdataentrances =
dynamicdataentrances.Where(d => d.DetailPageID == TypeID).AsQueryable();
if (RegionID != null)
dynamicdataentrances =
dynamicdataentrances.Where(d => d.RegionID == RegionID).AsQueryable();
if (ShiftGroupID != null)
dynamicdataentrances =
dynamicdataentrances.Where(d => d.ShiftPlan.ShiftGroupID == ShiftGroupID)
.AsQueryable();
And it works without any problems. However, filtering the objects according to "Workflow State" doesn't work. The code for it is like:
foreach (var wfs in workflowstates)
{
if (Request[wfs.ID.ToString()] != wfs.ID.ToString())
dynamicdataentrances =
dynamicdataentrances.Where(d => d.WorkflowStateRelation.WorkflowStateID
!= wfs.ID).AsQueryable();
}
As you can figure out, I use checkboxes for filtering; If Workflow State's checkbox isn't checked, I get the objects whose Workflow State isn't equal to unchecked one. I debugged the lines, foreach and if blocks are working correct, but the query doesn't work accordingly, it keeps getting all the objects. Is this a bug or am I doing something wrong?
If I turn my object collection to List before the Workflow State filtering, it works correctly.
With List it works, because the objects are already in the memory and not equal ones are ruled out for every non-checked state.
However, with IQueryable the objects are on the database, and the query gets all the objects, because they aren't ruled out from the list on each step.
I got the solution with:
var unCheckedStates = new List<int>();
foreach (var wfs in workflowstates)
{
if (Request[wfs.ID.ToString()] != wfs.ID.ToString())
{
unCheckedStates.Add(wfs.ID);
}
}
dynamicdataentrances =
dynamicdataentrances.Where(d => !unCheckedStates
.Contains(d.WorkflowStateRelation.WorkflowStateID))
.AsQueryable();
I was doing project in MVC3 with Entity framework. I have a LINQ query with foreach. Everything is fine. But when the data size goes up, i was facing performance issues. I dont have much experience with LINQ. So I couldn't fix my issue. Pls have a look at my code and provide a better suggestion for me.
Code
List<int> RouteIds = db.Cap.Where(asd => asd.Type == 3).Select(asd => asd.UserId).ToList();
var UsersWithRoutingId = (from route in db.RoutingListMembers
where RouteIds.Contains(route.RoutingListId.Value) && route.User.UserDeptId == Id
select
new RoutingWithUser
{
UserId = route.UserId,
RoutingId = route.RoutingListId
});
var ListRouteValue = (from cap in db.CareAllocationPercents
where cap.Type == 3
select new UserWithDeptId
{
Year = (from amt in db.CareAllocations where amt.CareItemId == cap.CareItemId select amt.Year).FirstOrDefault(),
UserId = cap.UserId,
UserDeptId = (from userdept in db.Users where userdept.Id == cap.UserId select userdept.UserDeptId).FirstOrDefault(),
});
List<UserWithDeptId> NewRouteList = new List<UserWithDeptId>();
ListRouteValue = ListRouteValue.Where(asd => asd.Year == Year);
foreach (var listdept in ListRouteValue)
{
foreach (var users in UsersWithRoutingId)
{
if (users.RoutingId == listdept.UserId)
{
UserWithDeptId UserwithRouteObj = new UserWithDeptId();
UserwithRouteObj.UserId = users.UserId;
UserwithRouteObj.Year = listdept.Year;
UserwithRouteObj.UserDeptId = db.Users.Where(asd => asd.Id == users.UserId).Select(asd => asd.UserDeptId).FirstOrDefault();
NewRouteList.Add(UserwithRouteObj);
}
}
}
NewRouteList = NewRouteList.Where(asd => asd.UserDeptId == Id).ToList();
Thanks,
You have to use join in first statement. Examples of how to do this are for example here: Joins in LINQ to SQL
I have some idea for you:
First:
Take care to complete your where close into your linq query to get just what you need to.
With Linq on collection, you can remove one foreach loop. I don't know the finality but, i've tryied to write something for you:
var UsersWithRoutingId = (from route in db.RoutingListMembers
where RouteIds.Contains(route.RoutingListId.Value) && route.User.UserDeptId == Id
select
new RoutingWithUser
{
UserId = route.UserId,
RoutingId = route.RoutingListId
});
var ListRouteValue = (from cap in db.CareAllocationPercents
where cap.Type == 3
select new UserWithDeptId
{
Year = (from amt in db.CareAllocations
where amt.CareItemId == cap.CareItemId && amt.Year == Year
select amt.Year).FirstOrDefault(),
UserId = cap.UserId,
UserDeptId = (from userdept in db.Users
where userdept.Id == cap.UserId && userdept.UserDeptId == Id
select userdept.UserDeptId).FirstOrDefault(),
});
List<UserWithDeptId> NewRouteList = new List<UserWithDeptId>();
foreach (var listdept in ListRouteValue)
{
var user = UsersWithRoutingId.Where(uwri => uwri.RoutingId == listdept.UserId).FirstOrDefault();
if (user != null)
{
NewRouteList.Add(new UserWithDeptId { UserId=user.UserId, Year=listdept.Year, UserDeptId=listdept.UserDeptId });
}
}
return NewRouteList
Is that right for you ?
(i don't poll the db.user table do get the UserDeptId for the NewRouteList assuming that the one in the listdept is the good one)
Second:
Take care of entity data loading, if you have tables with foreign key, take care to remove the lazy loading if you don't need the children of your table to be loaded at same time. Imagine the gain for multiple table with foreign key pointing to others.
Edit:
Here is a link that explain it:
http://msdn.microsoft.com/en-us/library/vstudio/dd456846%28v=vs.100%29.aspx
I am trying to learn how to reuse my Linqtotwitter result for reuse in my application.
Everything works fine except I am going to hit the ratelimit very quickly if I dont do a form of caching. I have 3 queries in my application that hits the twitter feed.
I tried to use the respository pattern at http://ardalis.com/introducing-the-cachedrepository-pattern but its way over my head and lets just say i didnt get far.
A sample controller from my code
[HttpGet]
public ActionResult PublicShouts()
{
var twitterCtx = new TwitterContext(Auth);
List<TweetViewModel> friendstweets = (from tweet in twitterCtx.Status
where tweet.Type == StatusType.User &&
tweet.ScreenName == "BattleShouts" &&
// tweet.InReplyToScreenName == "Battleshouts" &&
tweet.IncludeEntities == true &&
tweet.IncludeRetweets == true &&
tweet.IncludeContributorDetails == true &&
tweet.CreatedAt < DateTime.Now.AddDays(-30).Date
select new TweetViewModel
{
ImageUrl = tweet.User.ProfileImageUrl,
ScreenName = tweet.User.Identifier.ScreenName,
Tweet = tweet.Text
})
.ToList();
return PartialView(friendstweets);
I have also looked at this post How to cache data in a MVC application
How can I go about caching my results for later reuse so I dont hit the twitter limit?
Thank you
How about OutputCacheAttribute?
http://msdn.microsoft.com/en-us/library/system.web.mvc.outputcacheattribute.aspx
Look at VaryByCustom to have separate cache entry for each user.