Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private long FindRated(FormCollection form)
- {
- double weightThreshold = double.Parse(ConfigurationManager.AppSettings["contactThreshold"]);
- using (var db = new Entities())
- {
- List<string> contactValuesList = (from ric in _ratingInitialContacts
- where !String.IsNullOrEmpty(form["contact_" + ric.Key])
- select form["contact_" + ric.Key]).ToList();
- contactValuesList.AddRange(from string key in form.Keys
- where key.StartsWith("os_site")
- select int.Parse(key.Substring(("os_site").Length))
- into cn
- where !String.IsNullOrEmpty(form["os_username" + cn])
- select form["os_username" + cn]);
- var matchingContacts = db.rated_contact.Where(x => contactValuesList.Contains(x.value));
- if (matchingContacts.Any())
- {
- if (matchingContacts.Count() > 1)
- {
- //Compute weight to choose...
- var matchedThreshold = matchingContacts.Where(w => w.contact_type.weight >= weightThreshold);
- if (matchedThreshold.Any())
- {
- if (matchedThreshold.Count() > 1)
- {
- //multiple matching contacts, attempt to merge...
- return CreateMerge(from r in db.rateds
- join rc in matchedThreshold
- on r.ratedId equals rc.ratedId
- select r) * -1;
- }
- else
- {
- return matchedThreshold.First().ratedId;
- }
- }
- else
- {
- //none matched the threshold, attempt to merge...
- return CreateMerge(from r in db.rateds
- join rc in matchingContacts
- on r.ratedId equals rc.ratedId
- select r) * -1;
- }
- }
- else
- {
- //Only one matched, return.
- return matchingContacts.First().ratedId;
- }
- }
- else
- {
- //Nothing matched, return 0 to create.
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement