- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
public string GenerateWinCode(String PrefixWinCode, String Name, String LastName, String NameCompany, bool IsCompany = false)
{
string _NormalWinCode = "";
if (!IsCompany)
_NormalWinCode = (PrefixWinCode + Name[0] + LastName[0]).ToUpper();
else
{
var i = 1;
try
{
while (String.IsNullOrWhiteSpace(NameCompany[i].ToString()))
{
i++;
}
_NormalWinCode = (PrefixWinCode + NameCompany[0] + NameCompany[i]).ToUpper();
}
catch (Exception)
{
_NormalWinCode = (PrefixWinCode + NameCompany[0] + NameCompany[0]).ToUpper();
}
}
if (PrefixWinCode == "IN")
throw new RuleException("ErrorWincode", Resources.Accounts.Account.WincodeInvalid);
try
{
using (var context = db)
{
var _WincodesSim =
(from q in context.UserPartners.Where(m => m.WinCode.ToUpper().StartsWith(_NormalWinCode))
where q.WinCode.Length > 4
select q.WinCode).ToList();
var _Sufix = _WincodesSim.Select(m => Convert.ToInt32(m.Substring(4))).Max();
return _NormalWinCode + (_Sufix + 1);
}
}
catch (InvalidOperationException)
{
return _NormalWinCode + 1;
}
}
guest 24.02.2015 13:47 # +1
Lokich 25.02.2015 11:16 # 0