public static Dictionary <Guid, decimal> GetAgentRatio(Guid UserGuid) { Dictionary <Guid, decimal> agentRatio = new Dictionary <Guid, decimal>(); Common.User user = User.LoadUser(UserGuid); Common.GroupPrice groupPrice = GroupPrice.LoadGroupPrice(user.PriceGroupGuid); if (groupPrice.AgentRatio != string.Empty) { var xelement = XElement.Parse(groupPrice.AgentRatio); List <XElement> lstAgentElement = xelement.Elements("Table").ToList(); foreach (var item in lstAgentElement) { agentRatio.Add(Helper.GetGuid(item.Element("AgentID").Value), Helper.GetDecimal(item.Element("Ratio").Value)); } } return(agentRatio); }
public static decimal GetSendFormatPrice(Guid userGuid, Guid formatGuid, Guid privateNumberGuid, ref string numbersInfo) { decimal smsPrice = 0; int recipientCount; DataTable dtOperators = Operator.GetOperators(); Common.PrivateNumber privateNumber = PrivateNumber.LoadNumber(privateNumberGuid); List <DataRow> lstOperatorRatio = SmsSenderAgent.GetAgentRatio(privateNumber.SmsSenderAgentGuid).AsEnumerable().ToList(); Dictionary <Guid, decimal> dictionaryAgentRatio = GroupPrice.GetAgentRatio(userGuid); List <DataRow> lstInfo = SmsFormat.GetFormatSmsInfo(formatGuid).AsEnumerable().ToList(); Dictionary <int, int> operatorNumberCount = new Dictionary <int, int>(); int countUnicode = 0; int countLatin = 0; int mciCount = 0; int mtnCount = 0; int otherCount = 0; if (privateNumber.Type == (int)TypePrivateNumberAccesses.Bulk) { foreach (DataRow opt in dtOperators.Rows) { operatorNumberCount.Add(Helper.GetInt(opt["ID"]), lstInfo.Where(row => Helper.GetInt(row["Operator"]) == Helper.GetInt(opt["ID"])).Select(row => Helper.GetInt(row["Count"])).Sum()); countUnicode = lstInfo.Where(row => Helper.GetInt(row["Operator"]) == Helper.GetInt(opt["ID"]) && Helper.GetInt(row["Encoding"]) == 1).Select(row => Helper.GetInt(row["SmsPartCount"]) * Helper.GetInt(row["Count"])).Sum(); smsPrice += countUnicode * GetOperatorRatio(lstOperatorRatio, Helper.GetInt(opt["ID"]), SmsTypes.Farsi); countLatin = lstInfo.Where(row => Helper.GetInt(row["Operator"]) == Helper.GetInt(opt["ID"]) && Helper.GetInt(row["Encoding"]) == 0).Select(row => Helper.GetInt(row["SmsPartCount"]) * Helper.GetInt(row["Count"])).Sum(); smsPrice += countLatin * GetOperatorRatio(lstOperatorRatio, Helper.GetInt(opt["ID"]), SmsTypes.Latin); if (Helper.GetInt(opt["ID"]) == 1) //MCI { mciCount = countUnicode + countLatin; } else if (Helper.GetInt(opt["ID"]) == 2) //MTN { mtnCount = countUnicode + countLatin; } else { otherCount += countUnicode + countLatin; } } } else { foreach (DataRow opt in dtOperators.Rows) { operatorNumberCount.Add(Helper.GetInt(opt["ID"]), lstInfo.Where(row => Helper.GetInt(row["Operator"]) == Helper.GetInt(opt["ID"])).Select(row => Helper.GetInt(row["Count"])).Sum()); countUnicode = lstInfo.Where(row => Helper.GetInt(row["Operator"]) == Helper.GetInt(opt["ID"]) && Helper.GetInt(row["Encoding"]) == 1).Select(row => Helper.GetInt(row["Count"])).Sum(); smsPrice += countUnicode * GetOperatorRatio(lstOperatorRatio, Helper.GetInt(opt["ID"]), SmsTypes.Farsi); countLatin = lstInfo.Where(row => Helper.GetInt(row["Operator"]) == Helper.GetInt(opt["ID"]) && Helper.GetInt(row["Encoding"]) == 0).Select(row => Helper.GetInt(row["Count"])).Sum(); smsPrice += countLatin * GetOperatorRatio(lstOperatorRatio, Helper.GetInt(opt["ID"]), SmsTypes.Latin); if (Helper.GetInt(opt["ID"]) == 1) //MCI { mciCount = countUnicode + countLatin; } else if (Helper.GetInt(opt["ID"]) == 2) //MTN { mtnCount = countUnicode + countLatin; } else { otherCount += countUnicode + countLatin; } } } smsPrice *= dictionaryAgentRatio.ContainsKey(privateNumber.SmsSenderAgentGuid) ? Helper.GetDecimal(dictionaryAgentRatio[privateNumber.SmsSenderAgentGuid]) : 1; recipientCount = lstInfo.Select(row => Helper.GetInt(row["Count"])).Sum(); int totalCount = mciCount + mtnCount + otherCount; numbersInfo = "RecipientCount{(" + recipientCount + ")}TotalCount{(" + totalCount + ")}MCI{(" + mciCount + ")}MTN{(" + mtnCount + ")}Other{(" + otherCount + ")}Price{(" + smsPrice + ")}"; return(smsPrice); }