如何使用循环C#自动将交易分配给pipedrive中的用户列表? [英] How to auto assign deal to list of users in pipedrive using round robin C# ?

查看:51
本文介绍了如何使用循环C#自动将交易分配给pipedrive中的用户列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上客户在表单中输入交易,应该发布到Api,从Api发布到PipeDrive,所以我们在PipeDrive中有代理列表,每个交易都应分配给循环代理等。



例如:我们在PipeDrive帐户中有3个代理。所以第一笔交易应该去第一个代理商,第二笔交易给第二个代理商,第三笔交易给第三个代理商,第四笔交易应该回到第一个代理商。



所以我我使用内存缓存来存储最后分配的代理和下一个分配的代理。下面是代码。



问题是我正在寻找另一种方法来存储最后分配的和下一个分配而不是缓存。 />








如果有人帮我编写代码C,我将非常感激。

< pre> 





我的尝试:



< pre> 

列表< Agents> AgentsList = GetAgents(); 



 string CacheKey =LAST_ASSIGNED_AGENT; 



var lastAssignedAgent = GetItemFromCache

var nextAssignedAgent = NextOf(AgentList,lastAssignedAgent);

if(nextAssignedAgent == null)

抛出新的ApplicationException(不能找到下一个指定的代理);



AddItemToCache(AgentCacheKey,nextAssigned);



 private User NextOf(List< User> list,User agent)
{
if(agent == null)
return list [0];

var pair = list.Select((value,indx)=> new {Value = value,indx})
.Single(u => u.Value.Id == agent.Id);

int index = pair.indx;

if(index == -1)
return list [0];

返回列表[(index + 1)== list.Count? 0 :(索引+ 1)];
}

public static T GetItemFromCache< T>(字符串键)其中T:class
{
try
{
return(T )高速缓存[键]。
}
catch
{
return null;
}
}

public static void AddItemToCache(string key,object objectToCache)
{
Cache.Set(key,objectToCache,DateTime.Now。 AddDays(1));
}

解决方案

有什么我想念的吗? - 如果您有一定数量的代理商(在某个时间点),并且您有一个交易的顺序索引/计数器,那么,



< pre lang =c#> nextAgent = dealIndex%numberOfAgents;





按照你自己的规则



Quote:

例如:我们在PipeDrive帐户中有3个代理。所以第一笔交易应该转到第一个代理商,第二笔交易交给第二个代理商,第三笔交易交给第三个代理商,第四笔交易应该回到第一个代理商。





你只需要跟踪交易的顺序/索引/数量,因为分配给代理是一个'模数'操作


so basically the customer enter deal in form and it should be posted to Api and from Api to PipeDrive,so we have list of agents in PipeDrive and each deal should be assign to agents like round robin.

for example: we have 3 agents in PipeDrive account. so first deal should go to the first agent , second deal to the second agent, third deal to third agent and fourth deal should go back to first agent.

so I am using Memory Cache to store last assigned agent and Next Assigned agent. below is the code .

The question is I am looking for another way to store last assigned and next assigned instead of Cache .




I would be really grateful if somebody help me with code C# .

<pre>



What I have tried:

<pre>

List<Agents> AgentsList = GetAgents();


string CacheKey = "LAST_ASSIGNED_AGENT";


var lastAssignedAgent = GetItemFromCache
var nextAssignedAgent = NextOf(AgentList, lastAssignedAgent);
if (nextAssignedAgent == null)
throw new ApplicationException("Cannot find the next assigned agent");

AddItemToCache(AgentCacheKey, nextAssigned);

private User NextOf(List<User> list, User agent)
   {
       if (agent == null)
           return list[0];

       var pair = list.Select((value, indx) => new { Value = value, indx })
            .Single(u => u.Value.Id == agent.Id);

       int index = pair.indx;

       if (index == -1)
           return list[0];

       return list[(index + 1) == list.Count ? 0 : (index + 1)];
   }

   public static T GetItemFromCache<T>(string key) where T : class
   {
       try
       {
           return (T)Cache[key];
       }
       catch
       {
           return null;
       }
   }

   public static void AddItemToCache(string key, object objectToCache)
   {
       Cache.Set(key, objectToCache, DateTime.Now.AddDays(1));
   }

解决方案

is there something I'm missing ? - if you have a fixed number of agents (at a point in time), and you have a sequential index/counter of your 'deal', then,

nextAgent = dealIndex % numberOfAgents; 



by your own rules

Quote:

for example: we have 3 agents in PipeDrive account. so first deal should go to the first agent , second deal to the second agent, third deal to third agent and fourth deal should go back to first agent.



you only need to keep track of the sequence/index/count of the deal since assigning to an agent is a 'modulus' operation


这篇关于如何使用循环C#自动将交易分配给pipedrive中的用户列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆