Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 85.81 KB | None | 0 0
  1. using BinOp.BusinessLogic.Operations;
  2. using log4net;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using BinOp.Core;
  9. using BinOp.BusinessLogic.Caching;
  10. using BinOp.Site;
  11. using BinOp.DataAccess.Enums;
  12. using BinOp.SharedBusinessLogic.Helpers;
  13. using System.Configuration;
  14. using System.Data;
  15. using System.Threading;
  16. using System.Web.Security;
  17. using System.Web;
  18. using BinOp.Web;
  19. using BinOp.BusinessLogic.Globalization;
  20. using System.Globalization;
  21. using System.Collections.Specialized;
  22. using BinOp.BusinessLogic.Web.Commands;
  23. using BinOp.BusinessLogic.Web;
  24. using BinOp.SharedBusinessLogic.Enums;
  25. using System.Text.RegularExpressions;
  26. using BinOp.SharedBusinessLogic.Objects;
  27. using BinOp.BusinessLogic.Operations.BackOffice;
  28. using BinOp.BusinessLogic.Web.Mail;
  29. using BinOp.SharedBusinessLogic.Constants;
  30.  
  31. namespace BinOp.SharedBusinessLogic.WebAPI
  32. {
  33. public class WebApi
  34. {
  35. #region Constants
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. #endregion Constants
  43.  
  44. private UserHelper UserHelper { get; set; }
  45. private InvestmentHelper InvestmentHelper { get; set; }
  46. private CommonHelper CommonHelper { get; set; }
  47. private CrmHelper CrmHelper { get; set; }
  48.  
  49. public WebApi()
  50. {
  51. this.UserHelper = new UserHelper();
  52. this.InvestmentHelper = new InvestmentHelper();
  53. this.CommonHelper = new CommonHelper();
  54. this.CrmHelper = new CrmHelper();
  55. }
  56.  
  57. private ILog logger = LogManager.GetLogger(typeof(WebApi));
  58.  
  59. public PlatformUnixTime PlatformUnixTime()
  60. {
  61. long platformUnixTime = (long)((DateTime.Now.GetBinOpsTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
  62. return new PlatformUnixTime(platformUnixTime);
  63. }
  64.  
  65. public string ReloadTexts()
  66. {
  67. SiteTextsCache.Instance.InitiateDataTable();
  68. return "SUCCESS";
  69. }
  70.  
  71. public OperationResult CreateUser(string firstName, string lastName, string email, string password, int? partnerID = null)
  72. {
  73. OperationResult result = this.UserHelper.OpenAccount(
  74. firstName, lastName,
  75. null, String.Empty, 1, String.Empty, String.Empty, String.Empty,
  76. email, password,
  77. String.Empty, 0, false, partnerID, null,
  78. false, null, null, null);
  79. return result;
  80. }
  81.  
  82. public OperationResult Login(string username, string password)
  83. {
  84. bool EmailExists = ((bool)UsersOperations.CheckIfEmailNameExists(username).ResultValue);
  85. if (!EmailExists)
  86. {
  87. return new OperationResult(false, "username does not exist", null);
  88. }
  89.  
  90. if (!this.UserHelper.LoginUser(username, password).ProcessedSuccessful)
  91. {
  92. return new OperationResult(false, "wrong password", null);
  93. }
  94. return OperationResult.GenericSuccess;
  95. }
  96.  
  97. public OperationResult GetBalance(int userID)
  98. {
  99. try
  100. {
  101. if (userID > 0)
  102. {
  103. return UsersOperations.ReloadBalance(userID);
  104. }
  105.  
  106. return new OperationResult(false, MessageConstants.INVALID_USERID_TEXT, null);
  107. }
  108. catch (Exception ex)
  109. {
  110. return new OperationResult(false, ex.Message, null);
  111. }
  112. }
  113.  
  114. public OperationResult ChangePassword(string oldPassword, string newPassword, int userID)
  115. {
  116. try
  117. {
  118. if (userID > 0)
  119. {
  120. return UsersOperations.ChangePassword(userID, oldPassword, newPassword);
  121. }
  122.  
  123. return new OperationResult(false, MessageConstants.INVALID_USERID_TEXT, null);
  124. }
  125. catch (Exception ex)
  126. {
  127. return new OperationResult(false, ex.Message, null);
  128. }
  129. }
  130.  
  131. public OperationResult UpdateUser(string firstName, string lastName, string email, int userID)
  132. {
  133. try
  134. {
  135. if (userID > 0)
  136. {
  137. return UsersOperations.SaveUserDetails(userID, email, firstName, lastName, String.Empty);
  138. }
  139.  
  140. return new OperationResult(false, MessageConstants.INVALID_USERID_TEXT, null);
  141. }
  142. catch (Exception ex)
  143. {
  144. return new OperationResult(false, ex.Message, null);
  145. }
  146. }
  147.  
  148. public OperationResult Deposit(decimal amount, int userID)
  149. {
  150. try
  151. {
  152. if (userID > 0)
  153. {
  154. OperationResult res = PaymentOperations.StartPayment(userID, amount);
  155. int transactionId = Convert.ToInt32(res.ResultValue);
  156.  
  157. if (transactionId > 0) // success
  158. {
  159. return PaymentOperations.PaymentPassed(transactionId);
  160. }
  161. else // failure
  162. {
  163. return PaymentOperations.SetFailedState(transactionId);
  164. }
  165. }
  166.  
  167. return new OperationResult(false, string.Empty, null);
  168. }
  169. catch (Exception ex)
  170. {
  171. return new OperationResult(false, ex.Message, null);
  172. }
  173. }
  174.  
  175. public OperationResult Credit(decimal amount, int transactionType, int transactionSubType, int userID)
  176. {
  177. try
  178. {
  179. if (userID > 0)
  180. {
  181. return AccountsOperations.Credit(
  182. userID,
  183. amount,
  184. (TransactionTypes)transactionType,
  185. (TransactionSubTypes)transactionSubType,
  186. string.Empty, string.Empty, string.Empty, 1);
  187. }
  188.  
  189. return new OperationResult(false, MessageConstants.INVALID_USERID_TEXT, null);
  190. }
  191. catch (Exception ex)
  192. {
  193. return new OperationResult(false, ex.Message, null);
  194. }
  195. }
  196. public OperationResult Withdraw(decimal amount, int status, int userID)
  197. {
  198. try
  199. {
  200. if (userID > 0)
  201. {
  202. return AccountsOperations.Withdraw(userID, amount, status);
  203. }
  204.  
  205. return new OperationResult(false, MessageConstants.INVALID_USERID_TEXT, null);
  206. }
  207. catch (Exception ex)
  208. {
  209. return new OperationResult(false, ex.Message, null);
  210. }
  211. }
  212.  
  213. public OperationResult GetGeneralTradeInfo(string email)
  214. {
  215. OperationResult result = this.InvestmentHelper.GetGeneralTradeInfoByEmail(email);
  216.  
  217. return result;
  218. }
  219.  
  220. public OperationResult GetInvestments(string email, string from, string to, bool isClosed, int partnerID = 0, int? assetID = null)
  221. {
  222. DateTime dateFrom;
  223. DateTime? nulableDateFrom = null;
  224.  
  225. if (DateTime.TryParse(from, out dateFrom))
  226. {
  227. nulableDateFrom = dateFrom;
  228. }
  229.  
  230. DateTime dateTo;
  231. DateTime? nulableDateTo = null;
  232.  
  233. if (DateTime.TryParse(to, out dateTo))
  234. {
  235. nulableDateTo = dateTo;
  236. }
  237.  
  238. OperationResult result = this.InvestmentHelper.GetInvestmentsByEmail(email, nulableDateFrom, nulableDateTo, isClosed, assetID, partnerID: partnerID);
  239.  
  240. return result;
  241. }
  242.  
  243. public OperationResult GetTradeVolume(string email, DateTime? from, DateTime? to)
  244. {
  245. OperationResult result = this.InvestmentHelper.GetTradeVolumeByEmail(email, from, to);
  246.  
  247. return result;
  248. }
  249.  
  250. public OperationResult GetInvestmentsByExternalParameter(string externalParameter, string email, string from, string to, bool isClosed, int? assetID = null, int crmUserID = 0)
  251. {
  252. DateTime dateFrom;
  253. DateTime? nulableDateFrom = null;
  254.  
  255. if (DateTime.TryParse(from, out dateFrom))
  256. {
  257. nulableDateFrom = dateFrom;
  258. }
  259.  
  260. DateTime dateTo;
  261. DateTime? nulableDateTo = null;
  262.  
  263. if (DateTime.TryParse(to, out dateTo))
  264. {
  265. nulableDateTo = dateTo;
  266. }
  267.  
  268. string externalParametersAsString = ConfigurationManager.AppSettings["ExternalParameters"];
  269.  
  270. if (string.IsNullOrEmpty(externalParameter))
  271. {
  272. return new OperationResult(false, "externalParameter is required.", null);
  273. }
  274.  
  275. if (!string.IsNullOrEmpty(externalParametersAsString))
  276. {
  277. OperationResult result = this.InvestmentHelper.GetInvestmentsByEmail(email, nulableDateFrom, nulableDateTo, isClosed, assetID, externalParameter, crmUserID);
  278. return result;
  279. }
  280.  
  281. return new OperationResult(false, "Configuration is missing.", null);
  282. }
  283.  
  284. public OperationResult GetAccountDetails(int partnerID = 0, string email = null)
  285. {
  286. try
  287. {
  288. OperationResult userResult = UsersOperations.LoadUserDetailsByEmail(email, partnerID);
  289.  
  290. if (userResult.ProcessedSuccessful)
  291. {
  292. DataTable dtUsers = userResult.ResultValue as DataTable;
  293. if (dtUsers.Rows.Count > 0)
  294. {
  295. DataTable userTable = new DataTable();
  296. userTable.Columns.Add("ID", typeof(int));
  297.  
  298. foreach (DataRow drUser in dtUsers.Rows)
  299. {
  300. DataRow newDataRow = userTable.NewRow();
  301. newDataRow["ID"] = (int)drUser[UserConstants.COLUMN_USER_ID];
  302. userTable.Rows.Add(newDataRow);
  303. }
  304.  
  305. OperationResult result = UsersOperations.LoadUserDetails(0, userTable);
  306. return result;
  307. }
  308. else
  309. {
  310. return new OperationResult(false, MessageConstants.INVALID_USERNAME_TEXT, null);
  311. }
  312. }
  313. else
  314. {
  315. return userResult;
  316. }
  317.  
  318. }
  319. catch (Exception ex)
  320. {
  321. return new OperationResult(false, ex.Message, null);
  322. }
  323. }
  324.  
  325. public OperationResult UpdateAccountDetails(string email, string firstName, string lastName, string phone, bool joinCommunity, string publicNickname, string countryCode = null)
  326. {
  327. try
  328. {
  329. OperationResult userResult = UsersOperations.LoadUserDetailsByEmail(email);
  330.  
  331. if (userResult.ProcessedSuccessful)
  332. {
  333. DataTable dtUsers = userResult.ResultValue as DataTable;
  334. if (dtUsers.Rows.Count > 0)
  335. {
  336. DataRow drUser = dtUsers.Rows[0];
  337.  
  338. OperationResult result = UsersOperations.SaveUserDetails((int)drUser[UserConstants.COLUMN_USER_ID], email, firstName, lastName, phone, null, countryCode);
  339.  
  340. UsersOperations.SetSocialStatus((int)drUser[UserConstants.COLUMN_USER_ID], joinCommunity);
  341. UsersOperations.SetSocialInfo((int)drUser[UserConstants.COLUMN_USER_ID], publicNickname, string.Empty);
  342. if ((int)result.ResultValue == 0)
  343. {
  344. return new OperationResult(true, SiteTextsCache.Instance.GetValue("DetailsSaved", Thread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName), null);
  345. }
  346. else
  347. {
  348. return new OperationResult(true, SiteTextsCache.Instance.GetValue("EnterUserExists", Thread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName), null);
  349. }
  350. }
  351.  
  352. return new OperationResult(false, "No user has been found.", null);
  353. }
  354. else
  355. {
  356. return userResult;
  357. }
  358.  
  359. }
  360. catch (Exception ex)
  361. {
  362. return new OperationResult(false, ex.Message, null);
  363. }
  364. }
  365.  
  366. public OperationResult GetAccountOperations(string email, string from, string to, int accountOperationType, int partnerID = 0)
  367. {
  368. try
  369. {
  370. OperationResult userResult = UsersOperations.LoadUserDetailsByEmail(email, partnerID);
  371.  
  372. if (userResult.ProcessedSuccessful)
  373. {
  374. DataTable dtUsers = userResult.ResultValue as DataTable;
  375. if (dtUsers.Rows.Count > 0)
  376. {
  377. DataRow drUser = dtUsers.Rows[0];
  378.  
  379. DateTime dateFrom;
  380. DateTime? nulableDateFrom = null;
  381.  
  382. if (DateTime.TryParse(from, out dateFrom))
  383. {
  384. nulableDateFrom = dateFrom;
  385. }
  386.  
  387. DateTime dateTo;
  388. DateTime? nulableDateTo = null;
  389.  
  390. if (DateTime.TryParse(to, out dateTo))
  391. {
  392. nulableDateTo = dateTo;
  393. }
  394.  
  395. if (accountOperationType == 0 || accountOperationType < -1)
  396. {
  397. accountOperationType = -1;
  398. }
  399.  
  400. OperationResult result = UsersOperations.LoadAccountOperations((int)drUser[UserConstants.COLUMN_USER_ID], (AccountOperationTypes)accountOperationType, nulableDateFrom, nulableDateTo);
  401. return result;
  402. }
  403.  
  404. return new OperationResult(false, "No user has been found.", null);
  405. }
  406. else
  407. {
  408. return userResult;
  409. }
  410.  
  411. }
  412. catch (Exception ex)
  413. {
  414. return new OperationResult(false, ex.Message, null);
  415. }
  416. }
  417.  
  418. public OperationResult GetAccountLimitOrders(string email, string from, string to, int assetID, int groupID, int pageNum, int count)
  419. {
  420. try
  421. {
  422. OperationResult userResult = UsersOperations.LoadUserDetailsByEmail(email);
  423.  
  424. if (userResult.ProcessedSuccessful)
  425. {
  426. DataTable dtUsers = userResult.ResultValue as DataTable;
  427. if (dtUsers.Rows.Count > 0)
  428. {
  429. DataRow drUser = dtUsers.Rows[0];
  430.  
  431. DateTime dateFrom;
  432. DateTime? nulableDateFrom = null;
  433.  
  434. if (DateTime.TryParse(from, out dateFrom))
  435. {
  436. nulableDateFrom = dateFrom;
  437. }
  438.  
  439. DateTime dateTo;
  440. DateTime? nulableDateTo = null;
  441.  
  442. if (DateTime.TryParse(to, out dateTo))
  443. {
  444. nulableDateTo = dateTo;
  445. }
  446.  
  447. if (assetID == 0 || assetID < -1)
  448. {
  449. assetID = -1;
  450. }
  451.  
  452. if (groupID == 0 || groupID < -1)
  453. {
  454. groupID = -1;
  455. }
  456.  
  457. if (pageNum < 1)
  458. {
  459. pageNum = 1;
  460. }
  461.  
  462. if (count < 1)
  463. {
  464. count = 25;
  465. }
  466.  
  467. DataSet data = BackOfficeOperations.SearchLimitOrders(pageNum, count, nulableDateFrom, nulableDateTo, (int)drUser[UserConstants.COLUMN_USER_ID], -1, -1, -1, assetID, groupID, -1, 0).ResultValue as DataSet;
  468. int total = Convert.ToInt32(data.Tables[0].Rows[0][0]);
  469. DataTable table = data.Tables[1];
  470. foreach (DataRow row in table.Rows)
  471. {
  472. row["AssetName"] = GetAssetName(row);
  473. }
  474.  
  475. OperationResult result = new OperationResult(true, "success", table);
  476.  
  477. return result;
  478. }
  479.  
  480. return new OperationResult(false, "No user has been found.", null);
  481. }
  482. else
  483. {
  484. return userResult;
  485. }
  486.  
  487. }
  488. catch (Exception ex)
  489. {
  490. return new OperationResult(false, ex.Message, null);
  491. }
  492. }
  493.  
  494. public OperationResult OpenAccountWithCredit(string firstName, string lastName, string email, string phone, decimal bonusAmount, string password = null,
  495. int? partnerID = null, string affID = null, string dateOfBirth = null, string language = null, string id = null, string session = null, bool isAmerican = false, bool isDemo = false, bool isDemoLogin = false, string countryCode = null)
  496. {
  497.  
  498. bool EmailExists = ((bool)UsersOperations.CheckIfEmailNameExists(email).ResultValue);
  499. if (EmailExists)
  500. {
  501. return new OperationResult(false, MessageConstants.INVALID_USERNAME_DOES_NOT_EXISTS, null);
  502. }
  503.  
  504. DateTime date = new DateTime(1996, 01, 01);
  505. if (dateOfBirth != null)
  506. {
  507. DateTime.TryParse(dateOfBirth, out date);
  508. }
  509.  
  510. if (string.IsNullOrEmpty(countryCode) || countryCode.Length != 2)
  511. {
  512. countryCode = null;
  513. }
  514.  
  515. if (password == null)
  516. {
  517. var autoGeneratedPasswordLength = int.Parse(ConfigurationManager.AppSettings["AutoGeneratedPasswordLength"] ?? "8");
  518. var autoGeneratedPasswordNonAlphaNumericLength = int.Parse(ConfigurationManager.AppSettings["AutoGeneratedPasswordNonAlphaNumericLength"] ?? "3");
  519. password = Membership.GeneratePassword(autoGeneratedPasswordLength, autoGeneratedPasswordNonAlphaNumericLength);
  520. }
  521.  
  522. OperationResult result = this.UserHelper.OpenAccount(
  523. firstName, lastName,
  524. null, String.Empty, 1, phone, String.Empty, String.Empty,
  525. email, password,
  526. countryCode, 0, isDemo, partnerID, null,
  527. false, null, null, null, true, isAmerican: isAmerican, isDemoLogin: isDemoLogin);
  528.  
  529. return OpenAccountAddtionalOperations(result, firstName, lastName, email, phone, bonusAmount, password, language, true, id, session);
  530. }
  531.  
  532. public OperationResult GetResolveCountryCode()
  533. {
  534. string countryCode = WebUtils.ResolveUserCountryCode(HttpContext.Current);
  535. OperationResult result = new OperationResult(true, string.Empty, countryCode);
  536.  
  537. if (!string.IsNullOrEmpty(countryCode))
  538. {
  539. BinOpCallingCodeResolver resolver = new BinOpCallingCodeResolver();
  540. var callingCode = resolver.ResolveCallingCode(countryCode);
  541.  
  542. result.ResultValue = result.ResultValue.ToString() + ',' + callingCode;
  543.  
  544. }
  545.  
  546. return result;
  547. }
  548.  
  549. public OperationResult HasUserDeposited(int userID)
  550. {
  551. try
  552. {
  553. if (userID > 0)
  554. {
  555. return UsersOperations.HasUserDeposited(userID);
  556. }
  557.  
  558. return new OperationResult(false, MessageConstants.INVALID_USERID_TEXT, null);
  559. }
  560. catch (Exception ex)
  561. {
  562. return new OperationResult(false, ex.Message, null);
  563. }
  564. }
  565.  
  566. public OperationResult GetRiskGroups()
  567. {
  568. try
  569. {
  570. OperationResult result = RiskGroupsOperations.GetAll();
  571.  
  572. return result;
  573. }
  574. catch (Exception ex)
  575. {
  576. return new OperationResult(false, ex.Message, null);
  577. }
  578. }
  579.  
  580. public OperationResult GetUserRiskGroup(string email)
  581. {
  582. try
  583. {
  584. OperationResult result = RiskGroupsOperations.GetByEmail(email);
  585.  
  586. return result;
  587. }
  588. catch (Exception ex)
  589. {
  590. return new OperationResult(false, ex.Message, null);
  591. }
  592. }
  593.  
  594. public OperationResult SetUserRiskgroup(string email, int riskGroupID)
  595. {
  596. try
  597. {
  598. OperationResult result = RiskGroupsOperations.SetRiskGroupToUserByEmail(email, riskGroupID);
  599.  
  600. int rowsCount = 0;
  601. if (int.TryParse(result.ResultValue.ToString(), out rowsCount))
  602. {
  603. if (rowsCount > 0)
  604. {
  605. return new OperationResult(true, "Successfully updated", null);
  606. }
  607. }
  608.  
  609. return new OperationResult(false, "No records found", null);
  610. }
  611. catch (Exception ex)
  612. {
  613. return new OperationResult(false, ex.Message, null);
  614. }
  615. }
  616.  
  617. public OperationResult Withdraw(string username, decimal amount)
  618. {
  619. try
  620. {
  621. OperationResult or = UsersOperations.LoadUserDetailsByEmail(username);
  622. if (or.ProcessedSuccessful)
  623. {
  624. DataTable dtUsers = or.ResultValue as DataTable;
  625. if (dtUsers.Rows.Count > 0)
  626. {
  627. DataRow drUser = dtUsers.Rows[0];
  628. return AccountsOperations.Withdraw((int)drUser[UserConstants.COLUMN_USER_ID], amount);
  629. }
  630. else
  631. {
  632. return new OperationResult(false, MessageConstants.INVALID_USERNAME_TEXT, null);
  633. }
  634. }
  635. else
  636. {
  637. return or;
  638. }
  639. }
  640. catch (Exception ex)
  641. {
  642. return new OperationResult(false, ex.Message, null);
  643. }
  644. }
  645.  
  646. public OperationResult GetLoggedInUsers()
  647. {
  648. try
  649. {
  650. OperationResult result = this.UserHelper.GetAllOnlineUsers();
  651.  
  652. return result;
  653. }
  654. catch (Exception ex)
  655. {
  656. return new OperationResult(false, ex.Message, null);
  657. }
  658. }
  659.  
  660. public string GetAssetsList(int userID , int userLevelID)
  661. {
  662. //int countMostPopularAssets = (int)AllCache.Get<object>("CountMostPopularAssets");
  663. int countMostPopularAssets = 2;
  664.  
  665. // get assets and most popular tables
  666. DataTable assetsDataTable = new DataTable();
  667. if (HttpContext.Current.User.Identity.IsAuthenticated && userID > 0)
  668. {
  669. assetsDataTable = AssetsOperations.LoadAllAssets(UserId: userID).ResultValue as DataTable;
  670. }
  671. else
  672. {
  673. assetsDataTable = AssetsOperations.LoadAllAssets().ResultValue as DataTable;
  674. }
  675.  
  676. DataTable mostPopularAssets = BinOpsOperations.LoadMostPopularAssets(countMostPopularAssets).ResultValue as DataTable;
  677. //assetsDataTable.Select()
  678. // create hash of all popular assetIDs
  679. //HashSet<string> mostPopularAssetIDs = new HashSet<string>();
  680. //foreach (DataRow mpAssetRow in mostPopularAssets.Rows)
  681. // mostPopularAssetIDs.Add(mpAssetRow[COLUMN_ASSET_ID].ToString());
  682.  
  683. Dictionary<string, int> mostPopularAssetIDs = new Dictionary<string, int>();
  684. for (int i = 0; i < mostPopularAssets.Rows.Count; ++i)
  685. mostPopularAssetIDs.Add(mostPopularAssets.Rows[i][InvestmentConstants.COLUMN_ASSET_ID].ToString(), i + 1);
  686.  
  687. // start building the response string
  688. StringBuilder sb = new StringBuilder();
  689. sb.Append("[");
  690. DateTime currentTime = Shared.GetBinOpsTime(DateTime.Now);
  691. // for each row create a javascript array of objects, each object is an associative array {key:val} with data pertaining to the specific option
  692. foreach (DataRow assetRow in assetsDataTable.Rows)
  693. {
  694. if (assetRow[UserConstants.COLUMN_MIN_USER_LEVEL_ID] != DBNull.Value && userID > 0)
  695. {
  696. int minUserLevelId = Convert.ToInt32(assetRow[UserConstants.COLUMN_MIN_USER_LEVEL_ID]);
  697. if (minUserLevelId > userLevelID & userLevelID > 0)
  698. {
  699. continue;
  700. }
  701. }
  702.  
  703. string assetID = assetRow[InvestmentConstants.COLUMN_ASSET_ID].ToString();
  704. string groupID = assetRow[InvestmentConstants.COLUMN_GROUP_ID].ToString();
  705. string marketID = assetRow[InvestmentConstants.COLUMN_MARKET_ID].ToString();
  706. string assetName = GetAssetName(assetRow);
  707. string floatingPoints = assetRow[InvestmentConstants.COLUMN_ASSET_FLOATING_POINTS].ToString();
  708. int spread = 0;
  709. if (!String.IsNullOrEmpty(assetRow[InvestmentConstants.COLUMN_ASSET_SPREAD].ToString()))
  710. spread = Convert.ToInt32(assetRow[InvestmentConstants.COLUMN_ASSET_SPREAD]);
  711. int isMostPopular = mostPopularAssetIDs.ContainsKey(assetID) ? mostPopularAssetIDs[assetID] : 0;
  712.  
  713. DateTime startWorkingTime = Convert.ToDateTime(assetRow[InvestmentConstants.COLUMN_START_WORKING_TIME]);
  714. startWorkingTime = currentTime.Date.AddHours(startWorkingTime.Hour).AddMinutes(startWorkingTime.Minute);
  715. if (startWorkingTime.Hour < currentTime.Hour)
  716. {
  717. startWorkingTime = startWorkingTime.AddDays(1);
  718. }
  719.  
  720. DateTime closeEodTime = Convert.ToDateTime(assetRow[InvestmentConstants.COLUMN_CLOSE_EOD_TIME]);
  721. DateTime eodTime = Convert.ToDateTime(assetRow[InvestmentConstants.COLUMN_EOD_TIME]);
  722. int profitLowPercent = Convert.ToInt32(assetRow[InvestmentConstants.COLUMN_PROFIT_LOW_PERCENT]);
  723.  
  724. string isFavourite = assetRow[InvestmentConstants.COLUMN_IS_FAVOURITE].ToString();
  725.  
  726. string closeDay = ConfigurationManager.AppSettings["SetMarketCloseDayOfTheWeek"];
  727. string closeTime = ConfigurationManager.AppSettings["SetMarketCloseTime"];
  728. string closeIgnor = ConfigurationManager.AppSettings["SetMarketCloseIgnor"];
  729. bool ignorCloseDate = false;
  730. bool.TryParse(closeIgnor, out ignorCloseDate);
  731.  
  732. // ignor or not any markets close settings from the web.config
  733. if (!ignorCloseDate)
  734. {
  735. // gets and sets day and time from the web.config
  736. DateTime theTime = DateTime.Now.GetBinOpsTime();
  737.  
  738. if (!string.IsNullOrEmpty(closeDay) && !string.IsNullOrEmpty(closeTime))
  739. {
  740. int closeDayNumber = 0;
  741. if (int.TryParse(closeDay, out closeDayNumber) && closeDayNumber == (int)theTime.DayOfWeek)
  742. {
  743. if (DateTime.TryParse(closeTime, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out closeEodTime))
  744. {
  745. eodTime = closeEodTime.AddMinutes(5);
  746. }
  747. }
  748. }
  749. else if (theTime.DayOfWeek == DayOfWeek.Friday) // default settings fro friday
  750. {
  751. closeEodTime = DateTime.Parse("1/1/2015 19:55:00", CultureInfo.InvariantCulture);
  752. eodTime = DateTime.Parse("1/1/2015 20:00:00", CultureInfo.InvariantCulture);
  753. }
  754. }
  755.  
  756. string startWorkingTimeString = startWorkingTime.ToString(CommonConstants.ISO_FORMAT);
  757. string closeEodTimeString = closeEodTime.ToString(CommonConstants.ISO_FORMAT);
  758. string eodTimeString = eodTime.ToString(CommonConstants.ISO_FORMAT);
  759. string eodTimeFormattedString = eodTime.ToString("HH:mm (UTC)");
  760. sb.Append(string.Format("{{\"AID\":\"{0}\",\"GID\":\"{1}\",\"MID\":\"{2}\",\"AN\":\"{3}\",\"FP\":\"{4}\",\"MP\":\"{5}\",\"SP\":{6},\"SWT\":\"{7}\",\"CET\":\"{8}\",\"ET\":\"{9}\",\"ETF\":\"{10}\",\"PLP\":\"{11}\",\"IF\":\"{12}\"}}",
  761. assetID, groupID, marketID, assetName, floatingPoints, isMostPopular.ToString(), spread, startWorkingTimeString, closeEodTimeString, eodTimeString, eodTimeFormattedString, profitLowPercent, isFavourite));
  762.  
  763. if (!assetsDataTable.Rows[assetsDataTable.Rows.Count - 1].Equals(assetRow))
  764. sb.Append(",");
  765. }
  766.  
  767. // close the response string
  768. sb.Append("]");
  769.  
  770. return sb.ToString();
  771. }
  772.  
  773. public OperationResult GetAccountDetailsEx(string username, int partnerID = 0)
  774. {
  775. try
  776. {
  777. OperationResult or = BackOfficeOperations.LoadUserDetailsByIdentity(username, partnerID);
  778. if (or.ProcessedSuccessful)
  779. {
  780. return or;
  781. }
  782. else
  783. {
  784. return new OperationResult(false, MessageConstants.INVALID_USERNAME_TEXT, null);
  785. }
  786. }
  787. catch (Exception ex)
  788. {
  789. return new OperationResult(false, ex.Message, null);
  790. }
  791. }
  792.  
  793. public OperationResult PlaceOrder(string email, string gameType, int assetID, double amount, bool isCall, int percent, bool isVirtual,
  794. int dynamicTypeSlice, string expirationDate, int returnPercent, int timeSliceType, string binOpLevel)
  795. {
  796. try
  797. {
  798. if (string.IsNullOrEmpty(email))
  799. {
  800. return new OperationResult(false, MessageConstants.EMAIL_NOT_PROVIDED_TEXT, null);
  801. }
  802.  
  803. NameValueCollection parameters = new NameValueCollection();
  804. parameters.Add("Name", "PlaceLongTermOrder");
  805. parameters.Add("GT", gameType);
  806. parameters.Add("Bid", assetID.ToString());
  807. parameters.Add("Amnt", amount.ToString());
  808. if (isCall)
  809. {
  810. parameters.Add("Ot", "CALL");
  811. }
  812. else
  813. {
  814. parameters.Add("Ot", "PUT");
  815. }
  816.  
  817. parameters.Add("GI", "true");
  818. parameters.Add("P", percent.ToString());
  819. parameters.Add("OIID", "-1");
  820. parameters.Add("V", isVirtual.ToString());
  821. parameters.Add("DTS", dynamicTypeSlice.ToString());
  822. parameters.Add("ED", expirationDate);
  823. parameters.Add("RP", returnPercent.ToString());
  824. parameters.Add("TS", timeSliceType.ToString());
  825. parameters.Add("Lvl", binOpLevel);
  826. parameters.Add("CmdType", "PlaceLongTermOrder");
  827.  
  828.  
  829. OperationResult result = UsersOperations.LoadUserDetailsByEmail(email);
  830.  
  831. if (result.ProcessedSuccessful)
  832. {
  833. DataTable data = result.ResultValue as DataTable;
  834. if (data.Rows.Count > 0)
  835. {
  836. BaseCommand baseCommand = BaseCommand.CreateCommand(parameters);
  837. baseCommand.SettingsCollection = ConfigurationManager.AppSettings;
  838. baseCommand.UserDescriptorObject = this.CommonHelper.InitUserInfo(data);
  839.  
  840. string returnCode = baseCommand.Execute();
  841.  
  842. // 1 = No opened binops
  843. // 2 = Not enough money
  844. // 3 - Blocked
  845. // 0 = Ok
  846.  
  847. string[] returnCodeString = returnCode.Split(',');
  848. string returnedValue = null;
  849.  
  850. if (returnCodeString.Count() > 1)
  851. {
  852. returnCode = returnCodeString[0];
  853. returnedValue = returnCodeString[1];
  854. }
  855.  
  856. int returnCodeAsInt = 0;
  857. if (int.TryParse(returnCode, out returnCodeAsInt) & (returnCodeAsInt == 0 || returnCodeAsInt == 100))
  858. {
  859. return new OperationResult(true, "code: " + returnCode, returnedValue);
  860. }
  861. else
  862. {
  863. return new OperationResult(false, "code: " + returnCode, null);
  864. }
  865. }
  866. }
  867.  
  868. return result;
  869. }
  870. catch (Exception ex)
  871. {
  872. return new OperationResult(false, ex.Message, null);
  873. }
  874. }
  875.  
  876. public OperationResult GetDynamicTimeSliceTypes(int assetID)
  877. {
  878. OperationResult result = new OperationResult();
  879.  
  880. try
  881. {
  882. result = BinOpsOperations.GetDynamicTimeSliceTypes(assetID);
  883. }
  884. catch (Exception ex)
  885. {
  886. return new OperationResult(false, ex.Message, null);
  887. }
  888.  
  889. return result;
  890. }
  891.  
  892. public OperationResult BuyMoreTime(int investmentID, int time, int userID)
  893. {
  894. try
  895. {
  896. NameValueCollection parameters = new NameValueCollection();
  897. parameters.Add("Name", "BuyMoreTime");
  898. parameters.Add("TPM", time.ToString());
  899. parameters.Add("IiD", investmentID.ToString());
  900. parameters.Add("CmdType", "BuyMoreTime");
  901.  
  902. BaseCommand baseCommand = BaseCommand.CreateCommand(parameters);
  903. baseCommand.SettingsCollection = ConfigurationManager.AppSettings;
  904. baseCommand.UserDescriptorObject = new UserDescriptor(userID, null, null, null, null, 0, null, null, DateTime.Now, null,
  905. null, null, null, 3, null, false, false, DateTime.Now, false,
  906. null, 0, 0, null, null, null, null, false, null, false, 0, false);
  907. string returnCode = baseCommand.Execute();
  908.  
  909. // 1 = No opened binops
  910. // 2 = Not enough money
  911. // 3 - Blocked
  912. // 0 = Ok
  913.  
  914. int returnCodeAsInt = 0;
  915. if (int.TryParse(returnCode, out returnCodeAsInt) & (returnCodeAsInt == 0 || returnCodeAsInt == 100))
  916. {
  917. return new OperationResult(true, "code: " + returnCode, null);
  918. }
  919. else
  920. {
  921. return new OperationResult(false, "code: " + returnCode, null);
  922. }
  923. }
  924. catch (Exception ex)
  925. {
  926. return new OperationResult(false, ex.Message, null);
  927. }
  928. }
  929.  
  930. public OperationResult ChangePassword(int userID, string oldPassword, string newPassword)
  931. {
  932. try
  933. {
  934. return UsersOperations.ChangePassword(userID, oldPassword, newPassword);
  935. }
  936. catch (Exception ex)
  937. {
  938. return new OperationResult(false, ex.Message, null);
  939. }
  940. }
  941.  
  942. public OperationResult GetTopTraders()
  943. {
  944. try
  945. {
  946. return new OperationResult(true, String.Empty, this.UserHelper.GetTopTraders());
  947. }
  948. catch (Exception ex)
  949. {
  950. return new OperationResult(false, ex.Message, null);
  951. }
  952. }
  953.  
  954. public OperationResult ForgottenPassword(string email, string languageCode = null)
  955. {
  956. try
  957. {
  958. if (string.IsNullOrEmpty(email))
  959. {
  960. return new OperationResult(false, MessageConstants.EMAIL_NOT_PROVIDED_TEXT, null);
  961. }
  962.  
  963. OperationResult operationResult = UsersOperations.RecoverPassword(email);
  964.  
  965. if (operationResult.ProcessedSuccessful)
  966. {
  967. string newPassword = (string)operationResult.ResultValue;
  968. OperationResult detailsResult = UsersOperations.LoadUserDetailsByEmail(email);
  969.  
  970. if (!detailsResult.ProcessedSuccessful)
  971. {
  972. logger.Error(detailsResult.Message);
  973. throw new InvalidOperationException("Failed to get user details by email");
  974. }
  975.  
  976. DataTable userDetailsTable = detailsResult.ResultValue as DataTable;
  977.  
  978. string firstName = (string)userDetailsTable.Rows[0]["FirstName"];
  979. string lastName = (string)userDetailsTable.Rows[0]["LastName"];
  980.  
  981. if (string.IsNullOrEmpty(languageCode))
  982. {
  983. languageCode = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
  984. }
  985.  
  986. SendMailNotification(languageCode, email, firstName, lastName, null, MailTypes.PasswordRecovered, password: newPassword);
  987.  
  988. string isSupportReceiveMail = System.Configuration.ConfigurationManager.AppSettings["SupportReceiveMail"] ?? "";
  989.  
  990. if (isSupportReceiveMail == CommonConstants.TRUE_VALUE_AS_TEXT)
  991. {
  992. SendMailNotification(languageCode, System.Configuration.ConfigurationManager.AppSettings["AdminMail"], firstName, lastName, null, MailTypes.PasswordRecovered, password: newPassword);
  993. }
  994.  
  995. return new OperationResult(true, newPassword, null);
  996. }
  997. else
  998. {
  999. return new OperationResult(false, "No account with email " + email + " has been found.", null);
  1000.  
  1001. }
  1002. }
  1003. catch (Exception ex)
  1004. {
  1005. return new OperationResult(false, ex.Message, null);
  1006. }
  1007. }
  1008.  
  1009. public OperationResult SendSupportMail(string subject, string message, string email, string languageCode = null)
  1010. {
  1011. try
  1012. {
  1013. if (string.IsNullOrEmpty(email))
  1014. {
  1015. return new OperationResult(false, MessageConstants.EMAIL_NOT_PROVIDED_TEXT, null);
  1016. }
  1017.  
  1018. if (string.IsNullOrEmpty(message))
  1019. {
  1020. return new OperationResult(false, "The message can't be empty.", null);
  1021. }
  1022.  
  1023. OperationResult detailsResult = UsersOperations.LoadUserDetailsByEmail(email);
  1024.  
  1025. if (!detailsResult.ProcessedSuccessful)
  1026. {
  1027. logger.Error(detailsResult.Message);
  1028. throw new InvalidOperationException("Failed to get user details by email");
  1029. }
  1030.  
  1031. DataTable userDetailsTable = detailsResult.ResultValue as DataTable;
  1032.  
  1033. string firstName = (string)userDetailsTable.Rows[0]["FirstName"];
  1034. string lastName = (string)userDetailsTable.Rows[0]["LastName"];
  1035.  
  1036. if (string.IsNullOrEmpty(languageCode))
  1037. {
  1038. languageCode = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
  1039. }
  1040.  
  1041. SendMailNotification(languageCode, System.Configuration.ConfigurationManager.AppSettings["AdminMail"], firstName, lastName, null, MailTypes.ContactUs,
  1042. dataRow: userDetailsTable.Rows[0], subject: subject, message: message, fromAddress: email);
  1043.  
  1044. return new OperationResult(true, null, null);
  1045. }
  1046. catch (Exception ex)
  1047. {
  1048. return new OperationResult(false, ex.Message, null);
  1049. }
  1050. }
  1051.  
  1052. public OperationResult TermsAndConditions(string languageCode = null, bool removeHtml = false)
  1053. {
  1054. try
  1055. {
  1056. StringBuilder sb = new StringBuilder();
  1057.  
  1058. if (string.IsNullOrEmpty(languageCode))
  1059. {
  1060. languageCode = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
  1061. }
  1062.  
  1063. sb.Append(SiteTextsCache.Instance.GetValue("AgreementPreambleText", languageCode));
  1064. sb.Append(SiteTextsCache.Instance.GetValue("AgreementDepositText", languageCode));
  1065. sb.Append(SiteTextsCache.Instance.GetValue("AgreementPolicyText", languageCode));
  1066. sb.Append(SiteTextsCache.Instance.GetValue("AgreementAdditionalText", languageCode));
  1067. sb.Append(SiteTextsCache.Instance.GetValue("AgreementUnderageText", languageCode));
  1068.  
  1069. string result = sb.ToString();
  1070.  
  1071. if (removeHtml)
  1072. {
  1073. result = Regex.Replace(result, "<.*?>", string.Empty);
  1074. }
  1075.  
  1076. return new OperationResult(true, result, null);
  1077. }
  1078. catch (Exception ex)
  1079. {
  1080. return new OperationResult(false, ex.Message, null);
  1081. }
  1082. }
  1083.  
  1084. public OperationResult ReferAFriendInfo(int userID)
  1085. {
  1086. try
  1087. {
  1088. OperationResult result = UsersOperations.GetReferredUsersCount(userID);
  1089.  
  1090. return result;
  1091. }
  1092. catch (Exception ex)
  1093. {
  1094. return new OperationResult(false, ex.Message, null);
  1095. }
  1096. }
  1097.  
  1098. public OperationResult ReferAFriendSendNotification(int userID, string email, string languageCode, string firstName, string lastName)
  1099. {
  1100. try
  1101. {
  1102. if (string.IsNullOrEmpty(languageCode))
  1103. {
  1104. languageCode = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
  1105. }
  1106.  
  1107. SendMailNotification(languageCode, email, firstName, lastName, email, MailTypes.ReferAFriend, refNUmber: userID.ToString());
  1108.  
  1109. return new OperationResult(true, null, null);
  1110. }
  1111. catch (Exception ex)
  1112. {
  1113. return new OperationResult(false, ex.Message, null);
  1114. }
  1115. }
  1116.  
  1117. public List<SocialTradeObject> SocialTrades(int userID, int pageNumber, int pageSize)
  1118. {
  1119. List<SocialTradeObject> resultData = new List<SocialTradeObject>();
  1120.  
  1121. try
  1122. {
  1123. int assetId = -1;
  1124. int groupId = -1;
  1125. int? userId = null;
  1126. int call_put = -1;
  1127. int myUserId = -1;
  1128.  
  1129. if (pageSize < 1)
  1130. {
  1131. pageSize = 1;
  1132. }
  1133.  
  1134. if (pageNumber < 1)
  1135. {
  1136. pageNumber = 1;
  1137. }
  1138.  
  1139. if (userID > 0)
  1140. {
  1141. userId = userID;
  1142. }
  1143.  
  1144. OperationResult virtualLimitOrdersResult = null;
  1145. OperationResult virtualTradesResult = null;
  1146.  
  1147. OperationResult result1 = BusinessLogic.Operations.BinOpsOperations.GetSocialLimitOrders(pageNumber, pageSize, myUserId, userId, call_put, assetId, groupId);
  1148. OperationResult result2 = BusinessLogic.Operations.BinOpsOperations.GetSocialOrders(pageNumber, pageSize, myUserId, userId, call_put, assetId, groupId);
  1149. OperationResult result3 = BusinessLogic.Operations.BinOpsOperations.GetSocialQuickOptionsOrders(pageNumber, pageSize, myUserId, userId, call_put, assetId, groupId);
  1150.  
  1151. if (userId == null)
  1152. {
  1153. virtualLimitOrdersResult = BinOpsOperations.GetSocialVirtualLimitOrders(1, pageSize, null, call_put, assetId, groupId);
  1154. virtualTradesResult = BinOpsOperations.GetSocialVirtualTrades(1, pageSize, null, call_put, assetId, groupId);
  1155. }
  1156.  
  1157. DataSet data;
  1158. int total = 0;
  1159. DataTable limitTable;
  1160. DataTable OrderTable;
  1161.  
  1162. if (result1.ProcessedSuccessful)
  1163. {
  1164. data = result1.ResultValue as DataSet;
  1165. total += Convert.ToInt32(data.Tables[0].Rows[0][0]);
  1166. limitTable = data.Tables[1];
  1167.  
  1168. foreach (DataRow limitRow in limitTable.Rows)
  1169. {
  1170. foreach (DataColumn dataColumn in limitRow.Table.Columns)
  1171. {
  1172. resultData.Add(new SocialTradeObject() { Name = dataColumn.ColumnName, Value = limitRow[dataColumn].ToString(), IsLimitOrder = true });
  1173. }
  1174. }
  1175. }
  1176. if (result2.ProcessedSuccessful)
  1177. {
  1178. data = result2.ResultValue as DataSet;
  1179. total += Convert.ToInt32(data.Tables[0].Rows[0][0]);
  1180. OrderTable = data.Tables[1];
  1181.  
  1182. foreach (DataRow orderRow in OrderTable.Rows)
  1183. {
  1184. foreach (DataColumn dataColumn in orderRow.Table.Columns)
  1185. {
  1186. resultData.Add(new SocialTradeObject() { Name = dataColumn.ColumnName, Value = orderRow[dataColumn].ToString() });
  1187. }
  1188. }
  1189. }
  1190.  
  1191. if (result3.ProcessedSuccessful)
  1192. {
  1193. data = result3.ResultValue as DataSet;
  1194. total += Convert.ToInt32(data.Tables[0].Rows[0][0]);
  1195. OrderTable = data.Tables[1];
  1196.  
  1197. foreach (DataRow orderRow in OrderTable.Rows)
  1198. {
  1199. foreach (DataColumn dataColumn in orderRow.Table.Columns)
  1200. {
  1201. resultData.Add(new SocialTradeObject() { Name = dataColumn.ColumnName, Value = orderRow[dataColumn].ToString() });
  1202. }
  1203. }
  1204. }
  1205.  
  1206. if (virtualLimitOrdersResult != null && virtualLimitOrdersResult.ProcessedSuccessful)
  1207. {
  1208. var virtualLimitOrdersTable = virtualLimitOrdersResult.ResultValue as DataTable;
  1209.  
  1210. foreach (DataRow virtualLimitOrderRow in virtualLimitOrdersTable.Rows)
  1211. {
  1212. foreach (DataColumn dataColumn in virtualLimitOrderRow.Table.Columns)
  1213. {
  1214. resultData.Add(new SocialTradeObject() { Name = dataColumn.ColumnName, Value = virtualLimitOrderRow[dataColumn].ToString(), IsLimitOrder = true, IsVirtual = true });
  1215. }
  1216. }
  1217. }
  1218. if (virtualTradesResult != null && virtualTradesResult.ProcessedSuccessful)
  1219. {
  1220. var virtualTradesTable = virtualTradesResult.ResultValue as DataTable;
  1221.  
  1222. foreach (DataRow virtualTradeRow in virtualTradesTable.Rows)
  1223. {
  1224. foreach (DataColumn dataColumn in virtualTradeRow.Table.Columns)
  1225. {
  1226. resultData.Add(new SocialTradeObject() { Name = dataColumn.ColumnName, Value = virtualTradeRow[dataColumn].ToString(), IsVirtual = true });
  1227. }
  1228. }
  1229. }
  1230.  
  1231. }
  1232. catch (Exception ex)
  1233. {
  1234. logger.Error(ex.Message, ex);
  1235. }
  1236.  
  1237. return resultData;
  1238. }
  1239.  
  1240. public OperationResult SuperCash(int userID, string email, int socialCount)
  1241. {
  1242. OperationResult returnedObject = new OperationResult();
  1243.  
  1244. try
  1245. {
  1246. Dictionary<string, int> formData = new Dictionary<string, int> { };
  1247. Dictionary<string, int> Assets = new Dictionary<string, int> { };
  1248. DataTable resultTable = new DataTable();
  1249. resultTable.Columns.Add(InvestmentConstants.COLUMN_ASSET_ID, typeof(String));
  1250. resultTable.Columns.Add(InvestmentConstants.COLUMN_IS_CALL, typeof(String));
  1251. resultTable.Columns.Add(InvestmentConstants.COLUMN_EXPIRATION_TIME, typeof(String));
  1252. resultTable.Columns.Add(InvestmentConstants.COLUMN_SOCIAL_BOT, typeof(String));
  1253. resultTable.Columns.Add(InvestmentConstants.COLUMN_PAYOUT, typeof(String));
  1254.  
  1255. OperationResult result = BusinessLogic.Operations.AssetsOperations.LoadAllSocialAssets(ConfigurationManager.AppSettings[CommonConstants.SOURCE_SYSTEM_NAME].ToString(), userID);
  1256. DataSet data;
  1257. DataTable OrderTable;
  1258.  
  1259. if (result.ProcessedSuccessful)
  1260. {
  1261. data = result.ResultValue as DataSet;
  1262. OrderTable = data.Tables[0];
  1263.  
  1264. if (OrderTable.Rows.Count == 0)
  1265. {
  1266. return new OperationResult(true, string.Empty, null);
  1267. }
  1268. else
  1269. {
  1270. int i = 0;
  1271.  
  1272. foreach (DataRow Row in OrderTable.Rows)
  1273. {
  1274. if (i >= socialCount) break;
  1275.  
  1276. string socialBotID = Row[InvestmentConstants.COLUMN_SOCIAL_BOT].ToString();
  1277. int socialBotId = Convert.ToInt32(socialBotID);
  1278. string assetID = Row[InvestmentConstants.COLUMN_ASSET_ID].ToString();
  1279.  
  1280. string isCall = Row[InvestmentConstants.COLUMN_IS_CALL].ToString();
  1281. if (isCall == "True")
  1282. {
  1283. isCall = "1";
  1284. }
  1285. else
  1286. {
  1287. isCall = "0";
  1288. }
  1289.  
  1290. string expirationTime = Row[InvestmentConstants.COLUMN_EXPIRATION_TIME].ToString();
  1291. DateTime date = Convert.ToDateTime(expirationTime);
  1292. string current_date = date.Year + "-" + date.Month + "-" + date.Day + "T";
  1293. string current_time = date.TimeOfDay + "";
  1294. expirationTime = current_date + current_time;
  1295. string investValue = Row["InvestmentValue"].ToString();
  1296. string sourceSystem = Row["SourceSystem"].ToString();
  1297. string payout = Row[InvestmentConstants.COLUMN_PAYOUT].ToString();
  1298. string isVirtualTrade = Row["IsVirtualTrade"].ToString();
  1299. bool isVirtual = Convert.ToBoolean(isVirtualTrade);
  1300. string backOfficeSiteName = null;
  1301.  
  1302. int isBackOfficeSite = 0; //проверка дали записа в базата идва от backOffice и ако е от там се проверява времето което остава до изтичане, ако е по - малко от
  1303. if (sourceSystem.Contains("_"))
  1304. { // 20 минути автоматично към времето се добавят още 60 минути, това в случай че маркета е все още отворен
  1305. string[] backOfficeSite = sourceSystem.Split(new string[] { "_" }, StringSplitOptions.None);
  1306. backOfficeSiteName = backOfficeSite[1];
  1307. if (backOfficeSiteName == ConfigurationManager.AppSettings[CommonConstants.SOURCE_SYSTEM_NAME].ToString())
  1308. {
  1309. isBackOfficeSite = 1;
  1310. }
  1311. else
  1312. {
  1313. isBackOfficeSite = 2;
  1314. }
  1315. }
  1316.  
  1317. int val;
  1318. if (formData.TryGetValue(sourceSystem + "_" + userID, out val))
  1319. {
  1320. formData[sourceSystem + "_" + userID] = val + 1;
  1321. }
  1322. else
  1323. {
  1324. formData.Add(sourceSystem + "_" + userID, 1);
  1325. }
  1326.  
  1327. int value;
  1328. if (Assets.TryGetValue(assetID, out value))
  1329. {
  1330. Assets[assetID] = value + 1;
  1331. }
  1332. else
  1333. {
  1334. Assets.Add(assetID, 1);
  1335. }
  1336.  
  1337. int currentValue = formData[sourceSystem + "_" + userID];
  1338. int currentValueAsset = Assets[assetID];
  1339. bool isOneAsset = false;
  1340.  
  1341. if (currentValueAsset < 2)
  1342. {
  1343. isOneAsset = true;
  1344. }
  1345. else
  1346. {
  1347. if (isVirtual)
  1348. {
  1349. isOneAsset = true;
  1350. }
  1351. else
  1352. {
  1353. isOneAsset = false;
  1354. }
  1355. }
  1356. bool IsAvalibleAssetID = false;
  1357. DataTable assetsDataTable = AssetsOperations.LoadAllAssets().ResultValue as DataTable;
  1358.  
  1359. // iterate all open position rows in the table
  1360. foreach (DataRow openPositionRow in assetsDataTable.Rows)
  1361. {
  1362. string assetId = openPositionRow[InvestmentConstants.COLUMN_ASSET_ID].ToString();
  1363. if (assetId == assetID)
  1364. IsAvalibleAssetID = true;
  1365. }
  1366. if (IsAvalibleAssetID)
  1367. {
  1368. if (((currentValue < 5 && isOneAsset) && (isBackOfficeSite == 0 || isBackOfficeSite == 1)) && isBackOfficeSite != 2)
  1369. {
  1370. DataRow newRow = resultTable.NewRow();
  1371. newRow[InvestmentConstants.COLUMN_ASSET_ID] = assetID;
  1372. newRow[InvestmentConstants.COLUMN_IS_CALL] = isCall;
  1373. newRow[InvestmentConstants.COLUMN_EXPIRATION_TIME] = expirationTime;
  1374. newRow[InvestmentConstants.COLUMN_SOCIAL_BOT] = socialBotID;
  1375. newRow[InvestmentConstants.COLUMN_PAYOUT] = payout;
  1376.  
  1377. resultTable.Rows.Add(newRow);
  1378. ++i;
  1379. }
  1380. }
  1381. }
  1382.  
  1383. returnedObject = new OperationResult(true, null, resultTable);
  1384. }
  1385. }
  1386. }
  1387. catch (Exception ex)
  1388. {
  1389. return new OperationResult(false, ex.Message, null);
  1390. }
  1391.  
  1392. return returnedObject;
  1393. }
  1394.  
  1395. public OperationResult CopyTrade(string email, int binopID, double amount, bool isCall, int percent, bool isVirtual)
  1396. {
  1397. try
  1398. {
  1399. if (string.IsNullOrEmpty(email))
  1400. {
  1401. return new OperationResult(false, MessageConstants.EMAIL_NOT_PROVIDED_TEXT, null);
  1402. }
  1403.  
  1404. OperationResult investmentResult = BinOpsOperations.GetInvestmentsByBinOpID(binopID, isVirtual);
  1405.  
  1406. if (investmentResult.ProcessedSuccessful)
  1407. {
  1408. DataTable dataTable = investmentResult.ResultValue as DataTable;
  1409. if (dataTable != null && dataTable.Rows.Count > 0)
  1410. {
  1411. int originalInvestmentID = -1;
  1412. string binopLevel = string.Empty;
  1413.  
  1414. if (!isVirtual)
  1415. {
  1416. int investID = 0;
  1417. int.TryParse(dataTable.Rows[0][InvestmentConstants.COLUMN_INVESTMENT_ID].ToString(), out investID);
  1418. int.TryParse(dataTable.Rows[0][InvestmentConstants.COLUMN_ORIGINAL_INVESTMENT_ID].ToString(), out originalInvestmentID);
  1419. int.TryParse(dataTable.Rows[0][InvestmentConstants.COLUMN_ORIGINAL_VIRTUAL_TRADE_ID].ToString(), out originalInvestmentID);
  1420.  
  1421. if (originalInvestmentID < 1)
  1422. {
  1423. originalInvestmentID = investID;
  1424. }
  1425.  
  1426. binopLevel = dataTable.Rows[0]["BinOpLevel"].ToString();
  1427. }
  1428. else
  1429. {
  1430. int.TryParse(dataTable.Rows[0]["VirtualTradeID"].ToString(), out originalInvestmentID);
  1431. binopLevel = dataTable.Rows[0]["BinOpLevel"].ToString();
  1432. }
  1433.  
  1434. NameValueCollection parameters = new NameValueCollection();
  1435. parameters.Add("Name", "PlaceOrder");
  1436. parameters.Add("GT", "2");
  1437. parameters.Add("Bid", binopID.ToString());
  1438. parameters.Add("Amnt", amount.ToString());
  1439. if (isCall)
  1440. {
  1441. parameters.Add("Ot", "CALL");
  1442. }
  1443. else
  1444. {
  1445. parameters.Add("Ot", "PUT");
  1446. }
  1447.  
  1448. parameters.Add("P", percent.ToString());
  1449. parameters.Add("OIID", originalInvestmentID.ToString());
  1450. parameters.Add("V", isVirtual.ToString());
  1451. parameters.Add("DTS", null);
  1452. //parameters.Add("TS", timeSliceType.ToString());
  1453. parameters.Add("Lvl", binopLevel);
  1454. parameters.Add("CmdType", "PlaceOrder");
  1455.  
  1456. OperationResult result = UsersOperations.LoadUserDetailsByEmail(email);
  1457.  
  1458. if (result.ProcessedSuccessful)
  1459. {
  1460. DataTable data = result.ResultValue as DataTable;
  1461. if (data.Rows.Count > 0)
  1462. {
  1463. BaseCommand baseCommand = BaseCommand.CreateCommand(parameters);
  1464. baseCommand.SettingsCollection = ConfigurationManager.AppSettings;
  1465. baseCommand.UserDescriptorObject = this.CommonHelper.InitUserInfo(data);
  1466.  
  1467. string returnCode = baseCommand.Execute();
  1468.  
  1469. // 1 = No opened binops
  1470. // 2 = Not enough money
  1471. // 3 - Blocked
  1472. // 0 = Ok
  1473.  
  1474. int returnCodeAsInt = 0;
  1475. if (int.TryParse(returnCode, out returnCodeAsInt) & (returnCodeAsInt == 0 || returnCodeAsInt == 100))
  1476. {
  1477. return new OperationResult(true, "code: " + returnCode, null);
  1478. }
  1479. else
  1480. {
  1481. return new OperationResult(false, "code: " + returnCode, null);
  1482. }
  1483. }
  1484. }
  1485.  
  1486. return result;
  1487.  
  1488. }
  1489. }
  1490. }
  1491. catch (Exception ex)
  1492. {
  1493. logger.Error(ex.Message, ex);
  1494. return new OperationResult(false, ex.Message, null);
  1495. }
  1496.  
  1497. return new OperationResult(false, null, null);
  1498. }
  1499.  
  1500. public OperationResult SuperCashTrade(string email, int socialBotID, double amount, bool openOnePosition)
  1501. {
  1502. try
  1503. {
  1504. if (string.IsNullOrEmpty(email))
  1505. {
  1506. return new OperationResult(false, MessageConstants.EMAIL_NOT_PROVIDED_TEXT, null);
  1507. }
  1508.  
  1509. NameValueCollection parameters = new NameValueCollection();
  1510. parameters.Add("Name", "PlaceSocialBotOrder");
  1511. parameters.Add(InvestmentConstants.COLUMN_SOCIAL_BOT, socialBotID.ToString());
  1512. parameters.Add("amount", amount.ToString());
  1513. parameters.Add("OpenOnePosition", amount.ToString());
  1514. parameters.Add("CmdType", "PlaceSocialBotOrder");
  1515.  
  1516. OperationResult result = UsersOperations.LoadUserDetailsByEmail(email);
  1517.  
  1518. if (result.ProcessedSuccessful)
  1519. {
  1520. DataTable data = result.ResultValue as DataTable;
  1521. if (data.Rows.Count > 0)
  1522. {
  1523. BaseCommand baseCommand = BaseCommand.CreateCommand(parameters);
  1524. baseCommand.SettingsCollection = ConfigurationManager.AppSettings;
  1525. baseCommand.UserDescriptorObject = this.CommonHelper.InitUserInfo(data);
  1526.  
  1527. string returnCode = baseCommand.Execute();
  1528.  
  1529. // 1 = No opened binops
  1530. // 2 = Not enough money
  1531. // 3 - Blocked
  1532. // 0 = Ok
  1533.  
  1534. int returnCodeAsInt = 0;
  1535. if (int.TryParse(returnCode, out returnCodeAsInt) & (returnCodeAsInt == 0 || returnCodeAsInt == 100))
  1536. {
  1537. return new OperationResult(true, "code: " + returnCode, null);
  1538. }
  1539. else
  1540. {
  1541. return new OperationResult(false, "code: " + returnCode, null);
  1542. }
  1543. }
  1544. }
  1545.  
  1546. return result;
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. logger.Error(ex.Message, ex);
  1551. return new OperationResult(false, ex.Message, null);
  1552. }
  1553. }
  1554.  
  1555. public OperationResult CopyLimitTrade(string email, int limitID, double amount, bool isVirtual)
  1556. {
  1557. try
  1558. {
  1559. if (string.IsNullOrEmpty(email))
  1560. {
  1561. return new OperationResult(false, MessageConstants.EMAIL_NOT_PROVIDED_TEXT, null);
  1562. }
  1563.  
  1564. NameValueCollection parameters = new NameValueCollection();
  1565. parameters.Add("Name", "CopyLimitOrder");
  1566. parameters.Add("LID", limitID.ToString());
  1567. parameters.Add("A", amount.ToString());
  1568. parameters.Add("OIID", "-1");
  1569. parameters.Add("V", isVirtual.ToString());
  1570. parameters.Add("CmdType", "CopyLimitOrder");
  1571.  
  1572. OperationResult result = UsersOperations.LoadUserDetailsByEmail(email);
  1573.  
  1574. if (result.ProcessedSuccessful)
  1575. {
  1576. DataTable data = result.ResultValue as DataTable;
  1577. if (data.Rows.Count > 0)
  1578. {
  1579. BaseCommand baseCommand = BaseCommand.CreateCommand(parameters);
  1580. baseCommand.SettingsCollection = ConfigurationManager.AppSettings;
  1581. baseCommand.UserDescriptorObject = this.CommonHelper.InitUserInfo(data);
  1582.  
  1583. string returnCode = baseCommand.Execute();
  1584.  
  1585. // 1 = No opened binops
  1586. // 2 = Not enough money
  1587. // 3 - Blocked
  1588. // 0 = Ok
  1589.  
  1590. int returnCodeAsInt = 0;
  1591. if (int.TryParse(returnCode, out returnCodeAsInt) & (returnCodeAsInt == 0 || returnCodeAsInt == 100))
  1592. {
  1593. return new OperationResult(true, "code: " + returnCode, null);
  1594. }
  1595. else
  1596. {
  1597. return new OperationResult(false, "code: " + returnCode, null);
  1598. }
  1599. }
  1600. }
  1601.  
  1602. return result;
  1603. }
  1604. catch (Exception ex)
  1605. {
  1606. logger.Error(ex.Message, ex);
  1607. return new OperationResult(false, ex.Message, null);
  1608. }
  1609. }
  1610.  
  1611. public OperationResult CreatePartner(string username, string password, string crmKey, bool isActive)
  1612. {
  1613. try
  1614. {
  1615. if (string.IsNullOrEmpty(username))
  1616. {
  1617. return new OperationResult(false, MessageConstants.USERNAME_NOT_PROVIDED_TEXT, null);
  1618. }
  1619.  
  1620. OperationResult ValidateUserNameResult = BackOfficeUsersOperations.GetByUsername(username);
  1621. if (ValidateUserNameResult.ProcessedSuccessful)
  1622. {
  1623. logger.Info(MessageConstants.USERNAME_EXISTS_TEXT);
  1624. return new OperationResult(false, MessageConstants.USERNAME_EXISTS_TEXT, null);
  1625. }
  1626. else
  1627. {
  1628. DataTable rolesTable = new DataTable();
  1629. rolesTable.Columns.Add("ID", typeof(int));
  1630. DataRow newDataRow = rolesTable.NewRow();
  1631. newDataRow["ID"] = 6;
  1632. rolesTable.Rows.Add(newDataRow);
  1633.  
  1634. if (string.IsNullOrEmpty(password))
  1635. {
  1636. var autoGeneratedPasswordLength = int.Parse(ConfigurationManager.AppSettings["AutoGeneratedPasswordLength"] ?? "8");
  1637. var autoGeneratedPasswordNonAlphaNumericLength = int.Parse(ConfigurationManager.AppSettings["AutoGeneratedPasswordNonAlphaNumericLength"] ?? "3");
  1638. password = Membership.GeneratePassword(autoGeneratedPasswordLength, autoGeneratedPasswordNonAlphaNumericLength);
  1639. }
  1640.  
  1641. OperationResult result = BackOfficeUsersOperations.Create(username, password, rolesTable, isActive, crmKey);
  1642. if (result.ProcessedSuccessful)
  1643. {
  1644. DataTable dataTable = result.ResultValue as DataTable;
  1645. int partnerID = 0;
  1646. int.TryParse(dataTable.Rows[0][0].ToString(), out partnerID);
  1647. if (partnerID > 0)
  1648. {
  1649. return new OperationResult(true, string.Empty, partnerID);
  1650. }
  1651. }
  1652.  
  1653. return OperationResult.GenericFailure;
  1654. }
  1655. }
  1656. catch (Exception ex)
  1657. {
  1658. logger.Error(ex.Message, ex);
  1659. return new OperationResult(false, ex.Message, null);
  1660. }
  1661. }
  1662.  
  1663. public OperationResult GetUserByEmail(string email, int partnerID = 0)
  1664. {
  1665. OperationResult userData = this.UserHelper.GetUserByEmail(email, partnerID);
  1666. return userData;
  1667. }
  1668.  
  1669. #region Partner Related Methods
  1670.  
  1671. public OperationResult OpenAccount(string firstName, string lastName, string email, string phone, decimal bonusAmount = 0, int? partnerID = null, string password = null, string countryCode = null, string description = null)
  1672. {
  1673. string language = string.Empty;
  1674.  
  1675. if (phone == null)
  1676. {
  1677. phone = string.Empty;
  1678. }
  1679.  
  1680. if (!string.IsNullOrEmpty(countryCode) && countryCode.Length == 2)
  1681. {
  1682. language = countryCode;
  1683. }
  1684. if (password == null)
  1685. {
  1686. var autoGeneratedPasswordLength = int.Parse(ConfigurationManager.AppSettings["AutoGeneratedPasswordLength"] ?? "8");
  1687. var autoGeneratedPasswordNonAlphaNumericLength = int.Parse(ConfigurationManager.AppSettings["AutoGeneratedPasswordNonAlphaNumericLength"] ?? "3");
  1688. password = Membership.GeneratePassword(autoGeneratedPasswordLength, autoGeneratedPasswordNonAlphaNumericLength);
  1689. }
  1690.  
  1691. bool isSocial = false;
  1692.  
  1693. if (!string.IsNullOrEmpty(description))
  1694. {
  1695. isSocial = true;
  1696. }
  1697.  
  1698. OperationResult result = this.UserHelper.OpenAccount(
  1699. firstName, lastName,
  1700. null, String.Empty, 1, phone, String.Empty, String.Empty,
  1701. email, password,
  1702. language, 0, false, partnerID, null,
  1703. isSocial, description, null, null);
  1704.  
  1705. return OpenAccountAddtionalOperations(result, firstName, lastName, email, phone, bonusAmount, password, countryCode, false, partnerID: partnerID);
  1706. }
  1707.  
  1708. public OperationResult ListCountries()
  1709. {
  1710. OperationResult result = SystemOperations.LoadAllCountries();
  1711. return result;
  1712. }
  1713.  
  1714. public OperationResult GetAdditionalParameterValue(string name)
  1715. {
  1716. OperationResult result = AdditionalDataToStoreOperations.Exists(name, this.CommonHelper.GetIpAddress(HttpContext.Current));
  1717. return result;
  1718. }
  1719.  
  1720. public OperationResult ListAssets(int assetID = 0)
  1721. {
  1722. OperationResult result = new OperationResult();
  1723. int countMostPopularAssets = 2;
  1724. DataTable assetsDataTable = null;
  1725.  
  1726. if (assetID > 0)
  1727. {
  1728. assetsDataTable = AssetsOperations.LoadAllAssetsWithUserLevel(assetID: assetID, loadFromDb: true).ResultValue as DataTable;
  1729. }
  1730. else
  1731. {
  1732. assetsDataTable = AssetsOperations.LoadAllAssets().ResultValue as DataTable;
  1733. }
  1734.  
  1735. DataTable mostPopularAssets = BinOpsOperations.LoadMostPopularAssets(countMostPopularAssets).ResultValue as DataTable;
  1736.  
  1737. Dictionary<string, int> mostPopularAssetIDs = new Dictionary<string, int>();
  1738. for (int i = 0; i < mostPopularAssets.Rows.Count; ++i)
  1739. mostPopularAssetIDs.Add(mostPopularAssets.Rows[i][InvestmentConstants.COLUMN_ASSET_ID].ToString(), i + 1);
  1740.  
  1741. // start building the response string
  1742. StringBuilder sb = new StringBuilder();
  1743. DateTime currentTime = Shared.GetBinOpsTime(DateTime.Now);
  1744. // for each row create a javascript array of objects, each object is an associative array {key:val} with data pertaining to the specific option
  1745. foreach (DataRow assetRow in assetsDataTable.Rows)
  1746. {
  1747. string currentAssetID = assetRow[InvestmentConstants.COLUMN_ASSET_ID].ToString();
  1748. string groupID = assetRow[InvestmentConstants.COLUMN_GROUP_ID].ToString();
  1749. string marketID = assetRow[InvestmentConstants.COLUMN_MARKET_ID].ToString();
  1750. string assetName = GetAssetName(assetRow);
  1751. string floatingPoints = assetRow[InvestmentConstants.COLUMN_ASSET_FLOATING_POINTS].ToString();
  1752. int spread = 0;
  1753. if (!String.IsNullOrEmpty(assetRow[InvestmentConstants.COLUMN_ASSET_SPREAD].ToString()))
  1754. spread = Convert.ToInt32(assetRow[InvestmentConstants.COLUMN_ASSET_SPREAD]);
  1755. int isMostPopular = mostPopularAssetIDs.ContainsKey(currentAssetID) ? mostPopularAssetIDs[currentAssetID] : 0;
  1756.  
  1757. DateTime startWorkingTime = Convert.ToDateTime(assetRow[InvestmentConstants.COLUMN_START_WORKING_TIME]);
  1758. startWorkingTime = currentTime.Date.AddHours(startWorkingTime.Hour).AddMinutes(startWorkingTime.Minute);
  1759. if (startWorkingTime.Hour < currentTime.Hour)
  1760. {
  1761. startWorkingTime = startWorkingTime.AddDays(1);
  1762. }
  1763.  
  1764. DateTime closeEodTime = Convert.ToDateTime(assetRow[InvestmentConstants.COLUMN_CLOSE_EOD_TIME]);
  1765. DateTime eodTime = Convert.ToDateTime(assetRow[InvestmentConstants.COLUMN_EOD_TIME]);
  1766. int profitLowPercent = Convert.ToInt32(assetRow[InvestmentConstants.COLUMN_PROFIT_LOW_PERCENT]);
  1767.  
  1768. string closeDay = ConfigurationManager.AppSettings["SetMarketCloseDayOfTheWeek"];
  1769. string closeTime = ConfigurationManager.AppSettings["SetMarketCloseTime"];
  1770. string closeIgnor = ConfigurationManager.AppSettings["SetMarketCloseIgnor"];
  1771. bool ignorCloseDate = false;
  1772. bool.TryParse(closeIgnor, out ignorCloseDate);
  1773.  
  1774. // ignor or not any markets close settings from the web.config
  1775. if (!ignorCloseDate)
  1776. {
  1777. // gets and sets day and time from the web.config
  1778. DateTime theTime = DateTime.Now.GetBinOpsTime();
  1779.  
  1780. if (!string.IsNullOrEmpty(closeDay) && !string.IsNullOrEmpty(closeTime))
  1781. {
  1782. int closeDayNumber = 0;
  1783. if (int.TryParse(closeDay, out closeDayNumber) && closeDayNumber == (int)theTime.DayOfWeek)
  1784. {
  1785. if (DateTime.TryParse(closeTime, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out closeEodTime))
  1786. {
  1787. eodTime = closeEodTime.AddMinutes(5);
  1788. }
  1789. }
  1790. }
  1791. else if (theTime.DayOfWeek == DayOfWeek.Friday) // default settings fro friday
  1792. {
  1793. closeEodTime = DateTime.Parse("1/1/2015 19:55:00", CultureInfo.InvariantCulture);
  1794. eodTime = DateTime.Parse("1/1/2015 20:00:00", CultureInfo.InvariantCulture);
  1795. }
  1796. }
  1797.  
  1798. string startWorkingTimeString = startWorkingTime.ToString(CommonConstants.ISO_FORMAT);
  1799. string closeEodTimeString = closeEodTime.ToString(CommonConstants.ISO_FORMAT);
  1800. string eodTimeString = eodTime.ToString(CommonConstants.ISO_FORMAT);
  1801. string eodTimeFormattedString = eodTime.ToString("HH:mm (UTC)");
  1802. sb.Append(string.Format("{{\"AID\":\"{0}\",\"GID\":\"{1}\",\"MID\":\"{2}\",\"AN\":\"{3}\",\"FP\":\"{4}\",\"MP\":\"{5}\",\"SP\":{6},\"SWT\":\"{7}\",\"CET\":\"{8}\",\"ET\":\"{9}\",\"ETF\":\"{10}\",\"PLP\":\"{11}\"}}",
  1803. currentAssetID, groupID, marketID, assetName, floatingPoints, isMostPopular.ToString(), spread, startWorkingTimeString, closeEodTimeString, eodTimeString, eodTimeFormattedString, profitLowPercent));
  1804.  
  1805. if (!assetsDataTable.Rows[assetsDataTable.Rows.Count - 1].Equals(assetRow))
  1806. sb.Append(",");
  1807. }
  1808.  
  1809. // close the response string
  1810. if (!string.IsNullOrEmpty(sb.ToString()))
  1811. {
  1812. result.ResultValue = sb.ToString();
  1813. result.ProcessedSuccessful = true;
  1814. }
  1815.  
  1816. return result;
  1817. }
  1818.  
  1819. public OperationResult CreateCrmLead(string firstName, string lastName, string email, string phoneCountryCode,
  1820. string phoneAreaCode, string phoneNumber, string ip, string promoCode = null, int? affID = null, string description = null, string countryCode = null)
  1821. {
  1822. bool EmailExists = ((bool)UsersOperations.CheckIfEmailNameExists(email).ResultValue);
  1823. if (EmailExists)
  1824. {
  1825. return new OperationResult(false, MessageConstants.INVALID_USERNAME_DOES_NOT_EXISTS, null);
  1826. }
  1827.  
  1828. if (string.IsNullOrEmpty(ip))
  1829. {
  1830. ip = this.CommonHelper.GetIpAddress(HttpContext.Current);
  1831. }
  1832.  
  1833. this.CrmHelper.CreateCrmLead(firstName, lastName, email, phoneCountryCode, phoneAreaCode, phoneNumber, ip, null, promoCode, affID, description: description, countryCode: countryCode);
  1834. return new OperationResult(true, null, null);
  1835. }
  1836.  
  1837. #endregion Partner Related Methods
  1838.  
  1839. #region Private Methods
  1840. private void SendMailNotification(string languageCode, string toAddress, string firstName, string lastName, string username, MailTypes mailType, string password = null,
  1841. DataRow dataRow = null, string subject = null, string message = null, string fromAddress = null, string refNUmber = null)
  1842. {
  1843. ThreadPool.QueueUserWorkItem((state) =>
  1844. {
  1845. try
  1846. {
  1847. switch (mailType)
  1848. {
  1849. case MailTypes.PasswordRecovered:
  1850. SiteMailer.Instance.SendPasswordRecovered(languageCode, toAddress, firstName, lastName, password);
  1851. break;
  1852. case MailTypes.ContactUs:
  1853. SiteMailer.Instance.SendContacUs(languageCode, toAddress, fromAddress, firstName, lastName, dataRow["EMail"].ToString(), message, subject);
  1854. break;
  1855. case MailTypes.ReferAFriend:
  1856. SiteMailer.Instance.SendReferAFriend(languageCode, toAddress, firstName, lastName, refNUmber);
  1857. break;
  1858. default:
  1859. SiteMailer.Instance.SendUserCreatedNotification(languageCode, toAddress, firstName, lastName, username, password);
  1860. break;
  1861. }
  1862. }
  1863. catch (Exception ex)
  1864. {
  1865. logger.Error("Failed sending mail after user creation.", ex);
  1866. }
  1867. });
  1868. }
  1869.  
  1870. private string GetAssetName(DataRow asset)
  1871. {
  1872. string assetKey = (string)asset[InvestmentConstants.COLUMN_RES_KEY];
  1873. string assetName = (string)asset[InvestmentConstants.COLUMN_ASSET_NAME];
  1874.  
  1875. string assetSiteTextsKey = "AssetName_" + assetKey;
  1876. string assetSiteTextsValue = SiteTextsCache.Instance.GetValue(assetSiteTextsKey, Thread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName);
  1877.  
  1878. // if no translation value default to Asset Name from DB
  1879. if (assetSiteTextsValue == String.Format("[{0}]", assetSiteTextsKey))
  1880. {
  1881. assetSiteTextsValue = assetName;
  1882. }
  1883.  
  1884. return assetSiteTextsValue;
  1885. }
  1886.  
  1887. private OperationResult OpenAccountAddtionalOperations(OperationResult result, string firstName, string lastName, string email, string phone, decimal bonusAmount,
  1888. string password = null, string countryCode = null, bool login = true, string session = null, string id = null, int? partnerID = null)
  1889. {
  1890. int createduserID = 0;
  1891.  
  1892. if (result.ProcessedSuccessful)
  1893. {
  1894. int.TryParse(result.ResultValue.ToString(), out createduserID);
  1895.  
  1896. if (login)
  1897. {
  1898. result = Login(email, password);
  1899. }
  1900. else
  1901. {
  1902. result.ProcessedSuccessful = true;
  1903. }
  1904.  
  1905. if (result.ProcessedSuccessful)
  1906. {
  1907. this.CrmHelper.CreateCrmAccount(createduserID, firstName, lastName, email, String.Empty, String.Empty, phone,
  1908. HttpContext.Current.Request.UserHostAddress, "Account", affID: partnerID);
  1909.  
  1910. var languageCode = countryCode ?? Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
  1911. SendMailNotification(languageCode, email, firstName, lastName, email, MailTypes.UserCreated, password: password);
  1912.  
  1913. string binOpLimitCall = ConfigurationManager.AppSettings["DefaultBinOpLimitCall"] ?? "";
  1914. string binOpLimitPut = ConfigurationManager.AppSettings["DefaultBinOpLimitPut"] ?? "";
  1915.  
  1916. if (!String.IsNullOrEmpty(binOpLimitCall) &&
  1917. !String.IsNullOrEmpty(binOpLimitPut))
  1918. {
  1919. UsersOperations.CreateLimit(
  1920. email,
  1921. TimeSliceTypes.All, (PercentageTypes)(-1), -1, -1,
  1922. -1,
  1923. -1,
  1924. -1,
  1925. -1,
  1926. Convert.ToInt32(binOpLimitCall),
  1927. Convert.ToInt32(binOpLimitPut));
  1928. }
  1929.  
  1930.  
  1931. if (createduserID> 0)
  1932. {
  1933. if (login)
  1934. {
  1935. return new OperationResult(false, MessageConstants.INVALID_SESSION_TEXT, null);
  1936. }
  1937. else
  1938. {
  1939. OperationResult userResult = UsersOperations.LoadUserDetailsByEmail(email);
  1940. DataTable dataTable = userResult.ResultValue as DataTable;
  1941.  
  1942. }
  1943.  
  1944. if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(session))
  1945. {
  1946. ExternalParametersOperations.Save(createduserID, "id", id);
  1947. ExternalParametersOperations.Save(createduserID, "session", session);
  1948. }
  1949.  
  1950. string defaultUserBalanceAlert = ConfigurationManager.AppSettings["DefaultUserBalanceAlert"] ?? "";
  1951.  
  1952. if (!String.IsNullOrEmpty(defaultUserBalanceAlert))
  1953. {
  1954. UsersOperations.SetUserBalanceAlert(createduserID, Convert.ToInt32(defaultUserBalanceAlert));
  1955. }
  1956.  
  1957. string defaultUserPnLAlert = ConfigurationManager.AppSettings["DefaultUserPnLAlert"] ?? "";
  1958.  
  1959. if (!String.IsNullOrEmpty(defaultUserPnLAlert))
  1960. {
  1961. UsersOperations.SetUserPnLAlert(createduserID, Convert.ToInt32(defaultUserPnLAlert));
  1962. }
  1963.  
  1964. if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["DefaultBonus"]) && bonusAmount == 0)
  1965. {
  1966. bonusAmount = decimal.Parse(ConfigurationManager.AppSettings["DefaultBonus"]);
  1967. }
  1968.  
  1969. if (bonusAmount > 0)
  1970. {
  1971. return Credit(bonusAmount, (int)TransactionTypes.Bonus, (int)TransactionSubTypes.NewAccount, createduserID);
  1972. }
  1973. else
  1974. {
  1975. return result;
  1976. }
  1977. }
  1978. }
  1979. }
  1980.  
  1981. return result;
  1982. }
  1983.  
  1984. #endregion
  1985. }
  1986. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement