Guest User

Untitled

a guest
Nov 16th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 207.12 KB | None | 0 0
  1. public static class SessionWrapper
  2. {
  3.  
  4. //---------------------------------------------------------------
  5.  
  6. public static PermissionSession PermissionSession
  7. {
  8. get { return GetFromSession<PermissionSession>("PermissionSession"); }
  9. set { SetInSession<PermissionSession>("PermissionSession", value); }
  10. }
  11.  
  12. private static T GetFromSession<T>(string key)
  13. {
  14. object obj = HttpContext.Current.Session[key];
  15. if (obj == null)
  16. {
  17. return default(T);
  18. }
  19. return (T)obj;
  20. }
  21. private static void SetInSession<T>(string key, T value)
  22. {
  23. if (value == null)
  24. {
  25. HttpContext.Current.Session.Remove(key);
  26. }
  27. else
  28. {
  29. HttpContext.Current.Session[key] = value;
  30. }
  31. }
  32. private static T GetFromApplication<T>(string key)
  33. {
  34. return (T)HttpContext.Current.Application[key];
  35. }
  36. private static void SetInApplication<T>(string key, T value)
  37. {
  38. if (value == null)
  39. {
  40. HttpContext.Current.Application.Remove(key);
  41. }
  42. else
  43. {
  44. HttpContext.Current.Application[key] = value;
  45. }
  46. }
  47.  
  48. }
  49.  
  50. public class Q_User
  51. {
  52. public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
  53.  
  54. public bool AuthenticateUser(string username, string password, out int userid)
  55. {
  56. bool result = false;
  57. userid = 0;
  58. result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && u.administrator.HasValue && u.administrator.Value == true && (u.broker.HasValue == false || u.broker.Value == false)); // Check Administrator
  59. if (!result)
  60. {
  61. result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && u.broker.HasValue && u.broker.Value == true && (u.administrator.HasValue == false || u.administrator.Value == false)); // Check Broker
  62. if (!result)
  63. {
  64. result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && (u.administrator.HasValue == false || u.administrator.Value == false) && (u.broker.HasValue == false || u.broker.Value == false)); // Check User
  65. if (!result)
  66. {
  67. result = ctx.tblusers.Any(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == true && u.broker.Value == true)); // Check Manager
  68. }
  69. }
  70. }
  71.  
  72. if (result)
  73. {
  74. userid = ctx.tblusers.Where(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true).Select(u => u.userid).FirstOrDefault();
  75.  
  76. }
  77. return result;
  78. }
  79. }
  80.  
  81. Q Setting
  82. ======================================================================================
  83.  
  84. using System;
  85. using System.Collections.Generic;
  86. using System.Linq;
  87. using System.Web;
  88. using Occfinance_Data;
  89. using Occfinance.Models;
  90. using System.Net;
  91. using System.Data.SqlClient;
  92. using System.Data;
  93. using Occfinance.Helpers;
  94. using System.Configuration;
  95. using Mandrill;
  96. using System.Drawing;
  97. using System.IO;
  98. using System.Web.Configuration;
  99.  
  100. namespace Occfinance.Code
  101. {
  102. public class Q_settings
  103. {
  104. public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
  105. System.Web.HttpContext con = HttpContext.Current;
  106.  
  107. #region Add Broker
  108. /// <summary>
  109. /// Adding Broker
  110. /// </summary>
  111. /// <param name="brokername"></param>
  112. /// <param name="username"></param>
  113. /// <param name="accountid"></param>
  114. /// <param name="TeamsArray"></param>
  115. /// <param name="PrimaryContact"></param>
  116. /// <param name="SecondaryContact"></param>
  117. /// <param name="Address1"></param>
  118. /// <param name="Address2"></param>
  119. /// <param name="OtherDetails"></param>
  120. /// <param name="title"></param>
  121. /// <param name="fax"></param>
  122. /// <param name="qualification"></param>
  123. /// <param name="brkImage"></param>
  124. /// <returns></returns>
  125. public bool AddBroker(string brokername, string username, out int accountid, List<tblTeamMember> TeamsArray, string PrimaryContact, string SecondaryContact, string Address1, string Address2, string OtherDetails, string title, string fax, string qualification, string brkImage = "")
  126. {
  127. bool result = false;
  128. accountid = 0;
  129. try
  130. {
  131. if (con.Session["LoggedInUserAccountId"] != null)
  132. {
  133.  
  134. if (ctx.tblusers.Where(c => c.username.ToLower().Trim() == username.ToLower().Trim() && c.active == true && !string.IsNullOrEmpty(c.username)).Any())
  135. {
  136. result = false;
  137. }
  138. else
  139. {
  140. try
  141. {
  142. if (!string.IsNullOrWhiteSpace(brkImage))
  143. {
  144. brkImage = System.IO.Path.GetFileName(brkImage);
  145. }
  146. }
  147. catch { }
  148.  
  149. int parentaccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
  150.  
  151. var u = ctx.tblusers.Add(new tbluser()
  152. {
  153. account = parentaccountId,
  154. username = username,
  155. password = "test",
  156. active = true,
  157. administrator = false,
  158. Title = title,
  159. brokername = brokername,
  160. broker = true,
  161. PrimaryContact = PrimaryContact ?? "",
  162. SecondaryContact = SecondaryContact ?? "",
  163. Address1 = Address1 ?? "",
  164. Address2 = Address2 ?? "",
  165. FAX = fax,
  166. Qualification = qualification,
  167. OtherDetails = OtherDetails ?? "",
  168. BrokerImage = brkImage
  169.  
  170. });
  171. ctx.SaveChanges();
  172. result = true;
  173. accountid = u.userid;
  174.  
  175. //create Thumb
  176. if (!string.IsNullOrWhiteSpace(brkImage))
  177. {
  178. string path = System.Web.HttpContext.Current.Server.MapPath("~/Content/BrokerImages/");
  179. string fullImagePath = path + brkImage;
  180. if (File.Exists(fullImagePath))
  181. {
  182. string thumbPath = path + "Thumb/" + u.userid + ".jpg";
  183. System.Drawing.Image image = System.Drawing.Image.FromFile(fullImagePath);
  184. System.Drawing.Image thumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
  185. thumb.Save(thumbPath, System.Drawing.Imaging.ImageFormat.Jpeg);
  186. }
  187. }
  188.  
  189.  
  190. string body = "Hi " + brokername + ", <br /><br />";
  191. body += "Your email id: " + username + "<br /><br />";
  192. body += "Password: test <br /><br />";
  193. body += "Regards: <br /><br />";
  194. body += "Apptrack Admin";
  195.  
  196. //-------------------------------------
  197. List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
  198.  
  199. var _mailDrilEmails = new List<Mandrill.EmailAddress>();
  200. Mandrill.EmailAddress objEm = new Mandrill.EmailAddress();
  201. objEm.email = username;
  202. objEm.name = brokername;
  203. _mailDrilEmails.Add(objEm);
  204.  
  205. //Man DRILL ********************************************************************
  206.  
  207. var domain = "occfinance.com";
  208. Mandrill.EmailMessage message = new Mandrill.EmailMessage();
  209. var _mandrillMessage = new List<Mandrill.EmailMessage>();
  210.  
  211. message.to = _mailDrilEmails;
  212. message.html = body;
  213. message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
  214. message.from_name = "OCC";
  215. message.subject = "Your Apptrack Credential";
  216. message.inline_css = true;
  217. message.signing_domain = domain;
  218. message.AddHeader("X-MC-SigningDomain", domain);
  219. message.AddHeader("X-MC-TrackingDomain", domain);
  220. _mandrillMessage.Add(message);
  221.  
  222. //********************************************************************************
  223.  
  224. // Manage The ManDRILLModel - 25-07-2014
  225.  
  226. var objMAN = new ManDRILLModel();
  227. objMAN.contactId = 0;
  228. objMAN.financeid = 0;
  229. objMAN.mailcontent = body;
  230. objMAN.MandrillMSG = message;
  231. objMAN.IsAppContact = false;
  232.  
  233. objMAN.notemsg = "";
  234.  
  235. _mandrillOBJ.Add(objMAN);
  236.  
  237. int userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  238. WebUtility.SendMailViaManDRILL(_mandrillOBJ, userId);
  239. //-------------------------------------
  240.  
  241.  
  242. int _type = 1;
  243. if (TeamsArray != null)
  244. {
  245. foreach (var obj in TeamsArray)
  246. {
  247. if (obj.IsActive.HasValue && obj.IsActive.Value == true)
  248. _type = 1;
  249. else
  250. _type = 2;
  251.  
  252. AddTeamMembers(obj.TeamId.HasValue ? obj.TeamId.Value : 0, u.userid, userId, _type);
  253. }
  254. }
  255. AddAdminTeamMembers(parentaccountId, parentaccountId, u.userid, userId, 1);
  256.  
  257. // Add Default Permission ---------------------------
  258. // 1- Admin User, 2- Broker, 3- General User As per the client response ON 21-07-2014
  259. try
  260. {
  261. AddDefaultPermission(2, u.userid, parentaccountId, userId);
  262. }
  263. catch
  264. {
  265. }
  266. }
  267.  
  268. }
  269. return result;
  270. }
  271. catch (Exception)
  272. {
  273. return result;
  274. }
  275. }
  276.  
  277.  
  278. #endregion
  279.  
  280. #region Update Broker
  281. /// <summary>
  282. /// Updating broker
  283. /// </summary>
  284. /// <param name="brokername"></param>
  285. /// <param name="username"></param>
  286. /// <param name="brokerid"></param>
  287. /// <param name="accountid"></param>
  288. /// <param name="TeamsArray"></param>
  289. /// <param name="PrimaryContact"></param>
  290. /// <param name="SecondaryContact"></param>
  291. /// <param name="Address1"></param>
  292. /// <param name="Address2"></param>
  293. /// <param name="OtherDetails"></param>
  294. /// <param name="title"></param>
  295. /// <param name="fax"></param>
  296. /// <param name="qualification"></param>
  297. /// <param name="brkImage"></param>
  298. /// <returns></returns>
  299. public bool UpdateBroker(string brokername, string username, int brokerid, out int accountid, List<tblTeamMember> TeamsArray, string PrimaryContact, string SecondaryContact, string Address1, string Address2, string OtherDetails, string title, string fax, string qualification, string brkImage = "")
  300. {
  301. bool result = false;
  302. accountid = 0;
  303. try
  304. {
  305. if (con.Session["LoggedInUserAccountId"] != null && brokerid > 0)
  306. {
  307. if (ctx.tblusers.Where(c => c.username.ToLower().Trim() == username.ToLower().Trim() && c.active == true && c.userid != brokerid && !string.IsNullOrEmpty(c.username)).Any())
  308. {
  309. result = false;
  310. }
  311. else
  312. {
  313. try
  314. {
  315. if (!string.IsNullOrWhiteSpace(brkImage))
  316. {
  317. brkImage = System.IO.Path.GetFileName(brkImage);
  318. }
  319. }
  320. catch { }
  321.  
  322. int parentaccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
  323. var u = ctx.tblusers.Where(c => c.userid == brokerid).FirstOrDefault();
  324. u.account = parentaccountId;//broker.accountid,
  325. u.username = username;
  326. u.brokername = brokername;
  327. u.Title = title;
  328. u.PrimaryContact = PrimaryContact ?? "";
  329. u.SecondaryContact = SecondaryContact ?? "";
  330. u.Address1 = Address1 ?? "";
  331. u.Address2 = Address2 ?? "";
  332. u.FAX = fax;
  333. u.Qualification = qualification;
  334. u.OtherDetails = OtherDetails ?? "";
  335. u.BrokerImage = brkImage;
  336. // u.TeamId = teamid;
  337. ctx.SaveChanges();
  338. result = true;
  339. accountid = u.userid;
  340.  
  341. //create Thumb
  342. if (!string.IsNullOrWhiteSpace(brkImage))
  343. {
  344. string path = System.Web.HttpContext.Current.Server.MapPath("~/Content/BrokerImages/");
  345. string fullImagePath = path + brkImage;
  346. if (File.Exists(fullImagePath))
  347. {
  348. string thumbPath = path + "Thumb/" + u.userid + ".jpg";
  349. System.Drawing.Image image = System.Drawing.Image.FromFile(fullImagePath);
  350. System.Drawing.Image thumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
  351. thumb.Save(thumbPath, System.Drawing.Imaging.ImageFormat.Jpeg);
  352. }
  353. }
  354.  
  355. string body = "Hi " + brokername + ", <br /><br />";
  356. body += "Your updated email id: " + username + "<br /><br />";
  357. body += "Password: " + u.password + " <br /><br />";
  358. body += "Regards: <br /><br />";
  359. body += "Apptrack Admin";
  360.  
  361. //------------------------------------------------------------
  362.  
  363. List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
  364.  
  365. var _mailDrilEmails = new List<Mandrill.EmailAddress>();
  366. Mandrill.EmailAddress objEm = new Mandrill.EmailAddress();
  367. objEm.email = username;
  368. objEm.name = brokername;
  369. _mailDrilEmails.Add(objEm);
  370.  
  371. //Man DRILL ********************************************************************
  372.  
  373. var domain = "occfinance.com";
  374. Mandrill.EmailMessage message = new Mandrill.EmailMessage();
  375. var _mandrillMessage = new List<Mandrill.EmailMessage>();
  376.  
  377. message.to = _mailDrilEmails;
  378. message.html = body;
  379. message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
  380. message.from_name = "OCC";
  381. message.subject = "Your Apptrack Credential";
  382. message.inline_css = true;
  383. message.signing_domain = domain;
  384. message.AddHeader("X-MC-SigningDomain", domain);
  385. message.AddHeader("X-MC-TrackingDomain", domain);
  386. _mandrillMessage.Add(message);
  387.  
  388. //********************************************************************************
  389.  
  390. // Manage The ManDRILLModel - 25-07-2014
  391.  
  392. var objMAN = new ManDRILLModel();
  393. objMAN.contactId = 0;
  394. objMAN.financeid = 0;
  395. objMAN.mailcontent = body;
  396. objMAN.MandrillMSG = message;
  397. objMAN.IsAppContact = false;
  398.  
  399. objMAN.notemsg = "";
  400.  
  401. _mandrillOBJ.Add(objMAN);
  402.  
  403. int userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  404. WebUtility.SendMailViaManDRILL(_mandrillOBJ, userId);
  405.  
  406. //------------------------------------------------------------
  407.  
  408.  
  409.  
  410. int _type = 1;
  411. if (TeamsArray != null)
  412. {
  413. foreach (var obj in TeamsArray)
  414. {
  415. if (obj.IsActive.HasValue && obj.IsActive.Value == true)
  416. _type = 1;
  417. else
  418. _type = 2;
  419.  
  420. AddTeamMembers(obj.TeamId.HasValue ? obj.TeamId.Value : 0, u.userid, userId, _type);
  421. }
  422. }
  423. }
  424.  
  425. }
  426. return result;
  427. }
  428. catch (Exception ex)
  429. {
  430. Helper.ErrorLog(ex.InnerException, "Q_Settings", "UpdateBroker", ex.Message);
  431. return result;
  432. }
  433. }
  434.  
  435. /// <summary>
  436. /// Updating Team Broker
  437. /// </summary>
  438. /// <param name="brokername"></param>
  439. /// <param name="username"></param>
  440. /// <param name="brokerid"></param>
  441. /// <param name="accountid"></param>
  442. /// <param name="TeamsArray"></param>
  443. /// <returns></returns>
  444. public bool UpdateTeamBroker(string brokername, string username, int brokerid, out int accountid, List<tblAdminTeammeber> TeamsArray)
  445. {
  446. bool result = false;
  447. accountid = 0;
  448. try
  449. {
  450. if (con.Session["LoggedInUserAccountId"] != null && brokerid > 0)
  451. {
  452.  
  453.  
  454. int parentaccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
  455. var u = ctx.tblusers.Where(c => c.userid == brokerid).FirstOrDefault();
  456.  
  457. u.AdminId = 0;
  458. ctx.SaveChanges();
  459. result = true;
  460. accountid = u.userid;
  461.  
  462. int userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  463. int _type = 1;
  464. if (TeamsArray != null)
  465. {
  466. foreach (var obj in TeamsArray)
  467. {
  468. if (obj.IsActive.HasValue && obj.IsActive.Value == true)
  469. _type = 1;
  470. else
  471. _type = 2;
  472.  
  473. AddAdminTeamMembers(obj.AdminTeamId.HasValue ? obj.AdminTeamId.Value : 0, obj.AdminTeamId.HasValue ? obj.AdminTeamId.Value : 0, u.userid, userId, _type);
  474. }
  475. }
  476.  
  477. }
  478. return result;
  479. }
  480. catch (Exception ex)
  481. {
  482. Helper.ErrorLog(ex.InnerException, "Q_setting", "UpdateTeamBroker", ex.Message);
  483. return result;
  484. }
  485. }
  486.  
  487.  
  488. #endregion
  489.  
  490. #region Add Team
  491. /// <summary>
  492. /// Adding Team
  493. /// </summary>
  494. /// <param name="teamName"></param>
  495. /// <param name="managerId"></param>
  496. /// <param name="teamid"></param>
  497. /// <returns></returns>
  498. public bool AddTeam(string teamName, int managerId, out int teamid)
  499. {
  500. bool result = false;
  501. teamid = 0;
  502. try
  503. {
  504.  
  505. if (con.Session["LoggedInUserAccountId"] != null)
  506. {
  507. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  508. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  509.  
  510. SqlParameter[] Param = new SqlParameter[9];
  511. Param[0] = new SqlParameter("@AccountId", AccountId);
  512. Param[1] = new SqlParameter("@CompanyName", "0");
  513. Param[2] = new SqlParameter("@TeamName", teamName);
  514. Param[3] = new SqlParameter("@Regions", "0");
  515. Param[4] = new SqlParameter("@ManagerId", managerId);
  516. Param[5] = new SqlParameter("@EntryBy", userId);
  517. Param[6] = new SqlParameter("@IsActive", true);
  518. Param[7] = new SqlParameter("@IsDelete", false);
  519.  
  520. Param[8] = new SqlParameter("@TeamId", 0);
  521. Param[8].Direction = ParameterDirection.Output;
  522. string _procedurename = "tblTeamAdd";
  523.  
  524. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  525.  
  526. teamid = Convert.ToInt32(Param[8] != null ? Param[8].SqlValue.ToString() : "0");
  527.  
  528. if (teamid > 0)
  529. {
  530. if (AddTeamMembers(teamid, managerId, userId, 1) > 0)
  531. result = true;
  532. }
  533. }
  534. return result;
  535. }
  536. catch (Exception ex)
  537. {
  538. Helper.ErrorLog(ex.InnerException, "Q_Setting", "AddTeam", ex.Message);
  539. return result;
  540. }
  541. }
  542.  
  543. #endregion
  544.  
  545. #region Add Team Members
  546. /// <summary>
  547. /// Adding Team member
  548. /// </summary>
  549. /// <param name="TeamId"></param>
  550. /// <param name="MemberId"></param>
  551. /// <param name="userId"></param>
  552. /// <param name="Type"></param>
  553. /// <returns></returns>
  554. public int AddTeamMembers(int TeamId, int MemberId, int userId, int Type)
  555. {
  556. int chk = 0;
  557. try
  558. {
  559. if (con.Session["LoggedInUserAccountId"] != null)
  560. {
  561. SqlParameter[] Param = new SqlParameter[6];
  562. Param[0] = new SqlParameter("@TeamId", TeamId);
  563. Param[1] = new SqlParameter("@MemberId", MemberId);
  564. Param[2] = new SqlParameter("@EntryBy", userId);
  565. Param[3] = new SqlParameter("@IsActive", true);
  566. Param[4] = new SqlParameter("@IsDelete", false);
  567. Param[5] = new SqlParameter("@Type", Type);
  568.  
  569. string _procedurename = "tblTeamMembersAdd";
  570.  
  571. chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  572.  
  573. }
  574.  
  575. }
  576. catch (Exception ex)
  577. {
  578. Helper.ErrorLog(ex.InnerException, "Q_Setting", "Addteammembers", ex.Message);
  579. }
  580. return chk;
  581. }
  582.  
  583.  
  584. #endregion
  585.  
  586. #region Update Team
  587. /// <summary>
  588. /// Update team
  589. /// </summary>
  590. /// <param name="teamName"></param>
  591. /// <param name="managerId"></param>
  592. /// <param name="editteamId"></param>
  593. /// <param name="teamid"></param>
  594. /// <returns></returns>
  595. public bool UpdateTeam(string teamName, int managerId, int editteamId, out int teamid)
  596. {
  597. bool result = false;
  598. teamid = 0;
  599. try
  600. {
  601. if (con.Session["LoggedInUserAccountId"] != null)
  602. {
  603. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  604. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  605. SqlParameter[] Param = new SqlParameter[10];
  606. Param[0] = new SqlParameter("@TeamId", editteamId);
  607. Param[1] = new SqlParameter("@AccountId", AccountId);
  608. Param[2] = new SqlParameter("@CompanyName", "0");
  609. Param[3] = new SqlParameter("@TeamName", teamName);
  610. Param[4] = new SqlParameter("@Regions", "0");
  611. Param[5] = new SqlParameter("@ManagerId", managerId);
  612. Param[6] = new SqlParameter("@UpdateBy", userId);
  613. Param[7] = new SqlParameter("@IsActive", true);
  614. Param[8] = new SqlParameter("@IsDelete", false);
  615.  
  616. Param[9] = new SqlParameter("@Chk", 0);
  617. Param[9].Direction = ParameterDirection.Output;
  618. string _procedurename = "tblTeamUpdate";
  619.  
  620. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  621.  
  622. teamid = Convert.ToInt32(Param[9] != null ? Param[9].SqlValue.ToString() : "0");
  623.  
  624. if (teamid > 0)
  625. {
  626. if (AddTeamMembers(editteamId, managerId, userId, 1) > 0)
  627. result = true;
  628. }
  629. }
  630. return result;
  631. }
  632. catch (Exception ex)
  633. {
  634. Helper.ErrorLog(ex.InnerException, "Q_Setting", "UpdateTeam", ex.Message);
  635. return result;
  636. }
  637. }
  638.  
  639. #endregion
  640.  
  641. #region Delete Team
  642. /// <summary>
  643. /// Deleting Team
  644. /// </summary>
  645. /// <param name="teamid"></param>
  646. /// <param name="managerId"></param>
  647. /// <param name="chk"></param>
  648. /// <returns></returns>
  649. public bool DeleteTeam(int teamid, int managerId, out int chk)
  650. {
  651. bool result = false;
  652. chk = 0;
  653. try
  654. {
  655. if (con.Session["LoggedInUserAccountId"] != null)
  656. {
  657. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  658. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  659. SqlParameter[] Param = new SqlParameter[4];
  660. Param[0] = new SqlParameter("@TeamId", teamid);
  661. Param[1] = new SqlParameter("@ManagerId", managerId);
  662. Param[2] = new SqlParameter("@UpdateBy", userId);
  663.  
  664. Param[3] = new SqlParameter("@Chk", 0);
  665. Param[3].Direction = ParameterDirection.Output;
  666. string _procedurename = "tblTeamDelete";
  667.  
  668. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  669. chk = Convert.ToInt32(Param[3] != null ? Param[3].SqlValue.ToString() : "0");
  670.  
  671. if (chk > 0)
  672. {
  673. result = true;
  674. }
  675. }
  676. return result;
  677. }
  678. catch (Exception ex)
  679. {
  680. Helper.ErrorLog(ex.InnerException, "Q_Setting", "deleteTeam", ex.Message);
  681. return result;
  682. }
  683. }
  684.  
  685. #endregion
  686.  
  687. #region Delete Broker
  688. /// <summary>
  689. /// Delete Broker
  690. /// </summary>
  691. /// <param name="brokerid"></param>
  692. /// <returns></returns>
  693. public bool DeleteBroker(int brokerid)
  694. {
  695. bool result = false;
  696. try
  697. {
  698. if (con.Session["LoggedInUserAccountId"] != null)
  699. {
  700. int parentaccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"]);
  701. var brokeruser = ctx.tblusers.Where(b => b.userid == brokerid && b.active && b.broker.HasValue && b.broker.Value == true).Select(b => b).FirstOrDefault();
  702. if (brokeruser != null)
  703. {
  704. if (brokeruser != null)
  705. {
  706. brokeruser.active = false;
  707. brokeruser.TeamId = 0;
  708. ctx.SaveChanges();
  709. result = true;
  710. TeamMembersDeleteByMemberId(brokerid);
  711. int userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  712. AddAdminTeamMembers(parentaccountId, parentaccountId, brokerid, userId, 2);
  713. }
  714. }
  715. }
  716. return result;
  717. }
  718. catch (Exception ex)
  719. {
  720. Helper.ErrorLog(ex.InnerException, "Q_Setting", "deleteBroker", ex.Message);
  721. return result;
  722. }
  723. }
  724.  
  725. #endregion
  726.  
  727. #region Change LoggedIn User Password
  728. /// <summary>
  729. /// Changing logged inuser Password
  730. /// </summary>
  731. /// <param name="userId"></param>
  732. /// <param name="oldPassword"></param>
  733. /// <param name="newPassword"></param>
  734. /// <returns></returns>
  735. public bool ChangeLoggedUserPassword(int userId, string oldPassword, string newPassword)
  736. {
  737. bool result = false;
  738. try
  739. {
  740. var usr = ctx.tblusers.Where(u => u.userid == userId && u.password == oldPassword).Select(u => u).SingleOrDefault();
  741. if (usr != null)
  742. {
  743. usr.password = newPassword;
  744. ctx.SaveChanges();
  745. result = true;
  746. }
  747. return result;
  748. }
  749. catch (Exception ex)
  750. {
  751. Helper.ErrorLog(ex.InnerException, "Q_Setting", "ChangedLoggedUserPassword", ex.Message);
  752. return result;
  753. }
  754.  
  755. }
  756. #endregion
  757.  
  758. #region Find Broker for logged in user
  759. /// <summary>
  760. /// Finding broker for logged in user
  761. /// </summary>
  762. /// <param name="userid"></param>
  763. /// <returns></returns>
  764. public List<Clients> FindBrokerForLoggedInUser(int userid)
  765. {
  766. bool flag = false;
  767. List<Clients> brokers = new List<Clients>();
  768. Clients result = new Clients();
  769. Q_Application _obj = new Q_Application();
  770. try
  771. {
  772. int teamId = 0;
  773. string brokersIds = "";
  774. int _userType = 0;
  775. int _accountId = 0;
  776. _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
  777.  
  778. //Updated With Store Procedure For Navigation Delay ********* 7/7/2014 ********************************************
  779.  
  780. var _Id = 0;
  781.  
  782. if (_userType == (int)UserType.Admin)
  783. _Id = _accountId;
  784. else if (_userType == (int)UserType.Manager)
  785. _Id = teamId;
  786. else if (_userType == (int)UserType.Broker)
  787. _Id = userid;
  788.  
  789. SqlParameter[] Param = new SqlParameter[2];
  790. Param[0] = new SqlParameter("@UserType", _userType);
  791. Param[1] = new SqlParameter("@ID", _Id);
  792. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindBrokerForLoggedInUser", Param);
  793. brokers = (from DataRow row in dt.Rows
  794. select new Clients
  795. {
  796. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  797. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  798. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  799. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  800. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  801. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  802. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  803. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  804. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  805. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  806. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  807. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  808. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
  809. TeamNames = ((row["TeamNames"] == DBNull.Value || row["TeamNames"] == null) ? " " : row["TeamNames"]).ToString(),
  810. AdminTeamName = ((row["AdminTeamName"] == DBNull.Value || row["AdminTeamName"] == null) ? " " : row["AdminTeamName"]).ToString(),
  811. PrimaryContact = ((row["PrimaryContact"] == DBNull.Value || row["PrimaryContact"] == null) ? " " : row["PrimaryContact"]).ToString(),
  812. SecondaryContact = ((row["SecondaryContact"] == DBNull.Value || row["SecondaryContact"] == null) ? " " : row["SecondaryContact"]).ToString(),
  813. Address1 = ((row["Address1"] == DBNull.Value || row["Address1"] == null) ? " " : row["Address1"]).ToString(),
  814. Address2 = ((row["Address2"] == DBNull.Value || row["Address2"] == null) ? " " : row["Address2"]).ToString(),
  815. OtherDetails = ((row["OtherDetails"] == DBNull.Value || row["OtherDetails"] == null) ? " " : row["OtherDetails"]).ToString(),
  816. Title = ((row["Title"] == DBNull.Value || row["Title"] == null) ? " " : row["Title"]).ToString(),
  817. FAX = ((row["FAX"] == DBNull.Value || row["FAX"] == null) ? " " : row["FAX"]).ToString(),
  818. Qualification = ((row["Qualification"] == DBNull.Value || row["Qualification"] == null) ? " " : row["Qualification"]).ToString(),
  819. BrokerImage = ((row["BrokerImage"] == DBNull.Value || row["BrokerImage"] == null || row["BrokerImage"] == "") ? "noimage.jpg" : row["BrokerImage"]).ToString()
  820.  
  821.  
  822.  
  823. }).ToList();
  824.  
  825. //**********************************************************************************
  826.  
  827.  
  828. return brokers;
  829. }
  830. catch (Exception ex)
  831. {
  832. Helper.ErrorLog(ex.InnerException, "Q_setting", "FindBrokerForLoggedinUser");
  833. return brokers;
  834. }
  835. }
  836. /// <summary>
  837. /// Brokers for logged in user
  838. /// </summary>
  839. /// <param name="accid">Account Id</param>
  840. /// <param name="userid">User Id</param>
  841. /// <returns></returns>
  842. public List<Clients> FindBrokerForLoggedInUserWithUserId(int accid, int userid)
  843. {
  844. bool flag = false;
  845. List<Clients> brokers = new List<Clients>();
  846. Q_Application _obj = new Q_Application();
  847. try
  848. {
  849. int teamId = 0;
  850. string brokersIds = "";
  851. int _userType = 0;
  852. int _accountId = 0;
  853. _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
  854. var _Id = 0;
  855. if (_userType == (int)UserType.Admin)
  856. _Id = _accountId;
  857. else if (_userType == (int)UserType.Manager)
  858. _Id = teamId;
  859. else if (_userType == (int)UserType.Broker)
  860. _Id = userid;
  861. else if (_userType == (int)UserType.GeneralUser)
  862. {
  863. int account = ctx.tblaccounts.Where(u => u.accountid == _accountId).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
  864. _Id = account;
  865. }
  866.  
  867. SqlParameter[] Param = new SqlParameter[2];
  868. Param[0] = new SqlParameter("@UserType", _userType);
  869. Param[1] = new SqlParameter("@ID", _Id);
  870. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindBrokerForLoggedInUserWithUserId", Param);
  871. brokers = (from DataRow row in dt.Rows
  872. select new Clients
  873. {
  874. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  875. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  876. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  877. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  878. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  879. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  880. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  881. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  882. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  883. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  884. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  885. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  886. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
  887. }).ToList();
  888. return brokers;
  889. }
  890. catch (Exception ex)
  891. {
  892. Helper.ErrorLog(ex.InnerException, "Q_setting", "FindBrokerforLoggedInUserWithUserId");
  893. return brokers;
  894. }
  895. }
  896.  
  897. public bool DeleteFactFindUserById(long id)
  898. {
  899. if (id > 0)
  900. {
  901. try
  902. {
  903. tblUser_FactFind data;
  904. data = ctx.tblUser_FactFind.Where(x => x.Client_ID == id).FirstOrDefault();
  905. if (data != null)
  906. {
  907. data.IsActive = false;
  908. data.IsDeleted = true;
  909. ctx.SaveChanges();
  910. return true;
  911. }
  912. }
  913. catch (Exception ex)
  914. {
  915. Helper.ErrorLog(ex.InnerException, "Q_setting", "DeleteFactFindUserById");
  916. }
  917. }
  918. return false;
  919. }
  920.  
  921. /// <summary>
  922. /// Get All Intellic Users
  923. /// </summary>
  924. /// <returns></returns>
  925. public DataTable GetAllIntellicUsers()
  926. {
  927. try
  928. {
  929. SqlParameter[] Param = new SqlParameter[2];
  930. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAll_tblUser_FactFind_For_Intellicalc", Param);
  931. return dt;
  932. }
  933. catch (Exception ex)
  934. {
  935. Helper.ErrorLog(ex.InnerException, "Q_setting", "GetAllIntellicUsers");
  936. return null;
  937. }
  938. }
  939.  
  940. /// <summary>
  941. /// Save Adviser For Intellicalc
  942. /// </summary>
  943. /// <param name="clientId"></param>
  944. /// <param name="brokerId"></param>
  945. /// <returns></returns>
  946. public int SaveAdviserForIntellicalc(int clientId, int brokerId)
  947. {
  948. try
  949. {
  950. SqlParameter[] Param = new SqlParameter[2];
  951. Param[0] = new SqlParameter("@clientId", clientId);
  952. Param[1] = new SqlParameter("@adviserId", brokerId);
  953. SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "sp_Save_Adviser_For_Intellicalc", Param);
  954.  
  955. }
  956. catch (Exception ex)
  957. {
  958. Helper.ErrorLog(ex.InnerException, "Q_setting", "SaveAdviserForIntellicalc");
  959. return 0;
  960. }
  961. return 1;
  962. }
  963.  
  964.  
  965. /// <summary>
  966. /// Get All Intellic Users
  967. /// </summary>
  968. /// <returns></returns>
  969. public DataTable GetAllFactfindUsers(int adviserId = 0)
  970. {
  971. try
  972. {
  973. SqlParameter[] Param = new SqlParameter[2];
  974. Param[0] = new SqlParameter("@adviserId", adviserId);
  975. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAll_tblUser_FactFind_For_FactFind", Param);
  976. return dt;
  977. }
  978. catch (Exception ex)
  979. {
  980. Helper.ErrorLog(ex.InnerException, "Q_setting", "GetAllFactfindUsers");
  981. return null;
  982. }
  983. }
  984.  
  985. public int SaveAdviserForTblUserFactFind(int clientId, int brokerId)
  986. {
  987. try
  988. {
  989. SqlParameter[] Param = new SqlParameter[2];
  990. Param[0] = new SqlParameter("@clientId", clientId);
  991. Param[1] = new SqlParameter("@adviserId", brokerId);
  992. SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "sp_Save_Adviser_For_tbluser_FactFind", Param);
  993. }
  994. catch (Exception ex)
  995. {
  996. Helper.ErrorLog(ex.InnerException, "Q_setting", "SaveAdviserForTblUserFactFind");
  997. return 0;
  998. }
  999. return 1;
  1000. }
  1001.  
  1002. public DataTable GetFactfindUsersByClient_Id(int client_id)
  1003. {
  1004. try
  1005. {
  1006. SqlParameter[] Param = new SqlParameter[2];
  1007. Param[0] = new SqlParameter("@client_id", client_id);
  1008. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAll_tblUser_FactFind_ByClientid", Param);
  1009. return dt;
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. Helper.ErrorLog(ex.InnerException, "Q_setting", "GetFactfindUsersByClient_Id");
  1014. return null;
  1015. }
  1016. }
  1017.  
  1018.  
  1019. /// <summary>
  1020. /// Find broker for logged in user with account Id
  1021. /// </summary>
  1022. /// <param name="accid"></param>
  1023. /// <returns></returns>
  1024. public List<Clients> FindBrokerForLoggedInBrokerWithAccountId(int accid)
  1025. {
  1026. bool flag = false;
  1027. List<Clients> brokers = new List<Clients>();
  1028. Q_Application _obj = new Q_Application();
  1029.  
  1030. try
  1031. {
  1032.  
  1033.  
  1034. SqlParameter[] Param = new SqlParameter[2];
  1035. Param[0] = new SqlParameter("@UserType", 1);
  1036. Param[1] = new SqlParameter("@ID", accid);
  1037. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindBrokerForLoggedInUserWithUserId", Param);
  1038.  
  1039. brokers = (from DataRow row in dt.Rows
  1040. select new Clients
  1041. {
  1042. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  1043. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  1044. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  1045. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  1046. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  1047. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  1048. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  1049. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  1050. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  1051. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  1052. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  1053. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  1054. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
  1055. }).ToList();
  1056.  
  1057. //**********************************************************************************
  1058.  
  1059. return brokers;
  1060. }
  1061. catch (Exception ex)
  1062. {
  1063. Helper.ErrorLog(ex.InnerException, "Q_Setting", "FindBrokerForLoggedinUserwithAccountId", ex.Message);
  1064. return brokers;
  1065. }
  1066. }
  1067. /// <summary>
  1068. /// Finding Referral Broker for logged in user with account Id
  1069. /// </summary>
  1070. /// <param name="accid"></param>
  1071. /// <param name="userid"></param>
  1072. /// <param name="userType"></param>
  1073. /// <returns></returns>
  1074. public List<Clients> FindReferralBrokerForLoggedInBrokerWithAccountId(int accid, int userid, int userType)
  1075. {
  1076. bool flag = false;
  1077. List<Clients> brokers = new List<Clients>();
  1078. Q_Application _obj = new Q_Application();
  1079.  
  1080. try
  1081. {
  1082. SqlParameter[] Param = new SqlParameter[3];
  1083. Param[0] = new SqlParameter("@UserType", userType);
  1084. Param[1] = new SqlParameter("@ID", accid);
  1085. Param[2] = new SqlParameter("@UserId", userid);
  1086. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindReferralBrokerForLoggedInUserWithUserId", Param);
  1087.  
  1088. brokers = (from DataRow row in dt.Rows
  1089. select new Clients
  1090. {
  1091. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  1092. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  1093. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  1094. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  1095. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  1096. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  1097. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  1098. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  1099. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  1100. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  1101. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  1102. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  1103. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
  1104. }).ToList();
  1105.  
  1106. //**********************************************************************************
  1107.  
  1108. return brokers;
  1109. }
  1110. catch (Exception ex)
  1111. {
  1112. Helper.ErrorLog(ex.InnerException, "Q_Setting", "FindReferralBrokerForLoggedinBrokerWithscoountId", ex.Message);
  1113. return brokers;
  1114. }
  1115. }
  1116.  
  1117. public List<Clients> FindBrokerLoggedInBrokerId(int userid)
  1118. {
  1119. List<Clients> result = new List<Clients>();
  1120. try
  1121. {
  1122.  
  1123.  
  1124. result = (from u in ctx.tblusers.Where(u => u.userid == userid)
  1125. join t in ctx.tblTeams on u.TeamId equals t.TeamId into teamdata
  1126. from t in teamdata.DefaultIfEmpty()
  1127. select new Clients()
  1128. {
  1129. clientid = u.account,
  1130. parent = u.tblaccount.parent,
  1131. companyname = u.tblaccount.companyname,
  1132. TeamName = t.TeamName ?? "",
  1133. TeamId = u.TeamId ?? 0,
  1134. affiliateid = u.tblaccount.affiliateid,
  1135. telephone = u.tblaccount.telephone,
  1136. email = u.username,
  1137. contactname = u.brokername,
  1138. address = u.tblaccount.address,
  1139. userid = u.userid,
  1140. AdminId = u.AdminId,
  1141. countLeads = u.tblaccount.tblcontacts.Count()
  1142. }).ToList();
  1143.  
  1144. return result;
  1145. }
  1146. catch (Exception ex)
  1147. {
  1148. Helper.ErrorLog(ex.InnerException, "Q_Setting", "FindBrokerLoggedInBrokeRID", ex.Message);
  1149. return result;
  1150. }
  1151. }
  1152. /// <summary>
  1153. /// Find Admin Team List
  1154. /// </summary>
  1155. /// <param name="AccountId"></param>
  1156. /// <returns></returns>
  1157. public List<AdminTeam> FindAdminTeamList(int AccountId)
  1158. {
  1159. List<AdminTeam> result = new List<AdminTeam>();
  1160. SqlParameter[] Param = new SqlParameter[1];
  1161. if (AccountId > 0)
  1162. Param[0] = new SqlParameter("@AccountId", AccountId);
  1163. string _procedurename = "GetALLAdminTeam";
  1164. try
  1165. {
  1166. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1167.  
  1168. result = (from DataRow row in dt.Rows
  1169. select new AdminTeam
  1170. {
  1171. UserId = Convert.ToInt32(((row["UserId"] == DBNull.Value || row["UserId"] == null) ? "0" : row["UserId"]).ToString()),
  1172. AdminName = Convert.ToString((row["AdminName"] == DBNull.Value || row["AdminName"] == null) ? " " : row["AdminName"]),
  1173. AdminTeamName = Convert.ToString((row["AdminTeamName"] == DBNull.Value || row["AdminTeamName"] == null) ? " " : row["AdminTeamName"]),
  1174. AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
  1175. Brokers = Convert.ToString((row["Brokers"] == DBNull.Value || row["Brokers"] == null) ? " " : row["Brokers"]),
  1176.  
  1177. }).OrderBy(c => c.AdminTeamName).ToList();
  1178.  
  1179. return result;
  1180. }
  1181. catch (Exception ex)
  1182. {
  1183. Helper.ErrorLog(ex.InnerException, "Q_Setting", "FindAdminTeamList", ex.Message);
  1184. return result;
  1185. }
  1186. }
  1187.  
  1188. /// <summary>
  1189. /// Finding Team List
  1190. /// </summary>
  1191. /// <param name="AccountId"></param>
  1192. /// <returns></returns>
  1193. public List<Team> FindTeamList(int AccountId)
  1194. {
  1195. List<Team> result = new List<Team>();
  1196. SqlParameter[] Param = new SqlParameter[1];
  1197. Param[0] = new SqlParameter("@AccountId", AccountId);
  1198. string _procedurename = "tblTeamGetALL";
  1199. try
  1200. {
  1201. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1202.  
  1203. result = (from DataRow row in dt.Rows
  1204. select new Team
  1205. {
  1206. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  1207. TeamName = Convert.ToString((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]),
  1208. brokername = Convert.ToString((row["brokername"] == DBNull.Value || row["brokername"] == null) ? " " : row["brokername"]),
  1209. AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
  1210. IsActive = Convert.ToBoolean(((row["IsActive"] == DBNull.Value || row["IsActive"] == null) ? false : row["IsActive"]).ToString()),
  1211. IsDelete = Convert.ToBoolean(((row["IsDelete"] == DBNull.Value || row["IsDelete"] == null) ? false : row["IsDelete"]).ToString()),
  1212. CompanyName = Convert.ToString((row["CompanyName"] == DBNull.Value || row["CompanyName"] == null) ? " " : row["CompanyName"]),
  1213. TeamBrokers = Convert.ToString((row["TeamBrokers"] == DBNull.Value || row["TeamBrokers"] == null) ? " " : row["TeamBrokers"]),
  1214. ManagerId = Convert.ToInt32(((row["ManagerId"] == DBNull.Value || row["ManagerId"] == null) ? "0" : row["ManagerId"]).ToString()),
  1215. EntryBy = Convert.ToInt32(((row["EntryBy"] == DBNull.Value || row["EntryBy"] == null) ? "0" : row["EntryBy"]).ToString()),
  1216. UpdateBy = Convert.ToInt32(((row["UpdateBy"] == DBNull.Value || row["UpdateBy"] == null) ? "0" : row["UpdateBy"]).ToString()),
  1217. AddDate = (row["AddDate"] == DBNull.Value || row["AddDate"] == null) ? (DateTime?)null : Convert.ToDateTime(row["AddDate"]),
  1218.  
  1219. }).ToList();
  1220.  
  1221. return result;
  1222. }
  1223. catch (Exception ex)
  1224. {
  1225. Helper.ErrorLog(ex.InnerException, "Q_Setting", "FindteamList", ex.Message);
  1226. return result;
  1227. }
  1228. }
  1229. /// <summary>
  1230. /// Find Team by Team Id
  1231. /// </summary>
  1232. /// <param name="AccountId"></param>
  1233. /// <param name="TeamId"></param>
  1234. /// <returns></returns>
  1235. public List<Team> FindTeamByTeamId(int AccountId, int TeamId)
  1236. {
  1237. List<Team> result = new List<Team>();
  1238. SqlParameter[] Param = new SqlParameter[2];
  1239. Param[0] = new SqlParameter("@AccountId", AccountId);
  1240. Param[1] = new SqlParameter("@TeamId", TeamId);
  1241. string _procedurename = "tblTeamGetByTeamId";
  1242. try
  1243. {
  1244. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1245.  
  1246. result = (from DataRow row in dt.Rows
  1247. select new Team
  1248. {
  1249. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  1250. TeamName = Convert.ToString((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]),
  1251. brokername = Convert.ToString((row["brokername"] == DBNull.Value || row["brokername"] == null) ? " " : row["brokername"]),
  1252. AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
  1253. IsActive = Convert.ToBoolean(((row["IsActive"] == DBNull.Value || row["IsActive"] == null) ? false : row["IsActive"]).ToString()),
  1254. IsDelete = Convert.ToBoolean(((row["IsDelete"] == DBNull.Value || row["IsDelete"] == null) ? false : row["IsDelete"]).ToString()),
  1255. CompanyName = Convert.ToString((row["CompanyName"] == DBNull.Value || row["CompanyName"] == null) ? " " : row["CompanyName"]),
  1256. TeamBrokers = Convert.ToString((row["TeamBrokers"] == DBNull.Value || row["TeamBrokers"] == null) ? " " : row["TeamBrokers"]),
  1257. ManagerId = Convert.ToInt32(((row["ManagerId"] == DBNull.Value || row["ManagerId"] == null) ? "0" : row["ManagerId"]).ToString()),
  1258. EntryBy = Convert.ToInt32(((row["EntryBy"] == DBNull.Value || row["EntryBy"] == null) ? "0" : row["EntryBy"]).ToString()),
  1259. UpdateBy = Convert.ToInt32(((row["UpdateBy"] == DBNull.Value || row["UpdateBy"] == null) ? "0" : row["UpdateBy"]).ToString()),
  1260. AddDate = (row["AddDate"] == DBNull.Value || row["AddDate"] == null) ? (DateTime?)null : Convert.ToDateTime(row["AddDate"]),
  1261.  
  1262. }).ToList();
  1263.  
  1264. return result;
  1265. }
  1266. catch (Exception ex)
  1267. {
  1268. Helper.ErrorLog(ex.InnerException, "FindTeamByTeamId", ex.Message);
  1269. return result;
  1270. }
  1271. }
  1272. /// <summary>
  1273. /// To check Broker
  1274. /// </summary>
  1275. /// <param name="userid"></param>
  1276. /// <returns></returns>
  1277. public bool hasBroker(int userid)
  1278. {
  1279. bool flag = false;
  1280.  
  1281. try
  1282. {
  1283. flag = ctx.tblusers.Any(d => d.userid == userid && d.active == true && d.broker.HasValue && d.broker.Value == true);
  1284.  
  1285. return flag;
  1286. }
  1287. catch (Exception ex)
  1288. {
  1289. Helper.ErrorLog(ex.InnerException, "Q_Setting", "hasBroker", ex.Message);
  1290. return flag;
  1291. }
  1292. }
  1293. #endregion
  1294.  
  1295. #region Check password exist in database
  1296. /// <summary>
  1297. /// Check Password
  1298. /// </summary>
  1299. /// <param name="password"></param>
  1300. /// <returns></returns>
  1301. public bool checkpassword(string password)
  1302. {
  1303. bool result = false;
  1304. try
  1305. {
  1306. result = ctx.tblusers.Any(u => u.password == password);
  1307. return result;
  1308. }
  1309. catch (Exception ex)
  1310. {
  1311. Helper.ErrorLog(ex.InnerException, "Q_Setting", "checkpassword", ex.Message);
  1312. return result;
  1313. }
  1314. }
  1315.  
  1316. #endregion
  1317.  
  1318. #region Manage Permission
  1319. /// <summary>
  1320. /// User Permission Add update and delete
  1321. /// </summary>
  1322. /// <param name="accid"></param>
  1323. /// <param name="loggeduserid"></param>
  1324. /// <param name="PermissionArray"></param>
  1325. /// <returns></returns>
  1326. public int UserPermissionADDUpdateDelete(int accid, int loggeduserid, List<UserPermissionModel> PermissionArray)
  1327. {
  1328. int chk = 0;
  1329. try
  1330. {
  1331. foreach (var obj in PermissionArray)
  1332. {
  1333. SqlParameter[] Param = new SqlParameter[7];
  1334.  
  1335. Param[0] = new SqlParameter("@UserId", obj.userid);
  1336. Param[1] = new SqlParameter("@AccountId", accid);
  1337. Param[2] = new SqlParameter("@PermissionId", obj.PermissionId);
  1338. Param[3] = new SqlParameter("@EntryBy", loggeduserid);
  1339. Param[4] = new SqlParameter("@IsActive", true);
  1340. Param[5] = new SqlParameter("@IsDelete", false);
  1341. Param[6] = new SqlParameter("@Type", obj.Type);
  1342.  
  1343. int _chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "tblUserPermissionADDUpdateDelete", Param);
  1344. chk = 1;
  1345. }
  1346. }
  1347. catch (Exception ex)
  1348. {
  1349. Helper.ErrorLog(ex.InnerException, "Q_Setting", "UserPermissionAddUpdateDelete", ex.Message);
  1350. }
  1351.  
  1352. return chk;
  1353. }
  1354. #endregion
  1355.  
  1356. #region Manage Permission
  1357. /// <summary>
  1358. /// Adding Defualt Permission
  1359. /// </summary>
  1360. /// <param name="UserType"></param>
  1361. /// <param name="UserId"></param>
  1362. /// <param name="AccountId"></param>
  1363. /// <param name="LoggdInUserId"></param>
  1364. /// <returns></returns>
  1365. public int AddDefaultPermission(int UserType, int UserId, int AccountId, int LoggdInUserId)
  1366. {
  1367. // User Type - 1- Admin user having only View All permission, 2- Broker Full Permissions, 3- General User -- As per the client response ON 21-07-2014
  1368. int chk = 0;
  1369. try
  1370. {
  1371. SqlParameter[] Param = new SqlParameter[4];
  1372.  
  1373. Param[0] = new SqlParameter("@UserId", UserId);
  1374. Param[1] = new SqlParameter("@AccountId", AccountId);
  1375. Param[2] = new SqlParameter("@LoggdInUserId", LoggdInUserId);
  1376. Param[3] = new SqlParameter("@UserType", UserType);
  1377.  
  1378. int _chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "AddDefaultPermission", Param);
  1379. }
  1380. catch (Exception ex)
  1381. {
  1382. Helper.ErrorLog(ex.InnerException, "Q_settings", "AdddefualtPermission", ex.Message);
  1383. }
  1384.  
  1385. return chk;
  1386. }
  1387. #endregion
  1388.  
  1389. #region Attendance Settings
  1390. /// <summary>
  1391. /// Attendence for brokers and damin team
  1392. /// </summary>
  1393. /// <param name="userid"></param>
  1394. /// <param name="usertype"></param>
  1395. /// <param name="Year"></param>
  1396. /// <param name="Name"></param>
  1397. /// <param name="TeamId"></param>
  1398. /// <returns></returns>
  1399. public List<AttendanceClients> Attendance_FindBrokersForAdminTeam(int userid, int usertype, int Year = 0, string Name = "", int TeamId = 0)
  1400. {
  1401. var brokers = new List<AttendanceClients>();
  1402. string _procedurename = "GetUsersForYearAttendance";
  1403. try
  1404. {
  1405. SqlParameter[] Param = new SqlParameter[5];
  1406. Param[0] = new SqlParameter("@UserType", usertype);
  1407. Param[1] = new SqlParameter("@ID", userid);
  1408.  
  1409. if (Year > 0)
  1410. Param[2] = new SqlParameter("@Year", Year);
  1411. if (!string.IsNullOrWhiteSpace(Name))
  1412. Param[3] = new SqlParameter("@Name", Name);
  1413. if (TeamId > 0)
  1414. Param[4] = new SqlParameter("@TeamId", TeamId);
  1415.  
  1416. var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1417. brokers = (from DataRow row in dt.Rows
  1418. select new AttendanceClients
  1419. {
  1420. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  1421. companyname = Convert.ToString((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]),
  1422. email = Convert.ToString((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]),
  1423. contactname = Convert.ToString((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]),
  1424. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  1425. ActivityYear = Convert.ToInt32(((row["ActivityYear"] == DBNull.Value || row["ActivityYear"] == null) ? "0" : row["ActivityYear"]).ToString()),
  1426. DaysOffAllowed = Convert.ToDecimal(((row["DaysOffAllowed"] == DBNull.Value || row["DaysOffAllowed"] == null) ? "0" : row["DaysOffAllowed"]).ToString()),
  1427. DaysOffUsed = Convert.ToDecimal(((row["DaysOffUsed"] == DBNull.Value || row["DaysOffUsed"] == null) ? "0" : row["DaysOffUsed"]).ToString()),
  1428.  
  1429. DaysOffUsedManually = Convert.ToDecimal(((row["DaysOffUsedManually"] == DBNull.Value || row["DaysOffUsedManually"] == null) ? "0" : row["DaysOffUsedManually"]).ToString()),
  1430. }).ToList();
  1431. }
  1432. catch (Exception ex)
  1433. {
  1434. Helper.ErrorLog(ex.InnerException, "Q_Setting", "Attendance_FindbrokersForAdminTeam", ex.Message);
  1435. }
  1436. return brokers;
  1437.  
  1438. }
  1439. /// <summary>
  1440. /// Attendence Brokers for admin team day wise.
  1441. /// </summary>
  1442. /// <param name="DayVal"></param>
  1443. /// <param name="userid"></param>
  1444. /// <param name="usertype"></param>
  1445. /// <param name="Name"></param>
  1446. /// <param name="TeamId"></param>
  1447. /// <returns></returns>
  1448. public List<AttendanceClients> Attendance_FindBrokersForAdminTeamDayWise(string DayVal, int userid, int usertype, string Name = "", int TeamId = 0)
  1449. {
  1450. var brokers = new List<AttendanceClients>();
  1451. string _procedurename = "GetUsersForDaysAttendance";
  1452. try
  1453. {
  1454. string activitydate = System.DateTime.Now.ToString("MM/dd/yyyy");
  1455. if (!string.IsNullOrWhiteSpace(DayVal))
  1456. activitydate = DayVal.GetDate().Value.ToString("MM/dd/yyyy");
  1457.  
  1458. SqlParameter[] Param = new SqlParameter[5];
  1459. Param[0] = new SqlParameter("@UserType", usertype);
  1460. Param[1] = new SqlParameter("@ID", userid);
  1461.  
  1462. if (!string.IsNullOrWhiteSpace(Name))
  1463. Param[2] = new SqlParameter("@Name", Name);
  1464. if (TeamId > 0)
  1465. Param[3] = new SqlParameter("@TeamId", TeamId);
  1466. if (!string.IsNullOrWhiteSpace(DayVal))
  1467. Param[4] = new SqlParameter("@ActivityDate", activitydate);
  1468.  
  1469.  
  1470.  
  1471. var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1472. brokers = (from DataRow row in dt.Rows
  1473. select new AttendanceClients
  1474. {
  1475. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  1476. companyname = Convert.ToString((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]),
  1477. email = Convert.ToString((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]),
  1478. contactname = Convert.ToString((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]),
  1479. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  1480. AbsentHrsAllowed = Convert.ToDecimal(((row["AbsentHrsAllowed"] == DBNull.Value || row["AbsentHrsAllowed"] == null) ? "0" : row["AbsentHrsAllowed"]).ToString()),
  1481. AbsentHrsUsed = Convert.ToDecimal(((row["AbsentHrsUsed"] == DBNull.Value || row["AbsentHrsUsed"] == null) ? "0" : row["AbsentHrsUsed"]).ToString()),
  1482. ActivityDate = (row["ActivityDate"] == DBNull.Value || row["ActivityDate"] == null) ? (DateTime?)null : Convert.ToDateTime(row["ActivityDate"])
  1483.  
  1484. }).ToList();
  1485. }
  1486. catch (Exception ex)
  1487. {
  1488. Helper.ErrorLog(ex.InnerException, "Q_Setting", "Attendence_FindBrokersForAdminTeamDayWise", ex.Message);
  1489. }
  1490. return brokers;
  1491.  
  1492. }
  1493.  
  1494. #endregion
  1495.  
  1496. #region Admin Team
  1497.  
  1498. /// <summary>
  1499. /// This will return all available brokers regardless the Account id. As these brokers will be tranferable for other team as well
  1500. /// </summary>
  1501. /// <param name="AccountId">Account Id</param>
  1502. /// <returns></returns>
  1503. public List<Clients> FindBrokersForAdminTeam(int AccountId)
  1504. {
  1505. List<Clients> brokers = new List<Clients>();
  1506. string _procedurename = "FindBrokersForAdminTeam";
  1507. try
  1508. {
  1509. SqlParameter[] Param = new SqlParameter[1];
  1510. Param[0] = new SqlParameter("@Id", AccountId);
  1511. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1512. brokers = (from DataRow row in dt.Rows
  1513. select new Clients
  1514. {
  1515. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  1516. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  1517. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  1518. companyname = Convert.ToString((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]),
  1519. affiliateid = Convert.ToString((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]),
  1520. email = Convert.ToString((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]),
  1521. telephone = Convert.ToString((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]),
  1522. address = Convert.ToInt32((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]),
  1523. TeamName = Convert.ToString((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]),
  1524. AdminTeamName = Convert.ToString((row["AdminTeamName"] == DBNull.Value || row["AdminTeamName"] == null) ? " " : row["AdminTeamName"]),
  1525. contactname = Convert.ToString((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]),
  1526.  
  1527.  
  1528. }).ToList();
  1529. }
  1530. catch (Exception ex)
  1531. {
  1532. Helper.ErrorLog(ex.InnerException, "Q_setting.cs", "FindBrokerForAdminTeam", ex.Message);
  1533. }
  1534. return brokers;
  1535.  
  1536. }
  1537. /// <summary>
  1538. /// Getting Admin team
  1539. /// </summary>
  1540. /// <param name="AccountId"></param>
  1541. /// <returns></returns>
  1542. public AdminDetails GetAdminTeam(int AccountId)
  1543. {
  1544. AdminDetails result = new AdminDetails();
  1545. SqlParameter[] Param = new SqlParameter[1];
  1546. Param[0] = new SqlParameter("@AdminId", AccountId);
  1547. string _procedurename = "GetAdminTeam";
  1548. try
  1549. {
  1550. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procedurename, Param);
  1551.  
  1552. result = (from DataRow row in dt.Rows
  1553. select new AdminDetails
  1554. {
  1555. UserId = Convert.ToInt32(((row["UserId"] == DBNull.Value || row["UserId"] == null) ? "0" : row["UserId"]).ToString()),
  1556. ContactName = Convert.ToString((row["ContactName"] == DBNull.Value || row["ContactName"] == null) ? " " : row["ContactName"]),
  1557. AffiliateId = Convert.ToString((row["AffiliateId"] == DBNull.Value || row["AffiliateId"] == null) ? " " : row["AffiliateId"]),
  1558. AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
  1559. CompanyName = Convert.ToString((row["CompanyName"] == DBNull.Value || row["CompanyName"] == null) ? " " : row["CompanyName"]),
  1560. Email = Convert.ToString((row["Email"] == DBNull.Value || row["Email"] == null) ? " " : row["Email"]),
  1561. Telephone = Convert.ToString((row["Telephone"] == DBNull.Value || row["Telephone"] == null) ? " " : row["Telephone"]),
  1562. Address = Convert.ToString((row["Address"] == DBNull.Value || row["Address"] == null) ? " " : row["Address"]),
  1563. TeamName = Convert.ToString((row["CompanyName"] == DBNull.Value || row["CompanyName"] == null) ? " " : row["CompanyName"] + "-(Team)"),
  1564.  
  1565.  
  1566. }).FirstOrDefault();
  1567.  
  1568.  
  1569. return result ?? new AdminDetails();
  1570. }
  1571. catch (Exception ex)
  1572. {
  1573. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetAdminteam", ex.Message);
  1574. return result;
  1575. }
  1576. }
  1577. /// <summary>
  1578. /// Update Attendence
  1579. /// </summary>
  1580. /// <param name="userid"></param>
  1581. /// <param name="TotalAbsentDaysAllowed"></param>
  1582. /// <param name="TotalAbsentDaysUsedManually"></param>
  1583. /// <param name="TotalAbsentDaysUsedBySystem"></param>
  1584. /// <param name="ActivityYear"></param>
  1585. /// <param name="accountid"></param>
  1586. /// <param name="ActionType"></param>
  1587. /// <returns></returns>
  1588. public int UpdateAttendance(int userid, decimal TotalAbsentDaysAllowed, decimal TotalAbsentDaysUsedManually, decimal TotalAbsentDaysUsedBySystem, int ActivityYear, int accountid = 0, int ActionType = 1)
  1589. {
  1590. int _chk = 0;
  1591. try
  1592. {
  1593. if (con.Session["LoggedInUserAccountId"] != null)
  1594. {
  1595. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  1596. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  1597. SqlParameter[] Param = new SqlParameter[10];
  1598. Param[0] = new SqlParameter("@UserId", userid);
  1599. Param[1] = new SqlParameter("@AccountId", accountid);
  1600. Param[2] = new SqlParameter("@TotalAbsentDaysAllowed", TotalAbsentDaysAllowed);
  1601. Param[3] = new SqlParameter("@TotalAbsentDaysUsedManually", TotalAbsentDaysUsedManually);
  1602. Param[4] = new SqlParameter("@TotalAbsentDaysUsedBySystem", TotalAbsentDaysUsedBySystem);
  1603. Param[5] = new SqlParameter("@ActivityYear", ActivityYear);
  1604. Param[6] = new SqlParameter("@EntryBy", userId);
  1605. Param[7] = new SqlParameter("@IsActive", true);
  1606. Param[8] = new SqlParameter("@IsDelete", false);
  1607. Param[9] = new SqlParameter("@ActionType", ActionType);
  1608. string _procedurename = "UserYearWiseAbsentAddUpdate";
  1609. _chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1610. }
  1611. else
  1612. {
  1613. return -3;
  1614. }
  1615. }
  1616. catch (Exception ex)
  1617. {
  1618. Helper.ErrorLog(ex.InnerException, "Q_setting", "updateAttendence", ex.Message);
  1619. return 0;
  1620. }
  1621. return _chk;
  1622. }
  1623. /// <summary>
  1624. /// Update Attendence Day
  1625. /// </summary>
  1626. /// <param name="ActivityDate"></param>
  1627. /// <param name="userid"></param>
  1628. /// <param name="TotalHoursAllowed"></param>
  1629. /// <param name="ActionType"></param>
  1630. /// <returns></returns>
  1631. public int UpdateAttendanceDay(string ActivityDate, int userid, decimal TotalHoursAllowed, int ActionType = 1)
  1632. {
  1633. int _chk = 0;
  1634. try
  1635. {
  1636. if (con.Session["LoggedInUserAccountId"] != null)
  1637. {
  1638.  
  1639. string activitydate = System.DateTime.Now.ToString("MM/dd/yyyy");
  1640. if (!string.IsNullOrWhiteSpace(ActivityDate))
  1641. activitydate = ActivityDate.GetDate().Value.ToString("MM/dd/yyyy");
  1642.  
  1643. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  1644. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  1645. SqlParameter[] Param = new SqlParameter[8];
  1646. Param[0] = new SqlParameter("@UserId", userid);
  1647. Param[1] = new SqlParameter("@AccountId", AccountId);
  1648. Param[2] = new SqlParameter("@TotalAbsentHrsAllowed", TotalHoursAllowed);
  1649. Param[3] = new SqlParameter("@EntryBy", userId);
  1650. Param[4] = new SqlParameter("@IsActive", true);
  1651. Param[5] = new SqlParameter("@IsDelete", false);
  1652. Param[6] = new SqlParameter("@ActionType", ActionType);
  1653. Param[7] = new SqlParameter("@ActivityDate", activitydate);
  1654. string _procedurename = "UserYearWiseAbsentAddUpdateDay";
  1655. _chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1656. }
  1657. else
  1658. {
  1659. return -3;
  1660. }
  1661. }
  1662. catch (Exception ex)
  1663. {
  1664. Helper.ErrorLog(ex.InnerException, "Q_Setting", "UpdateAttendenceDay", ex.Message);
  1665. return 0;
  1666. }
  1667. return _chk;
  1668. }
  1669.  
  1670. /// <summary>
  1671. /// Update Admin Team
  1672. /// </summary>
  1673. /// <param name="companyname"></param>
  1674. /// <param name="contactname"></param>
  1675. /// <param name="telephone"></param>
  1676. /// <param name="email"></param>
  1677. /// <param name="accountid"></param>
  1678. /// <returns></returns>
  1679. public int UpdateAdminTeam(string companyname, string contactname, string telephone, string email, int accountid = 0)
  1680. {
  1681. try
  1682. {
  1683. if (con.Session["LoggedInUserAccountId"] != null)
  1684. {
  1685. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  1686. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  1687. SqlParameter[] Param = new SqlParameter[6];
  1688. Param[0] = new SqlParameter("@AccountId", accountid);
  1689. Param[1] = new SqlParameter("@Contactname", contactname);
  1690. Param[2] = new SqlParameter("@Companyname", companyname);
  1691. Param[3] = new SqlParameter("@Email", email);
  1692. Param[4] = new SqlParameter("@Telephone", telephone);
  1693.  
  1694. Param[5] = new SqlParameter("@Chk", 0);
  1695. Param[5].Direction = ParameterDirection.Output;
  1696.  
  1697. string _procedurename = "UpdateAdminTeam";
  1698. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1699.  
  1700. accountid = Convert.ToInt32(Param[5] != null ? Param[5].SqlValue.ToString() : "0");
  1701. }
  1702. else
  1703. {
  1704. return -3;
  1705. }
  1706. }
  1707. catch (Exception ex)
  1708. {
  1709. Helper.ErrorLog(ex.InnerException, "Q_Setting", "UpdateAdminTeam", ex.Message);
  1710. return 0;
  1711. }
  1712. return accountid;
  1713. }
  1714. /// <summary>
  1715. /// Delete Client
  1716. /// </summary>
  1717. /// <param name="userId"></param>
  1718. /// <returns></returns>
  1719. public int DeleteClient(int userId)
  1720. {
  1721. int accountid = 0;
  1722. try
  1723. {
  1724. if (con.Session["LoggedInUserAccountId"] != null)
  1725. {
  1726. SqlParameter[] Param = new SqlParameter[6];
  1727. Param[0] = new SqlParameter("@AdminId", userId);
  1728.  
  1729.  
  1730. string _procedurename = "DeleteClient";
  1731. accountid = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1732.  
  1733. }
  1734. else
  1735. {
  1736. return -3;
  1737. }
  1738. }
  1739. catch (Exception ex)
  1740. {
  1741. Helper.ErrorLog(ex.InnerException, "Q_Setting", "DeleteClient", ex.Message);
  1742. return 0;
  1743. }
  1744. return accountid;
  1745. }
  1746. /// <summary>
  1747. /// Addng Admin team
  1748. /// </summary>
  1749. /// <param name="companyname"></param>
  1750. /// <param name="contactname"></param>
  1751. /// <param name="telephone"></param>
  1752. /// <param name="email"></param>
  1753. /// <returns></returns>
  1754. public int AddAdminTeam(string companyname, string contactname, string telephone, string email)
  1755. {
  1756. int accountid = 0;
  1757. string affiliateid = "";
  1758. try
  1759. {
  1760. if (con.Session["LoggedInUserAccountId"] != null)
  1761. {
  1762. var AccountId = Convert.ToInt32(con.Session["LoggedInUserAccountId"] ?? "0");
  1763. var userId = Convert.ToInt32(con.Session["LoggedInUserId"] ?? "0");
  1764. SqlParameter[] Param = new SqlParameter[8];
  1765. Param[0] = new SqlParameter("@Contactname", contactname);
  1766. Param[1] = new SqlParameter("@Companyname", companyname);
  1767. Param[2] = new SqlParameter("@Email", email);
  1768. Param[3] = new SqlParameter("@Telephone", telephone);
  1769.  
  1770. Param[4] = new SqlParameter("@AffiliateId", SqlDbType.VarChar, 200);
  1771. Param[4].Direction = ParameterDirection.Output;
  1772.  
  1773. Param[5] = new SqlParameter("@AccountId", 0);
  1774. Param[5].Direction = ParameterDirection.Output;
  1775.  
  1776. Param[6] = new SqlParameter("@UserId", 0);
  1777. Param[6].Direction = ParameterDirection.Output;
  1778.  
  1779. Param[7] = new SqlParameter("@AdminId", AccountId);
  1780.  
  1781.  
  1782. string _procedurename = "AddAdminTeam";
  1783. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1784.  
  1785. affiliateid = Convert.ToString(Param[4] != null ? Param[4].SqlValue.ToString() : "");
  1786. accountid = Convert.ToInt32(Param[6] != null ? Param[6].SqlValue.ToString() : "0");
  1787. //Send Crdential Mail *****************************************************
  1788. if (accountid > 0 && !string.IsNullOrWhiteSpace(affiliateid))
  1789. {
  1790. string body = "Hi " + contactname + ", <br /><br /><br /><br />";
  1791. body += "Your email address/User Name: " + email + "<br /><br />";
  1792. body += "Password: " + affiliateid + " <br /><br /><br /><br />";
  1793. body += "Regards, <br /><br />";
  1794. body += "Apptrack Admin";
  1795.  
  1796. var _secureURL = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SecureURL"] ?? "");
  1797. var _contentURL = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ContentURL"] ?? "");
  1798.  
  1799. var AppTrackImg = _secureURL + "/Content/images/" + Convert.ToString("apptrack.jpg");
  1800. var AppTrackLogo = _secureURL + "/Content/images/" + Convert.ToString(HttpContext.Current.Session["SiteLogo"] ?? "logo_6569.jpg");
  1801. var FooterCopyRight = "© 2014 Finance Technology Ltd. Registered trademarks IntelliCalc®, AppTrack®. All rights reserved";
  1802. var SupportFooter = "Contact Us on: 0845 521 5153, Specialising in financial technologies & solutions";
  1803. var _mailTemplate = Codes.Extensions.Mailtemplates(AppTrackImg, AppTrackLogo, body, FooterCopyRight, SupportFooter, _contentURL);
  1804.  
  1805. //-------------------------------------
  1806. List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
  1807.  
  1808. var _mailDrilEmails = new List<Mandrill.EmailAddress>();
  1809. Mandrill.EmailAddress objEm = new Mandrill.EmailAddress();
  1810. objEm.email = email;
  1811. objEm.name = contactname;
  1812. _mailDrilEmails.Add(objEm);
  1813.  
  1814. //Man DRILL ********************************************************************
  1815.  
  1816. var domain = "occfinance.com";
  1817. Mandrill.EmailMessage message = new Mandrill.EmailMessage();
  1818. var _mandrillMessage = new List<Mandrill.EmailMessage>();
  1819.  
  1820. message.to = _mailDrilEmails;
  1821. message.html = _mailTemplate;
  1822. message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
  1823. message.from_name = "OCC";
  1824. message.subject = "Your Apptrack Credential";
  1825. message.inline_css = true;
  1826. message.signing_domain = domain;
  1827. message.AddHeader("X-MC-SigningDomain", domain);
  1828. message.AddHeader("X-MC-TrackingDomain", domain);
  1829. _mandrillMessage.Add(message);
  1830.  
  1831. //********************************************************************************
  1832.  
  1833. // Manage The ManDRILLModel - 25-07-2014
  1834.  
  1835. var objMAN = new ManDRILLModel();
  1836. objMAN.contactId = 0;
  1837. objMAN.financeid = 0;
  1838. objMAN.mailcontent = _mailTemplate;
  1839. objMAN.MandrillMSG = message;
  1840. objMAN.IsAppContact = false;
  1841.  
  1842. objMAN.notemsg = "";
  1843.  
  1844. _mandrillOBJ.Add(objMAN);
  1845.  
  1846.  
  1847. WebUtility.SendMailViaManDRILL(_mandrillOBJ, userId);
  1848. //-------------------------------------
  1849.  
  1850.  
  1851. // Add Default Permission ---------------------------
  1852. // 1- Admin User, 2- Broker, 3- General User As per the client response ON 21-07-2014
  1853. try
  1854. {
  1855.  
  1856. AddDefaultPermission(1, accountid, AccountId, userId);
  1857. }
  1858. catch
  1859. {
  1860. }
  1861. }
  1862. //*************************************************************************
  1863. }
  1864. else
  1865. {
  1866. return -3;
  1867. }
  1868. }
  1869. catch (Exception ex)
  1870. {
  1871. Helper.ErrorLog(ex.InnerException, "Q_Setting", "AddAdminTeam", ex.Message);
  1872. return 0;
  1873. }
  1874. return accountid;
  1875. }
  1876.  
  1877. /// <summary>
  1878. /// Registration
  1879. /// </summary>
  1880. /// <param name="companyname"></param>
  1881. /// <param name="contactname"></param>
  1882. /// <param name="telephone"></param>
  1883. /// <param name="email"></param>
  1884. /// <returns></returns>
  1885. public int Registration(string companyname, string contactname, string telephone, string email)
  1886. {
  1887. int UserId = 0;
  1888. int accountid = 0;
  1889. try
  1890. {
  1891.  
  1892. SqlParameter[] Param = new SqlParameter[7];
  1893. Param[0] = new SqlParameter("@Contactname", contactname);
  1894. Param[1] = new SqlParameter("@Companyname", companyname);
  1895. Param[2] = new SqlParameter("@Email", email);
  1896. Param[3] = new SqlParameter("@Telephone", telephone);
  1897. Param[4] = new SqlParameter("@UserId", 0);
  1898. Param[4].Direction = ParameterDirection.Output;
  1899. Param[5] = new SqlParameter("@AccountId", 0);
  1900. Param[5].Direction = ParameterDirection.Output;
  1901. Param[6] = new SqlParameter("@parent", 6569);
  1902. string _procedurename = "ClientRegistration";
  1903. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1904. accountid = Convert.ToInt32(Param[5] != null ? Param[5].SqlValue.ToString() : "0");
  1905. UserId = Convert.ToInt32(Param[4] != null ? Param[4].SqlValue.ToString() : "0"); // return userid
  1906.  
  1907. if (UserId > 0)
  1908. {
  1909.  
  1910. try
  1911. {
  1912. AddDefaultPermission(1, accountid, 6569, UserId);
  1913. }
  1914. catch
  1915. {
  1916. }
  1917. }
  1918. //*************************************************************************
  1919.  
  1920. }
  1921. catch (Exception ex)
  1922. {
  1923. Helper.ErrorLog(ex.InnerException, "Q_Setting", "Registration", ex.Message);
  1924. return 0;
  1925. }
  1926. return UserId;
  1927. }
  1928.  
  1929.  
  1930. public int ActivateClient(int Userid)
  1931. {
  1932. int chk = 0;
  1933. try
  1934. {
  1935.  
  1936. SqlParameter[] Param = new SqlParameter[1];
  1937. Param[0] = new SqlParameter("@Userid", Userid);
  1938.  
  1939. string _procedurename = "ActivateClient";
  1940. chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  1941.  
  1942. }
  1943. catch (Exception ex)
  1944. {
  1945. Helper.ErrorLog(ex.InnerException, "Q_setting", "ActivateClient", ex.Message);
  1946. return 0;
  1947. }
  1948. return chk;
  1949. }
  1950.  
  1951. #endregion
  1952. /// <summary>
  1953. /// Get Mortgage List
  1954. /// </summary>
  1955. /// <returns></returns>
  1956. public List<MortgageRate> GetMortgageList()
  1957. {
  1958.  
  1959. List<MortgageRate> Mortgage_Rate = new List<MortgageRate>();
  1960. Clients result = new Clients();
  1961. try
  1962. {
  1963.  
  1964. Mortgage_Rate = ctx.tblaccount_mortgagerates.Select(u => new MortgageRate()
  1965. {
  1966. accountid = u.accountid,
  1967. Rate = u.rate,
  1968. LTV = u.ltv
  1969. }).ToList();
  1970. return Mortgage_Rate;
  1971. }
  1972. catch (Exception ex)
  1973. {
  1974. Helper.ErrorLog(ex.InnerException, "Q_setting", "GetMortgageList", ex.Message);
  1975. return Mortgage_Rate;
  1976. }
  1977. }
  1978. /// <summary>
  1979. /// getting Team member by member id
  1980. /// </summary>
  1981. /// <param name="MemberId"></param>
  1982. /// <returns></returns>
  1983. public List<tblTeamMember> TeammembersGetByMemberId(int MemberId)
  1984. {
  1985.  
  1986. List<tblTeamMember> _teams = new List<tblTeamMember>();
  1987.  
  1988. try
  1989. {
  1990. SqlParameter[] Param = new SqlParameter[1];
  1991. Param[0] = new SqlParameter("@MemberId", MemberId);
  1992. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "tblteammembersGetByMemberId", Param);
  1993. _teams = (from DataRow row in dt.Rows
  1994. select new tblTeamMember
  1995. {
  1996. TeamMembersId = Convert.ToInt32(((row["TeamMembersId"] == DBNull.Value || row["TeamMembersId"] == null) ? "0" : row["TeamMembersId"]).ToString()),
  1997. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  1998. IsActive = Convert.ToBoolean(((row["IsActive"] == DBNull.Value || row["IsActive"] == null) ? false : row["IsActive"]).ToString()),
  1999. IsDelete = Convert.ToBoolean(((row["IsDelete"] == DBNull.Value || row["IsDelete"] == null) ? false : row["IsDelete"]).ToString()),
  2000. MemberId = Convert.ToInt32(((row["MemberId"] == DBNull.Value || row["MemberId"] == null) ? "0" : row["MemberId"]).ToString()),
  2001. EntryBy = Convert.ToInt32(((row["EntryBy"] == DBNull.Value || row["EntryBy"] == null) ? "0" : row["EntryBy"]).ToString()),
  2002. UpdateBy = Convert.ToInt32(((row["UpdateBy"] == DBNull.Value || row["UpdateBy"] == null) ? "0" : row["UpdateBy"]).ToString()),
  2003. AddDate = (row["AddDate"] == DBNull.Value || row["AddDate"] == null) ? (DateTime?)null : Convert.ToDateTime(row["AddDate"]),
  2004.  
  2005. }).ToList();
  2006. }
  2007. catch (Exception ex)
  2008. {
  2009. Helper.ErrorLog(ex.InnerException, "Q_Setting", "TeamMemberGetbyMemberID");
  2010. }
  2011. return _teams;
  2012. }
  2013. /// <summary>
  2014. /// User Permission Get all by account Id
  2015. /// </summary>
  2016. /// <param name="AccountId"></param>
  2017. /// <param name="UserId"></param>
  2018. /// <param name="UserType"></param>
  2019. /// <returns></returns>
  2020. public List<UserPermissionModel> UserPermissionGetAllByAccountId(int AccountId, int UserId, int UserType)
  2021. {
  2022. List<UserPermissionModel> _teams = new List<UserPermissionModel>();
  2023. try
  2024. {
  2025. SqlParameter[] Param = new SqlParameter[3];
  2026. Param[0] = new SqlParameter("@AccountId", AccountId);
  2027. Param[1] = new SqlParameter("@UserId", UserId);
  2028. Param[2] = new SqlParameter("@UserType", UserType);
  2029. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "tblUserPermissionGetAllByAccountId", Param);
  2030. _teams = (from DataRow row in dt.Rows
  2031. select new UserPermissionModel
  2032. {
  2033. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2034. account = Convert.ToInt32(((row["account"] == DBNull.Value || row["account"] == null) ? "0" : row["account"]).ToString()),
  2035. administrator = Convert.ToBoolean(((row["administrator"] == DBNull.Value || row["administrator"] == null) ? false : row["administrator"]).ToString()),
  2036. broker = Convert.ToBoolean(((row["broker"] == DBNull.Value || row["broker"] == null) ? false : row["broker"]).ToString()),
  2037. brokername = Convert.ToString(((row["brokername"] == DBNull.Value || row["brokername"] == null) ? "" : row["brokername"]).ToString()),
  2038. PermissionIds = Convert.ToString(((row["PermissionIds"] == DBNull.Value || row["PermissionIds"] == null) ? "" : row["PermissionIds"]).ToString()),
  2039. PermissionNames = Convert.ToString(((row["PermissionNames"] == DBNull.Value || row["PermissionNames"] == null) ? "" : row["PermissionNames"]).ToString()),
  2040.  
  2041. }).ToList();
  2042. }
  2043. catch (Exception ex)
  2044. {
  2045. Helper.ErrorLog(ex.InnerException, "Q_Setting", "UserPermissionGetAllByaccountID", ex.Message);
  2046. }
  2047. return _teams;
  2048. }
  2049.  
  2050. /// <summary>
  2051. /// get All activate client by Account Id
  2052. /// </summary>
  2053. /// <param name="AccountId"></param>
  2054. /// <param name="UserId"></param>
  2055. /// <returns></returns>
  2056. public List<InActiveUser> GetAllInActiveClientByAccountId(int AccountId, int UserId)
  2057. {
  2058.  
  2059. List<InActiveUser> _teams = new List<InActiveUser>();
  2060.  
  2061. try
  2062. {
  2063. SqlParameter[] Param = new SqlParameter[3];
  2064. Param[0] = new SqlParameter("@AccountId", AccountId);
  2065. Param[1] = new SqlParameter("@UserId", UserId);
  2066. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllInActiveClientByAccountId", Param);
  2067. _teams = (from DataRow row in dt.Rows
  2068. select new InActiveUser
  2069. {
  2070. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2071. account = Convert.ToInt32(((row["account"] == DBNull.Value || row["account"] == null) ? "0" : row["account"]).ToString()),
  2072. administrator = Convert.ToBoolean(((row["administrator"] == DBNull.Value || row["administrator"] == null) ? false : row["administrator"]).ToString()),
  2073. broker = Convert.ToBoolean(((row["broker"] == DBNull.Value || row["broker"] == null) ? false : row["broker"]).ToString()),
  2074. brokername = Convert.ToString(((row["brokername"] == DBNull.Value || row["brokername"] == null) ? "" : row["brokername"]).ToString()),
  2075. PermissionIds = Convert.ToString(((row["PermissionIds"] == DBNull.Value || row["PermissionIds"] == null) ? "" : row["PermissionIds"]).ToString()),
  2076. PermissionNames = Convert.ToString(((row["PermissionNames"] == DBNull.Value || row["PermissionNames"] == null) ? "" : row["PermissionNames"]).ToString()),
  2077. username = Convert.ToString(((row["username"] == DBNull.Value || row["username"] == null) ? "" : row["username"]).ToString()),
  2078. password = Convert.ToString(((row["password"] == DBNull.Value || row["password"] == null) ? "" : row["password"]).ToString()),
  2079.  
  2080. }).ToList();
  2081. }
  2082. catch (Exception ex)
  2083. {
  2084. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetallnActivateclientByAccoutnId", ex.Message);
  2085. }
  2086. return _teams;
  2087. }
  2088.  
  2089. /// <summary>
  2090. /// Get All Permissions
  2091. /// </summary>
  2092. /// <returns></returns>
  2093. public List<PermissionModel> GetAllPermissions()
  2094. {
  2095.  
  2096. List<PermissionModel> _teams = new List<PermissionModel>();
  2097.  
  2098. try
  2099. {
  2100. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllPermissions");
  2101. _teams = (from DataRow row in dt.Rows
  2102. select new PermissionModel
  2103. {
  2104. PermissionId = Convert.ToInt32(((row["PermissionId"] == DBNull.Value || row["PermissionId"] == null) ? "0" : row["PermissionId"]).ToString()),
  2105. AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
  2106. PermissionName = Convert.ToString(((row["PermissionName"] == DBNull.Value || row["PermissionName"] == null) ? "" : row["PermissionName"]).ToString()),
  2107.  
  2108. }).ToList();
  2109. }
  2110. catch (Exception ex)
  2111. {
  2112. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetAllPermission", ex.Message);
  2113. }
  2114. return _teams;
  2115. }
  2116.  
  2117. /// <summary>
  2118. /// Team Members Delete by Member Id
  2119. /// </summary>
  2120. /// <param name="MemberId"></param>
  2121. /// <returns></returns>
  2122. public int TeamMembersDeleteByMemberId(int MemberId)
  2123. {
  2124. int _chk = 0;
  2125. try
  2126. {
  2127. SqlParameter[] Param = new SqlParameter[1];
  2128. Param[0] = new SqlParameter("@MemberId", MemberId);
  2129. _chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "tblTeamMembersDeleteByMemberId", Param);
  2130. }
  2131. catch (Exception ex)
  2132. {
  2133. Helper.ErrorLog(ex.InnerException, "Q_Setting", "TeamMemberDelteByMemberId", ex.Message);
  2134. }
  2135.  
  2136. return _chk;
  2137. }
  2138.  
  2139. public int TeamMembersDeleteByTeamId(int TeamId)
  2140. {
  2141. int _chk = 0;
  2142. try
  2143. {
  2144. SqlParameter[] Param = new SqlParameter[1];
  2145. Param[0] = new SqlParameter("@TeamId", TeamId);
  2146. _chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "tblTeamMembersDeleteByTeamId", Param);
  2147. }
  2148. catch (Exception ex)
  2149. {
  2150. Helper.ErrorLog(ex.InnerException, "Q_Setting", "TeammembersDeleteByTeamId", ex.Message);
  2151. }
  2152.  
  2153. return _chk;
  2154. }
  2155.  
  2156. #region Add Team Members
  2157. /// <summary>
  2158. /// Adding Team Members
  2159. /// </summary>
  2160. /// <param name="AdminTeamId"></param>
  2161. /// <param name="AdminId"></param>
  2162. /// <param name="MemberId"></param>
  2163. /// <param name="userId"></param>
  2164. /// <param name="Type"></param>
  2165. /// <returns></returns>
  2166. public int AddAdminTeamMembers(int AdminTeamId, int AdminId, int MemberId, int userId, int Type)
  2167. {
  2168. int chk = 0;
  2169. try
  2170. {
  2171. if (con.Session["LoggedInUserAccountId"] != null)
  2172. {
  2173. SqlParameter[] Param = new SqlParameter[7];
  2174. Param[0] = new SqlParameter("@AdminTeamId", AdminTeamId);
  2175. Param[1] = new SqlParameter("@AdminId", AdminId);
  2176. Param[2] = new SqlParameter("@MemberId", MemberId);
  2177. Param[3] = new SqlParameter("@EntryBy", userId);
  2178. Param[4] = new SqlParameter("@IsActive", true);
  2179. Param[5] = new SqlParameter("@IsDelete", false);
  2180. Param[6] = new SqlParameter("@Type", Type);
  2181.  
  2182. string _procedurename = "tblAdminTeammebersADD";
  2183.  
  2184. chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  2185.  
  2186. }
  2187.  
  2188. }
  2189. catch (Exception ex)
  2190. {
  2191. Helper.ErrorLog(ex.InnerException, "Q_Setting", "AddAdminTeammember", ex.Message);
  2192. }
  2193. return chk;
  2194. }
  2195.  
  2196.  
  2197. #endregion
  2198. /// <summary>
  2199. /// Admin team Members Get By Member Id
  2200. /// </summary>
  2201. /// <param name="MemberId"></param>
  2202. /// <returns></returns>
  2203. public List<tblAdminTeammeber> AdminTeammembersGetByMemberId(int MemberId)
  2204. {
  2205.  
  2206. List<tblAdminTeammeber> _teams = new List<tblAdminTeammeber>();
  2207.  
  2208. try
  2209. {
  2210. SqlParameter[] Param = new SqlParameter[1];
  2211. Param[0] = new SqlParameter("@MemberId", MemberId);
  2212. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "tblAdminTeammebersGetAllByMemberId", Param);
  2213. _teams = (from DataRow row in dt.Rows
  2214. select new tblAdminTeammeber
  2215. {
  2216. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  2217. AdminTeamId = Convert.ToInt32(((row["AdminTeamId"] == DBNull.Value || row["AdminTeamId"] == null) ? "0" : row["AdminTeamId"]).ToString()),
  2218. AdminTeamMembersId = Convert.ToInt32((row["AdminTeamMembersId"] == DBNull.Value || row["AdminTeamMembersId"] == null) ? "0" : row["AdminTeamMembersId"]),
  2219. MemberId = Convert.ToInt32(((row["MemberId"] == DBNull.Value || row["MemberId"] == null) ? "0" : row["MemberId"]).ToString()),
  2220.  
  2221. }).ToList();
  2222. }
  2223. catch (Exception ex)
  2224. {
  2225. Helper.ErrorLog(ex.InnerException, "Q_Setting", "AdminTeammembersGetByMemberId", ex.Message);
  2226. }
  2227. return _teams;
  2228. }
  2229. /// <summary>
  2230. /// Email Tracking Add
  2231. /// </summary>
  2232. /// <param name="SenderId"></param>
  2233. /// <param name="ReceiverId"></param>
  2234. /// <param name="ReceiverEmail"></param>
  2235. /// <param name="MailContent"></param>
  2236. /// <param name="IsAotherContact"></param>
  2237. /// <param name="EntryBy"></param>
  2238. /// <param name="fromEmail"></param>
  2239. /// <param name="fromName"></param>
  2240. /// <param name="subject"></param>
  2241. /// <param name="inlinecss"></param>
  2242. /// <param name="signingDomain"></param>
  2243. /// <param name="financeId"></param>
  2244. /// <param name="mailContentString"></param>
  2245. /// <param name="notemsg"></param>
  2246. /// <param name="templateName"></param>
  2247. /// <param name="status"></param>
  2248. /// <param name="isfollowup"></param>
  2249. /// <param name="emailStatus"></param>
  2250. /// <param name="mandrilmsg"></param>
  2251. /// <returns></returns>
  2252. public int EmailTrackingAdd(int SenderId, int ReceiverId, string ReceiverEmail, string MailContent, bool IsAotherContact, int EntryBy, string fromEmail, string fromName, string subject, bool inlinecss, string signingDomain, int financeId, string mailContentString, string notemsg, string templateName, int status, bool isfollowup, int emailStatus = 1, IEnumerable<EmailAddress> mandrilmsg = null)
  2253. {
  2254. int chk = 0;
  2255. try
  2256. {
  2257. if (con.Session["LoggedInUserAccountId"] != null)
  2258. {
  2259. SqlParameter[] Param = new SqlParameter[21];
  2260. Param[0] = new SqlParameter("@SenderId", SenderId);
  2261. Param[1] = new SqlParameter("@ReceiverId", ReceiverId);
  2262. Param[2] = new SqlParameter("@ReceiverEmail", ReceiverEmail);
  2263. Param[3] = new SqlParameter("@MailContent", MailContent);
  2264. Param[4] = new SqlParameter("@IsAotherContact", IsAotherContact);
  2265. Param[5] = new SqlParameter("@EntryBy", EntryBy);
  2266. Param[6] = new SqlParameter("@IsActive", true);
  2267. Param[7] = new SqlParameter("@IsDelete", false);
  2268. Param[8] = new SqlParameter("@FromEmail", fromEmail);
  2269. Param[9] = new SqlParameter("@FromName", fromName);
  2270. Param[10] = new SqlParameter("@Subject", subject);
  2271. Param[11] = new SqlParameter("@InlineCss", inlinecss);
  2272. Param[12] = new SqlParameter("@SigningDomain", signingDomain);
  2273. Param[13] = new SqlParameter("@financeId", financeId);
  2274. Param[14] = new SqlParameter("@MailContentstring", mailContentString);
  2275. Param[15] = new SqlParameter("@NoteMsg", notemsg);
  2276. Param[16] = new SqlParameter("@TemplateName", templateName);
  2277. Param[17] = new SqlParameter("@status", status);
  2278. Param[19] = new SqlParameter("@Isfollowup", isfollowup);
  2279. Param[20] = new SqlParameter("@EmailStatus", emailStatus);
  2280.  
  2281. // Param[18] = new SqlParameter("@new_identity",ParameterDirection.Output);
  2282. SqlParameter id = new SqlParameter();
  2283. id.SqlDbType = SqlDbType.Int;
  2284. id.Direction = ParameterDirection.Output;
  2285. id.ParameterName = "@new_identity";
  2286. Param[18] = id;
  2287. string _procedurename = "EmailTrackingAdd";
  2288.  
  2289. chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  2290. var trackingId = Param[18].Value;
  2291.  
  2292. if (chk > 0 && trackingId != null)
  2293. {
  2294. if (mandrilmsg != null)
  2295. {
  2296. foreach (var v in mandrilmsg)
  2297. {
  2298. SqlParameter[] Param1 = new SqlParameter[3];
  2299. Param1[0] = new SqlParameter("@TrackingId", trackingId);
  2300. Param1[1] = new SqlParameter("@Email", v.email);
  2301. Param1[2] = new SqlParameter("@Name", v.name);
  2302. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "AddEmailForMail", Param1);
  2303. }
  2304. }
  2305. }
  2306.  
  2307. }
  2308.  
  2309. }
  2310. catch (Exception ex)
  2311. {
  2312. Helper.ErrorLog(ex.InnerException, "Q_Setting", "EmailTrackingAdd", ex.Message);
  2313. }
  2314. return chk;
  2315. }
  2316. /// <summary>
  2317. /// Getting Broker List for tree structure
  2318. /// </summary>
  2319. /// <param name="userid">User Id</param>
  2320. /// <returns>Broker List</returns>
  2321. public List<Clients> GetBrokersWithTeams(int userid)
  2322. {
  2323. Q_Application _obj = new Q_Application();
  2324. int teamId = 0;
  2325. string brokersIds = "";
  2326. int _userType = 0;
  2327. int _accountId = 0;
  2328.  
  2329. _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
  2330.  
  2331. var _Id = 0;
  2332.  
  2333. if (_userType == (int)UserType.Admin)
  2334. _Id = _accountId;
  2335. else if (_userType == (int)UserType.Manager)
  2336. _Id = teamId;
  2337. else if (_userType == (int)UserType.Broker)
  2338. _Id = userid;
  2339. else if (_userType == (int)UserType.GeneralUser)
  2340. {
  2341. int account = ctx.tblaccounts.Where(u => u.accountid == _accountId).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
  2342. _Id = account;
  2343. }
  2344.  
  2345.  
  2346. SqlParameter[] Param = new SqlParameter[2];
  2347. Param[0] = new SqlParameter("@UserType", _userType);
  2348. Param[1] = new SqlParameter("@ID", _Id);
  2349.  
  2350. List<Clients> _teams = new List<Clients>();
  2351.  
  2352. try
  2353. {
  2354. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokersWithTeams", Param);
  2355. _teams = (from DataRow row in dt.Rows
  2356. select new Clients
  2357. {
  2358. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  2359. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  2360. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  2361. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  2362. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  2363. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  2364. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  2365. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  2366. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  2367. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  2368. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2369.  
  2370. }).ToList();
  2371. }
  2372. catch (Exception ex)
  2373. {
  2374. Helper.ErrorLog(ex.InnerException, "Qsetting", "GetBrokerWithTeams", ex.Message);
  2375. }
  2376. return _teams;
  2377. }
  2378. /// <summary>
  2379. /// Get Referral Brokers With Teams
  2380. /// </summary>
  2381. /// <param name="userid"></param>
  2382. /// <returns></returns>
  2383. public List<Clients> GetReferralBrokersWithTeams(int userid)
  2384. {
  2385. Q_Application _obj = new Q_Application();
  2386. int teamId = 0;
  2387. string brokersIds = "";
  2388. int _userType = 0;
  2389. int _accountId = 0;
  2390. _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
  2391.  
  2392. var _Id = 0;
  2393.  
  2394. if (_userType == (int)UserType.Admin)
  2395. _Id = _accountId;
  2396. else if (_userType == (int)UserType.Manager)
  2397. _Id = teamId;
  2398. else if (_userType == (int)UserType.Broker)
  2399. _Id = userid;
  2400. else if (_userType == (int)UserType.GeneralUser)
  2401. {
  2402. int account = ctx.tblaccounts.Where(u => u.accountid == _accountId).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
  2403. _Id = account;
  2404. }
  2405.  
  2406.  
  2407. SqlParameter[] Param = new SqlParameter[2];
  2408. Param[0] = new SqlParameter("@UserType", 3);
  2409. Param[1] = new SqlParameter("@ID", _Id);
  2410.  
  2411. List<Clients> _teams = new List<Clients>();
  2412.  
  2413. try
  2414. {
  2415. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetReferralBrokersWithTeams", Param);
  2416. _teams = (from DataRow row in dt.Rows
  2417. select new Clients
  2418. {
  2419. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  2420. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  2421. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  2422. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  2423. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  2424. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  2425. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  2426. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  2427. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  2428. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  2429. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2430.  
  2431. }).ToList();
  2432. }
  2433. catch (Exception ex)
  2434. {
  2435. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetRferralBrokersWithTeams", ex.Message);
  2436. }
  2437. return _teams;
  2438. }
  2439. /// <summary>
  2440. /// Finding Referral Broker for logged in user with user id
  2441. /// </summary>
  2442. /// <param name="accid"></param>
  2443. /// <param name="userid"></param>
  2444. /// <returns></returns>
  2445. public List<Clients> FindReferralBrokerForLoggedInUserWithUserId(int accid, int userid)
  2446. {
  2447. bool flag = false;
  2448. List<Clients> brokers = new List<Clients>();
  2449. Q_Application _obj = new Q_Application();
  2450.  
  2451. try
  2452. {
  2453.  
  2454. int teamId = 0;
  2455. string brokersIds = "";
  2456. int _userType = 0;
  2457. int _accountId = 0;
  2458. _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
  2459.  
  2460. //Updated With Store Procedure For Navigation Delay ********* 7/7/2014 ********************************************
  2461.  
  2462. var _Id = 0;
  2463.  
  2464. if (_userType == (int)UserType.Admin)
  2465. _Id = _accountId;
  2466. else if (_userType == (int)UserType.Manager)
  2467. _Id = teamId;
  2468. else if (_userType == (int)UserType.Broker)
  2469. _Id = userid;
  2470. else if (_userType == (int)UserType.GeneralUser)
  2471. {
  2472. int account = ctx.tblaccounts.Where(u => u.accountid == userid).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
  2473. _Id = account;
  2474. }
  2475.  
  2476. SqlParameter[] Param = new SqlParameter[2];
  2477. Param[0] = new SqlParameter("@UserType", _userType);
  2478. Param[1] = new SqlParameter("@ID", _Id);
  2479. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindReferralBrokerForLoggedInUserWithUserId", Param);
  2480.  
  2481. brokers = (from DataRow row in dt.Rows
  2482. select new Clients
  2483. {
  2484. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  2485. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  2486. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  2487. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  2488. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  2489. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  2490. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  2491. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  2492. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  2493. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  2494. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2495. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  2496. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
  2497. }).ToList();
  2498.  
  2499. //**********************************************************************************
  2500.  
  2501. return brokers;
  2502. }
  2503. catch (Exception ex)
  2504. {
  2505. Helper.ErrorLog(ex.InnerException, "Q_Setting", "FindReferralBrokerForLoggedInUserWithUserId", ex.Message);
  2506. return brokers;
  2507. }
  2508. }
  2509. /// <summary>
  2510. /// Getting and setting Permission
  2511. /// </summary>
  2512. /// <param name="loginuserid"></param>
  2513. public void GetSetPermission(int loginuserid)
  2514. {
  2515. try
  2516. {
  2517. if (SessionWrapper.PermissionSession == null)
  2518. {
  2519. PermissionSession objS = new PermissionSession();
  2520. SessionWrapper.PermissionSession = objS;
  2521. }
  2522. SessionWrapper.PermissionSession.UserId = loginuserid;
  2523.  
  2524. Q_Application obj = new Q_Application();
  2525. if (obj.CheckIsSuperAdmin(loginuserid) == 1)
  2526. {
  2527. SessionWrapper.PermissionSession.IsFullPermission = true;
  2528. SessionWrapper.PermissionSession.IsViewAllData = true;
  2529. SessionWrapper.PermissionSession.IsUpdateAllData = true;
  2530. SessionWrapper.PermissionSession.IsPrintAllData = true;
  2531. }
  2532. else
  2533. {
  2534. SessionWrapper.PermissionSession.IsFullPermission = false;
  2535.  
  2536. List<UserPermissionModel> _permissions = new List<UserPermissionModel>();
  2537. SqlParameter[] Param = new SqlParameter[1];
  2538. Param[0] = new SqlParameter("@UserId", loginuserid);
  2539. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "tblUserPermissionGetByUserId", Param);
  2540. _permissions = (from DataRow row in dt.Rows
  2541. select new UserPermissionModel
  2542. {
  2543. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2544. PermissionId = Convert.ToInt32(((row["PermissionId"] == DBNull.Value || row["PermissionId"] == null) ? "0" : row["PermissionId"]).ToString()),
  2545. PermissionNames = Convert.ToString((row["PermissionName"] == DBNull.Value || row["PermissionName"] == null) ? "" : row["PermissionName"]),
  2546.  
  2547. }).ToList();
  2548.  
  2549. if (_permissions.Any(c => c.userid == loginuserid && c.PermissionId == (int)Permission.ViewData))
  2550. {
  2551.  
  2552. SessionWrapper.PermissionSession.IsViewAllData = true;
  2553. }
  2554. else
  2555. {
  2556. SessionWrapper.PermissionSession.IsViewAllData = false;
  2557. }
  2558.  
  2559. if (_permissions.Any(c => c.userid == loginuserid && c.PermissionId == (int)Permission.UpdateData))
  2560. {
  2561.  
  2562. SessionWrapper.PermissionSession.IsUpdateAllData = true;
  2563. }
  2564. else
  2565. {
  2566. SessionWrapper.PermissionSession.IsUpdateAllData = false;
  2567. }
  2568.  
  2569. if (_permissions.Any(c => c.userid == loginuserid && c.PermissionId == (int)Permission.PrintReport))
  2570. {
  2571. SessionWrapper.PermissionSession.IsPrintAllData = true;
  2572. }
  2573. else
  2574. {
  2575. SessionWrapper.PermissionSession.IsPrintAllData = false;
  2576. }
  2577.  
  2578.  
  2579. }
  2580.  
  2581. }
  2582. catch (Exception ex)
  2583. {
  2584. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetsetPermission", ex.Message);
  2585. }
  2586. }
  2587.  
  2588.  
  2589. #region GetYearsList
  2590. /// <summary>
  2591. /// Getting Years for autocomplete
  2592. /// </summary>
  2593. /// <param name="SearchText"></param>
  2594. /// <returns></returns>
  2595. public List<string> GetYearsForAutoComplete(string SearchText)
  2596. {
  2597. List<string> _tblusers = new List<string>();
  2598. try
  2599. {
  2600. SqlParameter[] Param = new SqlParameter[1];
  2601. Param[0] = new SqlParameter("@SearchText", SearchText);
  2602. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetYearsForAutoComplete", Param);
  2603. _tblusers = (from DataRow row in dt.Rows
  2604. select Convert.ToString(((row["ActivityYear"] == DBNull.Value || row["ActivityYear"] == null) ? "" : row["ActivityYear"]).ToString())
  2605. ).ToList();
  2606. }
  2607. catch (Exception ex)
  2608. {
  2609. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetYearsForAutocomplete", ex.Message);
  2610. }
  2611.  
  2612. return _tblusers;
  2613. }
  2614. #endregion
  2615.  
  2616. #region GetBrokersNameList
  2617. /// <summary>
  2618. /// Getting Brokers for autocomplete
  2619. /// </summary>
  2620. /// <param name="SearchText"></param>
  2621. /// <param name="UserType"></param>
  2622. /// <param name="ID"></param>
  2623. /// <returns></returns>
  2624. public List<string> GetBrokersForAutoComplete(string SearchText, int UserType, int ID)
  2625. {
  2626. List<string> _tblusers = new List<string>();
  2627. try
  2628. {
  2629. SqlParameter[] Param = new SqlParameter[3];
  2630. Param[0] = new SqlParameter("@SearchText", SearchText);
  2631. Param[1] = new SqlParameter("@UserType", UserType);
  2632. Param[2] = new SqlParameter("@ID", ID);
  2633. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokersForAutoComplete", Param);
  2634. _tblusers = (from DataRow row in dt.Rows
  2635. select Convert.ToString(((row["brokername"] == DBNull.Value || row["brokername"] == null) ? "" : row["brokername"]).ToString())
  2636. ).ToList();
  2637. }
  2638. catch (Exception ex)
  2639. {
  2640. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetBrokerForComplete", ex.Message);
  2641. }
  2642.  
  2643. return _tblusers;
  2644. }
  2645.  
  2646. #endregion
  2647.  
  2648. #region GetTeamManager
  2649. /// <summary>
  2650. /// Get Team Manager Dropdown
  2651. /// </summary>
  2652. /// <param name="UserType"></param>
  2653. /// <param name="ID"></param>
  2654. /// <returns></returns>
  2655. public List<tbluser> GetTeamManagerDropDown(int UserType, int ID)
  2656. {
  2657. List<tbluser> _tblmanagers = new List<tbluser>();
  2658. try
  2659. {
  2660. SqlParameter[] Param = new SqlParameter[2];
  2661. Param[0] = new SqlParameter("@UserType", UserType);
  2662. Param[1] = new SqlParameter("@ID", ID);
  2663. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetTeamManager", Param);
  2664. _tblmanagers = (from DataRow row in dt.Rows
  2665. select new tbluser
  2666. {
  2667. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  2668. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  2669. brokername = Convert.ToString((row["brokername"] == DBNull.Value || row["brokername"] == null) ? " " : row["brokername"])
  2670. }).ToList();
  2671. }
  2672. catch (Exception ex)
  2673. {
  2674. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetteamManagerdropDown", ex.Message);
  2675. }
  2676. return _tblmanagers;
  2677. }
  2678. #endregion
  2679.  
  2680.  
  2681. /***************************************************
  2682. * Code Block for E-Mail subscription/ unsubscription
  2683. *
  2684. * Created On : 31/01/2015
  2685. *
  2686. * ************************************************/
  2687. /// <summary>
  2688. /// Getting User Subscription
  2689. /// </summary>
  2690. /// <param name="loggedinuserid"></param>
  2691. /// <param name="pageNo"></param>
  2692. /// <param name="pageSize"></param>
  2693. /// <param name="brokers"></param>
  2694. /// <param name="clients"></param>
  2695. /// <param name="username"></param>
  2696. /// <param name="isSusbcribed"></param>
  2697. /// <returns></returns>
  2698. public DataTable GetUSerSubscription(int loggedinuserid, int pageNo, int pageSize, string brokers, string clients, string username, bool isSusbcribed = false)
  2699. {
  2700. DataTable subscribedUsers = null;
  2701. try
  2702. {
  2703. SqlParameter[] Param = new SqlParameter[7];
  2704. Param[0] = new SqlParameter("@Page", pageNo);
  2705. Param[1] = new SqlParameter("@RecsPerPage", pageSize);
  2706. Param[2] = new SqlParameter("@SubscribedUsers", isSusbcribed ? false : true /* for tweaking checked property */);
  2707. Param[3] = new SqlParameter("@Broker", string.IsNullOrEmpty(brokers) ? null : brokers.Trim());
  2708. Param[4] = new SqlParameter("@Client", string.IsNullOrEmpty(clients) ? null : clients.Trim());
  2709. Param[5] = new SqlParameter("@UserName", string.IsNullOrEmpty(username) ? null : username.Trim());
  2710. Param[6] = new SqlParameter("@CurrentUserId", loggedinuserid);
  2711.  
  2712. subscribedUsers = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "proc_SubscribedUsersList", Param);
  2713.  
  2714.  
  2715. }
  2716. catch (Exception ex)
  2717. {
  2718. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetUserSubscription", ex.Message);
  2719. throw ex;
  2720. }
  2721. return subscribedUsers;
  2722. }
  2723. /// <summary>
  2724. /// Get All Clients
  2725. /// </summary>
  2726. /// <param name="loggedinuserid"></param>
  2727. /// <returns></returns>
  2728. public DataTable GetClients(int loggedinuserid)
  2729. {
  2730. DataTable subscribedUsers = null;
  2731. SqlParameter[] par = new SqlParameter[]
  2732. {
  2733. new SqlParameter("@CurrentUserId", loggedinuserid)
  2734. };
  2735. try
  2736. {
  2737. subscribedUsers = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "proc_GetClients_Update", par);
  2738. }
  2739. catch (Exception ex)
  2740. {
  2741. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetClients", ex.Message);
  2742. throw ex;
  2743. }
  2744. return subscribedUsers;
  2745. }
  2746. /// <summary>
  2747. /// Getting Brokers
  2748. /// </summary>
  2749. /// <param name="loggedinuserid"></param>
  2750. /// <returns></returns>
  2751. public DataTable GetBrokers(int loggedinuserid)
  2752. {
  2753. DataTable subscribedUsers = null;
  2754.  
  2755. SqlParameter[] par = new SqlParameter[]
  2756. {
  2757. new SqlParameter("@Id",loggedinuserid)
  2758. };
  2759. try
  2760. {
  2761. subscribedUsers = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "proc_GetBrokers", par);
  2762. }
  2763. catch (Exception ex)
  2764. {
  2765. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetBrokers", ex.Message);
  2766. throw ex;
  2767. }
  2768. return subscribedUsers;
  2769. }
  2770. #region Getting all User
  2771.  
  2772. /// <summary>
  2773. /// Get all the user details to show in assign notes functionality.
  2774. /// </summary>
  2775. /// <param name="accId"></param>
  2776. /// <param name="userid"></param>
  2777. /// <returns></returns>
  2778. public List<Users> GetAllUser(int accId, int userid)
  2779. {
  2780. bool IsSubAdmin = ctx.tblusers.Where(x => x.userid == userid && x.administrator == true && x.active == true && x.broker == false && x.AdminId != null && x.AdminId != 0).Any();
  2781. if (IsSubAdmin)
  2782. {
  2783. accId = ctx.tblusers.Where(x => x.userid == userid).FirstOrDefault().AdminId ?? 0;
  2784. }
  2785. List<Users> allUser = new List<Users>();
  2786. allUser = (from u in ctx.tblusers
  2787. where (u.userid != userid && u.account == accId && u.active == true) || (u.AdminId == accId && u.active == true && u.administrator == true && u.broker == false && u.userid != userid)
  2788. select new Users()
  2789. {
  2790. userName = u.brokername,
  2791. userId = u.userid
  2792. }).OrderBy(x => x.userName).ToList();
  2793.  
  2794. return allUser;
  2795. }
  2796. /// <summary>
  2797. /// Getting all user for manage pwd
  2798. /// </summary>
  2799. /// <param name="accId"></param>
  2800. /// <param name="userid"></param>
  2801. /// <param name="usertype"></param>
  2802. /// <param name="pageNo"></param>
  2803. /// <param name="pagesize"></param>
  2804. /// <param name="searchName"></param>
  2805. /// <param name="total"></param>
  2806. /// <returns></returns>
  2807. public List<Users> GetAllUserForManagePwd(int accId, int userid, int usertype, int pageNo, int pagesize, string searchName, out int total)
  2808. {
  2809.  
  2810.  
  2811. total = 0;
  2812. int Type = 0;
  2813. List<Users> allUser = new List<Users>();
  2814. SqlParameter[] Param = new SqlParameter[2];
  2815. if (usertype > 0)
  2816. Param[0] = new SqlParameter("@usertype", usertype);
  2817. if (!string.IsNullOrEmpty(searchName))
  2818. Param[1] = new SqlParameter("@searchName", searchName);
  2819. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetDataForManagePwd", Param);
  2820. if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  2821. {
  2822. allUser = Occfinance.Code.DataTableHelper.CreateListFromTableForAll<Users>(ds.Tables[0]).ToList();
  2823. }
  2824. total = allUser.Count;
  2825. return allUser;
  2826. }
  2827. /// <summary>
  2828. /// Getting User type
  2829. /// </summary>
  2830. /// <param name="userId"></param>
  2831. /// <param name="userType"></param>
  2832. /// <returns></returns>
  2833. public string GetUserType(int userId, out int userType)
  2834. {
  2835. userType = 0;
  2836. string uType = string.Empty;
  2837. if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == false || u.broker.Value == false) && (!u.AdminId.HasValue || u.AdminId.Value == 0)))
  2838. {
  2839. uType = "CEO/Admin";
  2840. userType = Convert.ToInt32(UserTypes.Admin);
  2841. }
  2842. else if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == false || u.broker.Value == false) && (u.AdminId.HasValue && u.AdminId.Value > 0)))
  2843. {
  2844. uType = "Senior Adviser";
  2845. userType = Convert.ToInt32(UserTypes.SubAdmin);
  2846. }
  2847. else if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.administrator.HasValue == false || u.administrator.Value == false) && (u.broker.HasValue == true && u.broker.Value == true)))
  2848. {
  2849. uType = "Adviser";
  2850. userType = Convert.ToInt32(UserTypes.Broker);
  2851. }
  2852. else if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.administrator.HasValue == false || u.administrator.Value == false) && (u.broker.HasValue == false || u.broker.Value == false)))
  2853. {
  2854. uType = "Introducer";
  2855. userType = Convert.ToInt32(UserTypes.GeneralUser);
  2856. }
  2857.  
  2858. return uType;
  2859. }
  2860. #endregion Getting all User
  2861.  
  2862. #region [Getting all Existing clients]
  2863. /// <summary>
  2864. /// Get all Existing clients
  2865. /// </summary>
  2866. /// <param name="pageNo"></param>
  2867. /// <param name="pagesize"></param>
  2868. /// <param name="searchName"></param>
  2869. /// <param name="loggedInUser"></param>
  2870. /// <param name="total"></param>
  2871. /// <returns></returns>
  2872. public List<ExistingClients> GetAllExistingClients(int pageNo, int pagesize, string searchName, int loggedInUser, out int total)
  2873. {
  2874.  
  2875.  
  2876. total = 0;
  2877.  
  2878. List<ExistingClients> allclients = new List<ExistingClients>();
  2879. SqlParameter[] Param = new SqlParameter[4];
  2880.  
  2881. if (!string.IsNullOrEmpty(searchName))
  2882. Param[0] = new SqlParameter("@searchName", searchName);
  2883. Param[1] = new SqlParameter("@PageNo", pageNo);
  2884. Param[2] = new SqlParameter("@PageSize", pagesize);
  2885. Param[3] = new SqlParameter("@loggedInUser", loggedInUser);
  2886. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetContactForfactFind", Param);
  2887. if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  2888. {
  2889. allclients = Occfinance.Code.DataTableHelper.CreateListFromTableForAll<ExistingClients>(ds.Tables[0]).ToList();
  2890. total = allclients[0].TotalCount;
  2891. }
  2892.  
  2893. return allclients;
  2894. }
  2895.  
  2896.  
  2897. #endregion
  2898.  
  2899. #region[Defualt Currency Setting ]
  2900. public string GetDefaultCurrency()
  2901. {
  2902. try
  2903. {
  2904. db_occfinance_5572Entities _ctx = new db_occfinance_5572Entities();
  2905. var defaultCurrency = _ctx.tblDefaultCurrencySettings.Where(x => x.IsDefault == true).FirstOrDefault();
  2906.  
  2907. return defaultCurrency == null ? string.Empty : defaultCurrency.Value;
  2908. }
  2909. catch (Exception ex)
  2910. {
  2911. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetDeafultCurrency", ex.Message);
  2912. return string.Empty;
  2913. }
  2914. }
  2915.  
  2916. public void UpdateDefaultCurrency(string val)
  2917. {
  2918. try
  2919. {
  2920. db_occfinance_5572Entities _ctx = new db_occfinance_5572Entities();
  2921. var defaultCurrency = _ctx.tblDefaultCurrencySettings.Where(x => x.Value == val).FirstOrDefault();
  2922. var allCurrency = _ctx.tblDefaultCurrencySettings.ToList();
  2923. if (defaultCurrency != null)
  2924. {
  2925. foreach (var v in allCurrency)
  2926. {
  2927. v.IsDefault = false;
  2928. }
  2929. defaultCurrency.IsDefault = true;
  2930. _ctx.SaveChanges();
  2931.  
  2932. HttpContext.Current.Session["DefaultCurrency"] = defaultCurrency.Value;
  2933. }
  2934. }
  2935. catch (Exception ex)
  2936. {
  2937. Helper.ErrorLog(ex.InnerException, "Q_Setting", "GetDeafultCurrency", ex.Message);
  2938. }
  2939.  
  2940. }
  2941. #endregion
  2942.  
  2943.  
  2944. #region webservice Setting methode
  2945.  
  2946. #region Add broker from webservice
  2947.  
  2948. /// <summary>
  2949. /// WSAddBroker from webservice
  2950. /// </summary>
  2951. /// <param name="_userId"></param>
  2952. /// <param name="_accountId"></param>
  2953. /// <param name="brokername"></param>
  2954. /// <param name="username"></param>
  2955. /// <param name="accountid"></param>
  2956. /// <param name="TeamsArray"></param>
  2957. /// <param name="PrimaryContact"></param>
  2958. /// <param name="SecondaryContact"></param>
  2959. /// <param name="Address1"></param>
  2960. /// <param name="Address2"></param>
  2961. /// <param name="OtherDetails"></param>
  2962. /// <param name="title"></param>
  2963. /// <param name="fax"></param>
  2964. /// <param name="qualification"></param>
  2965. /// <param name="brkImage"></param>
  2966. /// <returns></returns>
  2967. public bool WSAddBroker(int _userId, int _accountId, string brokername, string username, out int accountid, List<tblTeamMember> TeamsArray, string PrimaryContact, string SecondaryContact, string Address1, string Address2, string OtherDetails, string title, string fax, string qualification, string brkImage = "", string path = "")
  2968. {
  2969. bool result = false;
  2970. string fileName = "noimage.jpg";
  2971. string fullImagePath = "";
  2972. accountid = 0;
  2973. try
  2974. {
  2975. if (ctx.tblusers.Where(c => c.username.ToLower().Trim() == username.ToLower().Trim() && c.active == true && !string.IsNullOrEmpty(c.username)).Any())
  2976. {
  2977. result = false;
  2978. }
  2979. else
  2980. {
  2981. try
  2982. {
  2983. if (!string.IsNullOrWhiteSpace(brkImage))
  2984. {
  2985. fileName = Guid.NewGuid().ToString() + ".jpg";
  2986. fullImagePath = path + fileName;
  2987. byte[] imageBytes = Convert.FromBase64String(brkImage);
  2988. MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
  2989. ms.Write(imageBytes, 0, imageBytes.Length);
  2990. System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
  2991. image.Save(fullImagePath);
  2992. }
  2993. }
  2994. catch (Exception ex)
  2995. {
  2996. fileName = "noimage.jpg";
  2997. }
  2998.  
  2999. int parentaccountId = _accountId;
  3000.  
  3001. var u = ctx.tblusers.Add(new tbluser()
  3002. {
  3003. account = parentaccountId,
  3004. username = username,
  3005. password = "test",
  3006. active = true,
  3007. administrator = false,
  3008. Title = title,
  3009. brokername = brokername,
  3010. broker = true,
  3011. PrimaryContact = PrimaryContact ?? "",
  3012. SecondaryContact = SecondaryContact ?? "",
  3013. Address1 = Address1 ?? "",
  3014. Address2 = Address2 ?? "",
  3015. FAX = fax,
  3016. Qualification = qualification,
  3017. OtherDetails = OtherDetails ?? "",
  3018. BrokerImage = fileName
  3019.  
  3020. });
  3021. ctx.SaveChanges();
  3022. result = true;
  3023. accountid = u.userid;
  3024.  
  3025. //create Thumb
  3026. if (File.Exists(fullImagePath))
  3027. {
  3028. string thumbPath = path + "Thumb/" + u.userid + ".jpg";
  3029. System.Drawing.Image image = System.Drawing.Image.FromFile(fullImagePath);
  3030. System.Drawing.Image thumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
  3031. thumb.Save(thumbPath, System.Drawing.Imaging.ImageFormat.Jpeg);
  3032. }
  3033.  
  3034. string body = "Hi " + brokername + ", <br /><br />";
  3035. body += "Your email id: " + username + "<br /><br />";
  3036. body += "Password: test <br /><br />";
  3037. body += "Regards: <br /><br />";
  3038. body += "Apptrack Admin";
  3039.  
  3040. //-------------------------------------
  3041. List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
  3042.  
  3043. var _mailDrilEmails = new List<Mandrill.EmailAddress>();
  3044. Mandrill.EmailAddress objEm = new Mandrill.EmailAddress();
  3045. objEm.email = username;
  3046. objEm.name = brokername;
  3047. _mailDrilEmails.Add(objEm);
  3048.  
  3049. //Man DRILL ********************************************************************
  3050.  
  3051. var domain = "occfinance.com";
  3052. Mandrill.EmailMessage message = new Mandrill.EmailMessage();
  3053. var _mandrillMessage = new List<Mandrill.EmailMessage>();
  3054.  
  3055. message.to = _mailDrilEmails;
  3056. message.html = body;
  3057. message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
  3058. message.from_name = "OCC";
  3059. message.subject = "Your Apptrack Credential";
  3060. message.inline_css = true;
  3061. message.signing_domain = domain;
  3062. message.AddHeader("X-MC-SigningDomain", domain);
  3063. message.AddHeader("X-MC-TrackingDomain", domain);
  3064. _mandrillMessage.Add(message);
  3065.  
  3066. //********************************************************************************
  3067.  
  3068. // Manage The ManDRILLModel - 25-07-2014
  3069.  
  3070. var objMAN = new ManDRILLModel();
  3071. objMAN.contactId = 0;
  3072. objMAN.financeid = 0;
  3073. objMAN.mailcontent = body;
  3074. objMAN.MandrillMSG = message;
  3075. objMAN.IsAppContact = false;
  3076.  
  3077. objMAN.notemsg = "";
  3078.  
  3079. _mandrillOBJ.Add(objMAN);
  3080.  
  3081. int userId = _userId;
  3082. WebUtility.SendMailViaManDRILL(_mandrillOBJ, userId);
  3083. //-------------------------------------
  3084.  
  3085.  
  3086. int _type = 1;
  3087. if (TeamsArray != null)
  3088. {
  3089. foreach (var obj in TeamsArray)
  3090. {
  3091. if (obj.IsActive.HasValue && obj.IsActive.Value == true)
  3092. _type = 1;
  3093. else
  3094. _type = 2;
  3095.  
  3096. WSAddTeamMembers(_userId, _accountId, obj.TeamId.HasValue ? obj.TeamId.Value : 0, u.userid, userId, _type);
  3097. }
  3098. }
  3099. WSAddAdminTeamMembers(_userId, _accountId, parentaccountId, parentaccountId, u.userid, userId, 1);
  3100.  
  3101. // Add Default Permission ---------------------------
  3102. // 1- Admin User, 2- Broker, 3- General User As per the client response ON 21-07-2014
  3103. try
  3104. {
  3105. AddDefaultPermission(2, u.userid, parentaccountId, userId);
  3106. }
  3107. catch
  3108. {
  3109. }
  3110.  
  3111.  
  3112. }
  3113. return result;
  3114. }
  3115. catch (Exception)
  3116. {
  3117. return result;
  3118. }
  3119. }
  3120.  
  3121. #endregion
  3122.  
  3123. #region Update Broker
  3124. /// <summary>
  3125. /// Updating broker
  3126. /// </summary>
  3127. /// <param name="_userId"></param>
  3128. /// <param name="_accountId"></param>
  3129. /// <param name="brokername"></param>
  3130. /// <param name="username"></param>
  3131. /// <param name="brokerid"></param>
  3132. /// <param name="accountid"></param>
  3133. /// <param name="TeamsArray"></param>
  3134. /// <param name="PrimaryContact"></param>
  3135. /// <param name="SecondaryContact"></param>
  3136. /// <param name="Address1"></param>
  3137. /// <param name="Address2"></param>
  3138. /// <param name="OtherDetails"></param>
  3139. /// <param name="title"></param>
  3140. /// <param name="fax"></param>
  3141. /// <param name="qualification"></param>
  3142. /// <param name="brkImage"></param>
  3143. /// <returns></returns>
  3144. public bool WSUpdateBroker(int _userId, int _accountId, string brokername, string username, int brokerid, out int accountid, List<tblTeamMember> TeamsArray, string PrimaryContact, string SecondaryContact, string Address1, string Address2, string OtherDetails, string title, string fax, string qualification, string brkImage = "", string path = "")
  3145. {
  3146. bool result = false;
  3147. string fileName = string.Empty;
  3148. string fullImagePath = "";
  3149. accountid = 0;
  3150. try
  3151. {
  3152. if (brokerid > 0)
  3153. {
  3154. if (ctx.tblusers.Where(c => c.username.ToLower().Trim() == username.ToLower().Trim() && c.active == true && c.userid != brokerid && !string.IsNullOrEmpty(c.username)).Any())
  3155. {
  3156. result = false;
  3157. }
  3158. else
  3159. {
  3160. try
  3161. {
  3162. if (!string.IsNullOrWhiteSpace(brkImage))
  3163. {
  3164. fileName = Guid.NewGuid().ToString() + ".jpg";
  3165. fullImagePath = path + fileName;
  3166. byte[] imageBytes = Convert.FromBase64String(brkImage);
  3167. MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
  3168. ms.Write(imageBytes, 0, imageBytes.Length);
  3169. System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
  3170. image.Save(fullImagePath);
  3171. }
  3172. }
  3173. catch
  3174. {
  3175. fileName = "";
  3176. }
  3177.  
  3178. int parentaccountId = _accountId;
  3179. var u = ctx.tblusers.Where(c => c.userid == brokerid).FirstOrDefault();
  3180. u.account = parentaccountId;//broker.accountid,
  3181. u.username = username;
  3182. u.brokername = brokername;
  3183. u.Title = title;
  3184. u.PrimaryContact = PrimaryContact ?? "";
  3185. u.SecondaryContact = SecondaryContact ?? "";
  3186. u.Address1 = Address1 ?? "";
  3187. u.Address2 = Address2 ?? "";
  3188. u.FAX = fax;
  3189. u.Qualification = qualification;
  3190. u.OtherDetails = OtherDetails ?? "";
  3191. if (!string.IsNullOrWhiteSpace(fileName))
  3192. {
  3193. u.BrokerImage = fileName;
  3194. }
  3195. ctx.SaveChanges();
  3196. result = true;
  3197. accountid = u.userid;
  3198.  
  3199. //create Thumb
  3200. if (File.Exists(fullImagePath))
  3201. {
  3202. string thumbPath = path + "Thumb/" + u.userid + ".jpg";
  3203. System.Drawing.Image image = System.Drawing.Image.FromFile(fullImagePath);
  3204. System.Drawing.Image thumb = image.GetThumbnailImage(100, 100, () => false, IntPtr.Zero);
  3205. thumb.Save(thumbPath, System.Drawing.Imaging.ImageFormat.Jpeg);
  3206. }
  3207.  
  3208. string body = "Hi " + brokername + ", <br /><br />";
  3209. body += "Your updated email id: " + username + "<br /><br />";
  3210. body += "Password: " + u.password + " <br /><br />";
  3211. body += "Regards: <br /><br />";
  3212. body += "Apptrack Admin";
  3213.  
  3214. //------------------------------------------------------------
  3215.  
  3216. List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
  3217.  
  3218. var _mailDrilEmails = new List<Mandrill.EmailAddress>();
  3219. Mandrill.EmailAddress objEm = new Mandrill.EmailAddress();
  3220. objEm.email = username;
  3221. objEm.name = brokername;
  3222. _mailDrilEmails.Add(objEm);
  3223.  
  3224. //Man DRILL ********************************************************************
  3225.  
  3226. var domain = "occfinance.com";
  3227. Mandrill.EmailMessage message = new Mandrill.EmailMessage();
  3228. var _mandrillMessage = new List<Mandrill.EmailMessage>();
  3229.  
  3230. message.to = _mailDrilEmails;
  3231. message.html = body;
  3232. message.from_email = ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
  3233. message.from_name = "OCC";
  3234. message.subject = "Your Apptrack Credential";
  3235. message.inline_css = true;
  3236. message.signing_domain = domain;
  3237. message.AddHeader("X-MC-SigningDomain", domain);
  3238. message.AddHeader("X-MC-TrackingDomain", domain);
  3239. _mandrillMessage.Add(message);
  3240.  
  3241. //********************************************************************************
  3242.  
  3243. // Manage The ManDRILLModel - 25-07-2014
  3244.  
  3245. var objMAN = new ManDRILLModel();
  3246. objMAN.contactId = 0;
  3247. objMAN.financeid = 0;
  3248. objMAN.mailcontent = body;
  3249. objMAN.MandrillMSG = message;
  3250. objMAN.IsAppContact = false;
  3251.  
  3252. objMAN.notemsg = "";
  3253.  
  3254. _mandrillOBJ.Add(objMAN);
  3255.  
  3256. int userId = _userId;
  3257. WebUtility.SendMailViaManDRILL(_mandrillOBJ, userId);
  3258.  
  3259. //------------------------------------------------------------
  3260.  
  3261.  
  3262.  
  3263. int _type = 1;
  3264. if (TeamsArray != null)
  3265. {
  3266. foreach (var obj in TeamsArray)
  3267. {
  3268. if (obj.IsActive.HasValue && obj.IsActive.Value == true)
  3269. _type = 1;
  3270. else
  3271. _type = 2;
  3272.  
  3273. WSAddTeamMembers(_userId, _accountId, obj.TeamId.HasValue ? obj.TeamId.Value : 0, u.userid, userId, _type);
  3274. }
  3275. }
  3276. }
  3277.  
  3278. }
  3279. return result;
  3280. }
  3281. catch (Exception ex)
  3282. {
  3283. Helper.ErrorLog(ex.InnerException, "Q_Settings", "UpdateBroker", ex.Message);
  3284. return result;
  3285. }
  3286. }
  3287.  
  3288. /// <summary>
  3289. /// Updating Team Broker
  3290. /// </summary>
  3291. /// <param name="_userId"></param>
  3292. /// <param name="_accountId"></param>
  3293. /// <param name="brokername"></param>
  3294. /// <param name="username"></param>
  3295. /// <param name="brokerid"></param>
  3296. /// <param name="accountid"></param>
  3297. /// <param name="TeamsArray"></param>
  3298. /// <returns></returns>
  3299. public bool WSUpdateTeamBroker(int _userId, int _accountId, string brokername, string username, int brokerid, out int accountid, List<tblAdminTeammeber> TeamsArray)
  3300. {
  3301. bool result = false;
  3302. accountid = 0;
  3303. try
  3304. {
  3305. if (brokerid > 0)
  3306. {
  3307. int parentaccountId = _accountId;
  3308. var u = ctx.tblusers.Where(c => c.userid == brokerid).FirstOrDefault();
  3309. u.AdminId = 0;
  3310. ctx.SaveChanges();
  3311. result = true;
  3312. accountid = u.userid;
  3313. int userId = _userId;
  3314. int _type = 1;
  3315. if (TeamsArray != null)
  3316. {
  3317. foreach (var obj in TeamsArray)
  3318. {
  3319. if (obj.IsActive.HasValue && obj.IsActive.Value == true)
  3320. _type = 1;
  3321. else
  3322. _type = 2;
  3323.  
  3324. WSAddAdminTeamMembers(_userId, _accountId, obj.AdminTeamId.HasValue ? obj.AdminTeamId.Value : 0, obj.AdminTeamId.HasValue ? obj.AdminTeamId.Value : 0, u.userid, userId, _type);
  3325. }
  3326. }
  3327. }
  3328. return result;
  3329. }
  3330. catch (Exception ex)
  3331. {
  3332. Helper.ErrorLog(ex.InnerException, "Q_setting", "UpdateTeamBroker", ex.Message);
  3333. return result;
  3334. }
  3335. }
  3336.  
  3337. /// <summary>
  3338. /// WSAddAdminTeamMembers
  3339. /// </summary>
  3340. /// <param name="_userId"></param>
  3341. /// <param name="_accountId"></param>
  3342. /// <param name="AdminTeamId"></param>
  3343. /// <param name="AdminId"></param>
  3344. /// <param name="MemberId"></param>
  3345. /// <param name="userId"></param>
  3346. /// <param name="Type"></param>
  3347. /// <returns></returns>
  3348. public int WSAddAdminTeamMembers(int _userId, int _accountId, int AdminTeamId, int AdminId, int MemberId, int userId, int Type)
  3349. {
  3350. int chk = 0;
  3351. try
  3352. {
  3353. if (_accountId > 0)
  3354. {
  3355. SqlParameter[] Param = new SqlParameter[7];
  3356. Param[0] = new SqlParameter("@AdminTeamId", AdminTeamId);
  3357. Param[1] = new SqlParameter("@AdminId", AdminId);
  3358. Param[2] = new SqlParameter("@MemberId", MemberId);
  3359. Param[3] = new SqlParameter("@EntryBy", userId);
  3360. Param[4] = new SqlParameter("@IsActive", true);
  3361. Param[5] = new SqlParameter("@IsDelete", false);
  3362. Param[6] = new SqlParameter("@Type", Type);
  3363.  
  3364. string _procedurename = "tblAdminTeammebersADD";
  3365.  
  3366. chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  3367.  
  3368. }
  3369.  
  3370. }
  3371. catch (Exception ex)
  3372. {
  3373. Helper.ErrorLog(ex.InnerException, "Q_Setting", "AddAdminTeammember", ex.Message);
  3374. }
  3375. return chk;
  3376. }
  3377.  
  3378. #endregion
  3379.  
  3380. #region Add Team calling from webservice
  3381. /// <summary>
  3382. /// Adding Team calling from webservice
  3383. /// </summary>
  3384. /// <param name="_userId"></param>
  3385. /// <param name="_accountId"></param>
  3386. /// <param name="teamName"></param>
  3387. /// <param name="managerId"></param>
  3388. /// <param name="teamid"></param>
  3389. /// <returns></returns>
  3390. public int WSAddTeam(int _userId, int _accountId, string teamName, int managerId, out int teamid)
  3391. {
  3392.  
  3393. teamid = 0;
  3394. try
  3395. {
  3396. var AccountId = _accountId;
  3397. var userId = _userId;
  3398.  
  3399. SqlParameter[] Param = new SqlParameter[9];
  3400. Param[0] = new SqlParameter("@AccountId", AccountId);
  3401. Param[1] = new SqlParameter("@CompanyName", "0");
  3402. Param[2] = new SqlParameter("@TeamName", teamName);
  3403. Param[3] = new SqlParameter("@Regions", "0");
  3404. Param[4] = new SqlParameter("@ManagerId", managerId);
  3405. Param[5] = new SqlParameter("@EntryBy", userId);
  3406. Param[6] = new SqlParameter("@IsActive", true);
  3407. Param[7] = new SqlParameter("@IsDelete", false);
  3408.  
  3409. Param[8] = new SqlParameter("@TeamId", 0);
  3410. Param[8].Direction = ParameterDirection.Output;
  3411. string _procedurename = "tblTeamAdd";
  3412.  
  3413. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  3414.  
  3415. teamid = Convert.ToInt32(Param[8] != null ? Param[8].SqlValue.ToString() : "0");
  3416.  
  3417. if (teamid > 0)
  3418. {
  3419. if (WSAddTeamMembers(_userId, _accountId, teamid, managerId, userId, 1) > 0)
  3420. { return teamid; }
  3421. }
  3422.  
  3423. return teamid;
  3424. }
  3425. catch (Exception ex)
  3426. {
  3427. Helper.ErrorLog(ex.InnerException, "Q_Setting", "AddTeam", ex.Message);
  3428. return 0;
  3429. }
  3430. }
  3431.  
  3432. #endregion
  3433.  
  3434. #region Add Team Members calling from webservice
  3435. /// <summary>
  3436. /// Adding Team member calling from webservice
  3437. /// </summary>
  3438. /// <param name="_userId"></param>
  3439. /// <param name="_accountId"></param>
  3440. /// <param name="TeamId"></param>
  3441. /// <param name="MemberId"></param>
  3442. /// <param name="userId"></param>
  3443. /// <param name="Type"></param>
  3444. /// <returns></returns>
  3445. public int WSAddTeamMembers(int _userId, int _accountId, int TeamId, int MemberId, int userId, int Type)
  3446. {
  3447. int chk = 0;
  3448. try
  3449. {
  3450. SqlParameter[] Param = new SqlParameter[6];
  3451. Param[0] = new SqlParameter("@TeamId", TeamId);
  3452. Param[1] = new SqlParameter("@MemberId", MemberId);
  3453. Param[2] = new SqlParameter("@EntryBy", userId);
  3454. Param[3] = new SqlParameter("@IsActive", true);
  3455. Param[4] = new SqlParameter("@IsDelete", false);
  3456. Param[5] = new SqlParameter("@Type", Type);
  3457.  
  3458. string _procedurename = "tblTeamMembersAdd";
  3459.  
  3460. chk = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  3461.  
  3462. }
  3463. catch (Exception ex)
  3464. {
  3465. Helper.ErrorLog(ex.InnerException, "Q_Setting", "Addteammembers", ex.Message);
  3466. }
  3467. return chk;
  3468. }
  3469.  
  3470.  
  3471. #endregion
  3472.  
  3473. #region Update Team calling from webservice
  3474. /// <summary>
  3475. /// Update team calling from webservice
  3476. /// </summary>
  3477. /// <param name="_userId"></param>
  3478. /// <param name="_accountId"></param>
  3479. /// <param name="teamName"></param>
  3480. /// <param name="managerId"></param>
  3481. /// <param name="editteamId"></param>
  3482. /// <param name="teamid"></param>
  3483. /// <returns></returns>
  3484. public int WSUpdateTeam(int _userId, int _accountId, string teamName, int managerId, int editteamId, out int teamid)
  3485. {
  3486.  
  3487. teamid = 0;
  3488. try
  3489. {
  3490. var AccountId = _accountId;
  3491. var userId = _userId;
  3492. SqlParameter[] Param = new SqlParameter[10];
  3493. Param[0] = new SqlParameter("@TeamId", editteamId);
  3494. Param[1] = new SqlParameter("@AccountId", AccountId);
  3495. Param[2] = new SqlParameter("@CompanyName", "0");
  3496. Param[3] = new SqlParameter("@TeamName", teamName);
  3497. Param[4] = new SqlParameter("@Regions", "0");
  3498. Param[5] = new SqlParameter("@ManagerId", managerId);
  3499. Param[6] = new SqlParameter("@UpdateBy", userId);
  3500. Param[7] = new SqlParameter("@IsActive", true);
  3501. Param[8] = new SqlParameter("@IsDelete", false);
  3502.  
  3503. Param[9] = new SqlParameter("@Chk", 0);
  3504. Param[9].Direction = ParameterDirection.Output;
  3505. string _procedurename = "tblTeamUpdate";
  3506.  
  3507. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  3508.  
  3509. teamid = Convert.ToInt32(Param[9] != null ? Param[9].SqlValue.ToString() : "0");
  3510.  
  3511. if (teamid > 0)
  3512. {
  3513. if (WSAddTeamMembers(_userId, _accountId, editteamId, managerId, userId, 1) > 0)
  3514. return teamid;
  3515. }
  3516.  
  3517. return teamid;
  3518. }
  3519. catch (Exception ex)
  3520. {
  3521. Helper.ErrorLog(ex.InnerException, "Q_Setting", "UpdateTeam", ex.Message);
  3522. return 0;
  3523. }
  3524. }
  3525.  
  3526. #endregion
  3527.  
  3528. #region Delete Team calling from webservice
  3529. /// <summary>
  3530. /// Deleting Team calling from webservice
  3531. /// </summary>
  3532. /// <param name="_userId"></param>
  3533. /// <param name="_accountId"></param>
  3534. /// <param name="teamid"></param>
  3535. /// <param name="managerId"></param>
  3536. /// <param name="chk"></param>
  3537. /// <returns></returns>
  3538. public bool WSDeleteTeam(int _userId, int _accountId, int teamid, int managerId, out int chk)
  3539. {
  3540. bool result = false;
  3541. chk = 0;
  3542. try
  3543. {
  3544. var AccountId = _accountId;
  3545. var userId = _userId;
  3546. SqlParameter[] Param = new SqlParameter[4];
  3547. Param[0] = new SqlParameter("@TeamId", teamid);
  3548. Param[1] = new SqlParameter("@ManagerId", managerId);
  3549. Param[2] = new SqlParameter("@UpdateBy", userId);
  3550.  
  3551. Param[3] = new SqlParameter("@Chk", 0);
  3552. Param[3].Direction = ParameterDirection.Output;
  3553. string _procedurename = "tblTeamDelete";
  3554.  
  3555. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
  3556. chk = Convert.ToInt32(Param[3] != null ? Param[3].SqlValue.ToString() : "0");
  3557.  
  3558. if (chk > 0)
  3559. {
  3560. result = true;
  3561. }
  3562.  
  3563. return result;
  3564. }
  3565. catch (Exception ex)
  3566. {
  3567. Helper.ErrorLog(ex.InnerException, "Q_Setting", "deleteTeam", ex.Message);
  3568. return result;
  3569. }
  3570. }
  3571.  
  3572. #endregion
  3573.  
  3574. #region Delete Broker calling from webservice
  3575. /// <summary>
  3576. /// Delete Broker calling from webservice
  3577. /// </summary>
  3578. /// <param name="brokerid"></param>
  3579. /// <returns></returns>
  3580. public bool WSDeleteBroker(int _userId, int _accountId, int brokerid)
  3581. {
  3582. bool result = false;
  3583. try
  3584. {
  3585.  
  3586. int parentaccountId = _accountId;
  3587. var brokeruser = ctx.tblusers.Where(b => b.userid == brokerid && b.active && b.broker.HasValue && b.broker.Value == true).Select(b => b).FirstOrDefault();
  3588. if (brokeruser != null)
  3589. {
  3590. if (brokeruser != null)
  3591. {
  3592. brokeruser.active = false;
  3593. brokeruser.TeamId = 0;
  3594. ctx.SaveChanges();
  3595. result = true;
  3596. TeamMembersDeleteByMemberId(brokerid);
  3597. int userId = _userId;
  3598. WSAddAdminTeamMembers(_userId, _accountId, parentaccountId, parentaccountId, brokerid, userId, 2);
  3599. }
  3600. }
  3601.  
  3602. return result;
  3603. }
  3604. catch (Exception ex)
  3605. {
  3606. Helper.ErrorLog(ex.InnerException, "Q_Setting", "deleteBroker", ex.Message);
  3607. return result;
  3608. }
  3609. }
  3610.  
  3611. #endregion
  3612.  
  3613. #endregion webservice Setting methode
  3614.  
  3615. }
  3616. }
  3617.  
  3618. namespace Occfinance.Code
  3619. {
  3620. /*! Class is used to hold data access for scheduler
  3621. * \This classs provides data access facility for shceduler
  3622. * \All the fields are declared on top
  3623. * \This class may hold large number of methods implementation
  3624. */
  3625. public class Q_SchedulerAccess
  3626. {
  3627. #region Fields
  3628.  
  3629. public db_occfinance_5572Entities dbCtx = new db_occfinance_5572Entities();
  3630. public int taskStatus = 0;
  3631.  
  3632. #endregion Fields
  3633.  
  3634. #region Methods Implementation
  3635.  
  3636. public int TaskOperation(string financeIds, string rIds, DateTime? start)
  3637. {
  3638. try
  3639. {
  3640. SqlParameter[] parameters = new SqlParameter[3];
  3641. parameters[0] = new SqlParameter("@financeid", string.IsNullOrEmpty(financeIds) ? "" : financeIds);
  3642. parameters[1] = new SqlParameter("@ID", string.IsNullOrEmpty(rIds) ? "" : rIds);
  3643. parameters[2] = new SqlParameter("@followup", start ?? (object)DBNull.Value);
  3644. taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateFollowupDatefinance", parameters);
  3645. }
  3646. catch
  3647. {
  3648. }
  3649. return taskStatus;
  3650. }
  3651.  
  3652. public int TaskOperation(string recurrenceRule, string recurrenceException, int? taskId)
  3653. {
  3654. try
  3655. {
  3656. SqlParameter[] parameters = new SqlParameter[3];
  3657. parameters[0] = new SqlParameter("@taskid", taskId ?? 0);
  3658. parameters[1] = new SqlParameter("@recurrencerule", string.IsNullOrEmpty(recurrenceRule) ? "" : recurrenceRule);
  3659. parameters[2] = new SqlParameter("@recurrenceexception", string.IsNullOrEmpty(recurrenceException) ? "" : recurrenceException);
  3660. taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateRecurrenceRuleException", parameters);
  3661. }
  3662. catch
  3663. {
  3664. }
  3665. return taskStatus;
  3666. }
  3667.  
  3668. public int TaskOperation(string financeIds, string Ids, string followUp)
  3669. {
  3670. try
  3671. {
  3672. SqlParameter[] parameters = new SqlParameter[3];
  3673. parameters[0] = new SqlParameter("@ID", string.IsNullOrEmpty(Ids) ? "" : Ids);
  3674. parameters[1] = new SqlParameter("@financeid", string.IsNullOrEmpty(financeIds) ? "" : financeIds);
  3675. parameters[2] = new SqlParameter("@followup", Convert.ToDateTime(followUp));
  3676. taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateFollowupDateSavedEvent", parameters);
  3677. }
  3678. catch
  3679. {
  3680. }
  3681. return taskStatus;
  3682. }
  3683.  
  3684. public int TaskOperation(string financeIds, DateTime? followUp)
  3685. {
  3686. try
  3687. {
  3688. SqlParameter[] parameters = new SqlParameter[2];
  3689. parameters[0] = new SqlParameter("@ID", string.IsNullOrEmpty(financeIds) ? "" : financeIds);
  3690. parameters[1] = new SqlParameter("@followup", followUp ?? (object)DBNull.Value);
  3691. taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "UpdateFollowupDateSavedEvent", parameters);
  3692. }
  3693. catch
  3694. {
  3695. }
  3696. return taskStatus;
  3697. }
  3698.  
  3699. public int TaskOperation(int financeId, int Type, int Status, DateTime? startEvent, DateTime? endEvent, string recurrenceRule, int recurrenceId, string recurrenceException)
  3700. {
  3701. try
  3702. {
  3703. SqlParameter[] parameters = new SqlParameter[8];
  3704. parameters[0] = new SqlParameter("financeid", financeId);
  3705. parameters[1] = new SqlParameter("type", Type);
  3706. parameters[2] = new SqlParameter("status", Status);
  3707. parameters[3] = new SqlParameter("startevent", startEvent ?? (object)DBNull.Value);
  3708. parameters[4] = new SqlParameter("endevent", endEvent ?? (object)DBNull.Value);
  3709. parameters[5] = new SqlParameter("recurrencerule", string.IsNullOrEmpty(recurrenceRule) ? "" : recurrenceRule);
  3710. parameters[6] = new SqlParameter("recurrenceID", recurrenceId);
  3711. parameters[7] = new SqlParameter("recurrenceexception", string.IsNullOrEmpty(recurrenceException) ? "" : recurrenceException);
  3712.  
  3713. taskStatus = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "SaveEvents", parameters);
  3714. }
  3715. catch
  3716. {
  3717. }
  3718. return taskStatus;
  3719. }
  3720.  
  3721. public DataTable GetIcsFiles(int financeId)
  3722. {
  3723. DataTable icsFiles = null;
  3724. SqlParameter[] parameters = new SqlParameter[1];
  3725. parameters[0] = new SqlParameter("@financeid", financeId);
  3726. icsFiles = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetIcsFileForEvent_Update", parameters);
  3727. return icsFiles;
  3728. }
  3729.  
  3730. public DataTable GetIcsFilesForApplicationPage(int financeId)
  3731. {
  3732. DataTable icsFiles = null;
  3733. SqlParameter[] parameters = new SqlParameter[1];
  3734. parameters[0] = new SqlParameter("@financeid", financeId);
  3735.  
  3736. icsFiles = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetIcsFileForEventForApplicationPage_Update", parameters);
  3737. return icsFiles;
  3738. }
  3739.  
  3740. public DataTable GetCompleteIcsFile(string financeId)
  3741. {
  3742. DataTable icsFiles = null;
  3743. SqlParameter[] parameters = new SqlParameter[1];
  3744. parameters[0] = new SqlParameter("@financeid", financeId);
  3745. icsFiles = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetCompleteIcsFileForEvents_Update", parameters);
  3746. return icsFiles;
  3747. }
  3748.  
  3749. #endregion Methods Implementation
  3750. }
  3751. }
  3752.  
  3753. {
  3754. public class Q_ReportsDataForScreen
  3755. {
  3756.  
  3757. public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
  3758. System.Web.HttpContext con = HttpContext.Current;
  3759. #region [Methods For Big screen]
  3760. #region [All CLients]
  3761. public List<DashboardClients> FindDashboardClients(int parentuserid, int userId = 0)
  3762. {
  3763. List<DashboardClients> clients = new List<DashboardClients>();
  3764. try
  3765. {
  3766.  
  3767. SqlParameter[] Param = new SqlParameter[2];
  3768. Param[0] = new SqlParameter("@parentuserid", parentuserid);
  3769. Param[1] = new SqlParameter("@filteredaccount", null);
  3770.  
  3771. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAgentAndBranchListForScreen", Param);
  3772.  
  3773. clients = (from DataRow row in dt.Rows
  3774. select new DashboardClients
  3775. {
  3776. clientid = Convert.ToInt32(((row["accountid"] == DBNull.Value || row["accountid"] == null) ? "0" : row["accountid"]).ToString()),
  3777. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  3778. averageLeads = Convert.ToInt32(((row["average"] == DBNull.Value || row["average"] == null) ? "0" : row["average"]).ToString()),
  3779. countLeads = Convert.ToInt32(((row["total"] == DBNull.Value || row["total"] == null) ? "0" : row["total"]).ToString()),
  3780. thisMonthLeads = Convert.ToInt32(((row["last30days"] == DBNull.Value || row["last30days"] == null) ? "0" : row["last30days"]).ToString()),
  3781. lastLeadDate = (row["lastleaddate"] == DBNull.Value || row["lastleaddate"] == null) ? (DateTime?)null : Convert.ToDateTime(row["lastleaddate"]),
  3782.  
  3783. }).OrderBy(c => c.companyname).ToList();
  3784.  
  3785. return clients;
  3786. }
  3787. catch (Exception ex)
  3788. {
  3789. return clients;
  3790. }
  3791. }
  3792. #endregion
  3793. #region [All Brokers]
  3794. public List<DashboardBrokers> FindDashboardBrokers(int parentuserid, int userId = 0)
  3795. {
  3796. bool flag = false;
  3797. List<DashboardBrokers> clients = new List<DashboardBrokers>();
  3798. try
  3799. {
  3800.  
  3801. var userAccount = ctx.tblaccounts.Where(u => u.parent.HasValue && u.parent.Value == parentuserid).Select(u => u.accountid).ToList();
  3802. var account = ctx.tblusers.Where(u => u.broker.HasValue && u.broker.Value == true && u.account == parentuserid).Select(u => u).ToList();
  3803.  
  3804. SqlParameter[] Param = new SqlParameter[1];
  3805. Param[0] = new SqlParameter("@parentuserid", parentuserid);
  3806. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokerListForScreen", Param);
  3807.  
  3808. if (dt != null)
  3809. {
  3810. clients = (from DataRow row1 in dt.Rows
  3811. select new DashboardBrokers()
  3812. {
  3813. contactname = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString()),
  3814. Completion_Average = Convert.ToInt32(row1["exaverage"] == null ? "0" : row1["exaverage"].ToString()),
  3815. Completion_Total = Convert.ToInt32(row1["extotal"] == null ? "0" : row1["extotal"].ToString()),
  3816. Completion_Last30 = Convert.ToInt32(row1["exlast30days"] == null ? "0" : row1["exlast30days"].ToString()),
  3817. Completion_Change = Convert.ToInt32(row1["exChange"] == null ? "0" : row1["exChange"].ToString()),
  3818. Decision_in_principle_Average = Convert.ToInt32(row1["dipaverage"] == null ? "0" : row1["dipaverage"].ToString()),
  3819. Decision_in_principle_Total = Convert.ToInt32(row1["diptotal"] == null ? "0" : row1["diptotal"].ToString()),
  3820. Decision_in_principle_Last30 = Convert.ToInt32(row1["diplast30days"] == null ? "0" : row1["diplast30days"].ToString()),
  3821. Decision_in_principle_Change = Convert.ToInt32(row1["dipChange"] == null ? "0" : row1["dipChange"].ToString()),
  3822. ApplicationsSubmitted_Average = Convert.ToInt32(row1["appsubaverage"] == null ? "0" : row1["appsubaverage"].ToString()),
  3823. ApplicationsSubmitted_Total = Convert.ToInt32(row1["appsubtotal"] == null ? "0" : row1["appsubtotal"].ToString()),
  3824. ApplicationsSubmitted_Last30 = Convert.ToInt32(row1["appsublast30days"] == null ? "0" : row1["appsublast30days"].ToString()),
  3825. ApplicationsSubmitted_Change = Convert.ToInt32(row1["appChange"] == null ? "0" : row1["appChange"].ToString())
  3826.  
  3827. }).ToList();
  3828. }
  3829.  
  3830.  
  3831. return clients;
  3832. }
  3833. catch (Exception ex)
  3834. {
  3835. return clients;
  3836. }
  3837. }
  3838. #endregion
  3839. #region [Get Mortgage Report For Screen]
  3840. public DataSet GetMortgageCaseWrittenReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  3841. {
  3842. SqlParameter[] Param = new SqlParameter[9];
  3843. Param[0] = new SqlParameter("@CurrentUserId", userid);
  3844. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  3845. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  3846. if (!string.IsNullOrEmpty(Negotiator))
  3847. {
  3848. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  3849. Param[4] = new SqlParameter("@Company", Company.Trim());
  3850. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  3851. }
  3852. if (!string.IsNullOrWhiteSpace(brokers))
  3853. {
  3854. Param[6] = new SqlParameter("@BrokerId", brokers);
  3855. }
  3856. if (!string.IsNullOrWhiteSpace(type))
  3857. {
  3858. Param[7] = new SqlParameter("@MortgageType", type);
  3859. }
  3860.  
  3861. Param[8] = new SqlParameter("@productTypeID", productTypeID);
  3862.  
  3863. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCaseWrittenForScreen_Update", Param);
  3864. return ds;
  3865.  
  3866. }
  3867. #endregion [Get Mortgage Report For Screen]
  3868. #region [Get Mortgage Completed Report For Screen]
  3869.  
  3870. public DataSet GetMortgageCompletedReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  3871. {
  3872. SqlParameter[] Param = new SqlParameter[9];
  3873. Param[0] = new SqlParameter("@CurrentUserId", userid);
  3874. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  3875. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  3876. if (!string.IsNullOrEmpty(Negotiator))
  3877. {
  3878. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  3879. Param[4] = new SqlParameter("@Company", Company.Trim());
  3880. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  3881. }
  3882. if (!string.IsNullOrWhiteSpace(brokers))
  3883. {
  3884. Param[6] = new SqlParameter("@BrokerId", brokers);
  3885. }
  3886. if (!string.IsNullOrWhiteSpace(type))
  3887. {
  3888. Param[7] = new SqlParameter("@MortgageType", type);
  3889. }
  3890.  
  3891. Param[8] = new SqlParameter("@productTypeID", productTypeID);
  3892.  
  3893. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetMortgageCompletedReportForScreen_Update", Param);
  3894. return ds;
  3895. }
  3896.  
  3897. #endregion [Get Mortgage Completed Report For Screen]
  3898. #region [Get Insurance Written Report For screen]
  3899.  
  3900. /// <summary>
  3901. /// method for InsuranceCaseWrittenForScreen
  3902. /// </summary>
  3903. /// <param name="type"></param>
  3904. /// <param name="fromdate"></param>
  3905. /// <param name="todate"></param>
  3906. /// <param name="userid"></param>
  3907. /// <param name="brokerId"></param>
  3908. /// <param name="Negotiator"></param>
  3909. /// <param name="brokers"></param>
  3910. /// <param name="Company"></param>
  3911. /// <param name="Branches"></param>
  3912. /// <param name="productTypeID"></param>
  3913. /// <returns></returns>
  3914. public DataSet GetInsuranceCaseWrittenReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  3915. {
  3916. SqlParameter[] Param = new SqlParameter[9];
  3917. Param[0] = new SqlParameter("@CurrentUserId", userid);
  3918. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  3919. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  3920. if (!string.IsNullOrEmpty(Negotiator))
  3921. {
  3922. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  3923. Param[4] = new SqlParameter("@Company", Company.Trim());
  3924. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  3925. }
  3926. if (!string.IsNullOrWhiteSpace(brokers))
  3927. {
  3928. Param[6] = new SqlParameter("@BrokerId", brokers);
  3929. }
  3930. if (!string.IsNullOrWhiteSpace(type))
  3931. {
  3932. Param[7] = new SqlParameter("@InsuranceType", type);
  3933. }
  3934. Param[8] = new SqlParameter("@productTypeID", productTypeID);
  3935.  
  3936. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCaseWrittenForScreen_Update", Param);
  3937. return ds;
  3938. }
  3939.  
  3940. #endregion [Get Insurance Written Report For screen]
  3941. #region [Get insurance Completed Report for Screen]
  3942. public DataSet GetInsuranceCompletedReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  3943. {
  3944. SqlParameter[] Param = new SqlParameter[9];
  3945. Param[0] = new SqlParameter("@CurrentUserId", userid);
  3946. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  3947. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  3948. if (!string.IsNullOrEmpty(Negotiator))
  3949. {
  3950. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  3951. Param[4] = new SqlParameter("@Company", Company.Trim());
  3952. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  3953. }
  3954. if (!string.IsNullOrWhiteSpace(brokers))
  3955. {
  3956. Param[6] = new SqlParameter("@BrokerId", brokers);
  3957. }
  3958. if (!string.IsNullOrWhiteSpace(type))
  3959. {
  3960. Param[7] = new SqlParameter("@InsuranceType", type);
  3961. }
  3962. Param[8] = new SqlParameter("@productTypeID", productTypeID);
  3963.  
  3964. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetInsuranceCompletedReportForScreen_Update", Param);
  3965. return ds;
  3966. }
  3967. #endregion [Get insurance Completed Report for Screen]
  3968. #region [Get Total Writeen Report For Screen]
  3969. public DataSet GetTotalWrittenReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  3970. {
  3971. SqlParameter[] Param = new SqlParameter[7];
  3972. Param[0] = new SqlParameter("@CurrentUserId", userid);
  3973. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  3974. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  3975. if (!string.IsNullOrEmpty(Negotiator))
  3976. {
  3977. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  3978. Param[4] = new SqlParameter("@Company", Company.Trim());
  3979. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  3980. }
  3981. if (!string.IsNullOrWhiteSpace(brokers))
  3982. {
  3983. Param[6] = new SqlParameter("@BrokerId", brokers);
  3984. }
  3985.  
  3986.  
  3987. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWrittenForScreen_Update", Param);
  3988. return ds;
  3989. }
  3990. #endregion [Get Total Completed Report For Screen]
  3991. #region [Get Total Completed Report For Screen]
  3992. public DataSet GetTotalWrittenReportCompleted(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  3993. {
  3994. SqlParameter[] Param = new SqlParameter[7];
  3995. Param[0] = new SqlParameter("@CurrentUserId", userid);
  3996. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  3997. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  3998. if (!string.IsNullOrEmpty(Negotiator))
  3999. {
  4000. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  4001. Param[4] = new SqlParameter("@Company", Company.Trim());
  4002. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  4003. }
  4004. if (!string.IsNullOrWhiteSpace(brokers))
  4005. {
  4006. Param[6] = new SqlParameter("@BrokerId", brokers);
  4007. }
  4008.  
  4009.  
  4010. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWrittenCompleted_Update", Param);
  4011. return ds;
  4012. }
  4013. #endregion [Get Total Written Report For Screen]
  4014. #region [Get Total Writeen Month For Screen]
  4015. public DataSet GetTotalWrittenMonthReportForScreen(string type, DateTime fromdate, DateTime todate, int userid, int brokerId = 0, string Negotiator = "", string brokers = "", string Company = "", string Branches = "", int productTypeID = 0)
  4016. {
  4017. SqlParameter[] Param = new SqlParameter[7];
  4018. Param[0] = new SqlParameter("@CurrentUserId", userid);
  4019. Param[1] = new SqlParameter("@FromDate", fromdate.ToString("dd/MMM/yyyy"));
  4020. Param[2] = new SqlParameter("@ToDate", todate.ToString("dd/MMM/yyyy"));
  4021. if (!string.IsNullOrEmpty(Negotiator))
  4022. {
  4023. Param[3] = new SqlParameter("@Negotiator", Negotiator.Trim());
  4024. Param[4] = new SqlParameter("@Company", Company.Trim());
  4025. Param[5] = new SqlParameter("@Branches", Branches.Trim());
  4026. }
  4027. if (!string.IsNullOrWhiteSpace(brokers))
  4028. {
  4029. Param[6] = new SqlParameter("@BrokerId", brokers);
  4030. }
  4031.  
  4032.  
  4033. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetTotalWrittenMonthForScreen_Update", Param);
  4034. return ds;
  4035. }
  4036. #endregion [Get Total Written Month For Screen]
  4037. #region [Condition For Animation]
  4038. public BrokerDetailForScreen ConditionForProductSubmitted()
  4039. {
  4040. BrokerDetailForScreen submittedBrokerDetail = null;// = new SubmittedBrokerDetailForScreen();
  4041. try
  4042. {
  4043. SqlParameter[] Param = new SqlParameter[0];
  4044. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "SubmittedConditionForScreen", Param);
  4045. submittedBrokerDetail = (from System.Data.DataRow row in ds.Tables[0].Rows
  4046. select new BrokerDetailForScreen
  4047. {
  4048. brokerId = Convert.ToInt32((row["brokerId"] == DBNull.Value || row["brokerId"] == null) ? "" : row["brokerId"]),
  4049. brokerName = ((row["brokerName"] == DBNull.Value || row["brokerName"] == null) ? "" : row["brokerName"]).ToString(),
  4050. commision = (decimal)((row["commision"] == DBNull.Value || row["commision"] == null) ? (decimal)0 : Convert.ToDecimal(row["commision"])),
  4051. dealSize = (decimal)((row["dealSize"] == DBNull.Value || row["dealSize"] == null) ? (decimal)0 : Convert.ToDecimal(row["dealSize"])),
  4052. financeId = Convert.ToInt32((row["financeId"] == DBNull.Value || row["financeId"] == null) ? "0" : row["financeId"]),
  4053. type = Convert.ToInt32((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]),
  4054. }).FirstOrDefault();
  4055. }
  4056. catch
  4057. {
  4058.  
  4059. }
  4060. return submittedBrokerDetail;
  4061. }
  4062.  
  4063. public BrokerDetailForScreen ConditionForProductCompleted()
  4064. {
  4065. BrokerDetailForScreen completedBrokerDetail = null;
  4066. try
  4067. {
  4068. SqlParameter[] Param = new SqlParameter[0];
  4069. DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "CompletedConditionForScreen", Param);
  4070. completedBrokerDetail = (from System.Data.DataRow row in ds.Tables[0].Rows
  4071. select new BrokerDetailForScreen
  4072. {
  4073. brokerId = Convert.ToInt32((row["brokerId"] == DBNull.Value || row["brokerId"] == null) ? "" : row["brokerId"]),
  4074. brokerName = ((row["brokerName"] == DBNull.Value || row["brokerName"] == null) ? "" : row["brokerName"]).ToString(),
  4075. commision = (decimal)((row["commision"] == DBNull.Value || row["commision"] == null) ? (decimal)0 : Convert.ToDecimal(row["commision"])),
  4076. dealSize = (decimal)((row["dealSize"] == DBNull.Value || row["dealSize"] == null) ? (decimal)0 : Convert.ToDecimal(row["dealSize"])),
  4077. financeId = Convert.ToInt32((row["financeId"] == DBNull.Value || row["financeId"] == null) ? "0" : row["financeId"]),
  4078. type = Convert.ToInt32((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]),
  4079. }).FirstOrDefault();
  4080. }
  4081. catch
  4082. {
  4083.  
  4084. }
  4085. return completedBrokerDetail;
  4086. }
  4087. public BrokerDetailForScreen ConditionForAnimation(out int animationType)
  4088. {
  4089.  
  4090. animationType = 0;
  4091. var submittedBrokerDetail = ConditionForProductSubmitted();
  4092. var completedBrokerDetail = ConditionForProductCompleted();
  4093. BrokerDetailForScreen brokerDetail = null;
  4094. try
  4095. {
  4096. if (submittedBrokerDetail != null && completedBrokerDetail == null)
  4097. {
  4098. if (submittedBrokerDetail.type == 1 && submittedBrokerDetail.commision >= 1500)
  4099. {
  4100. animationType = 1; // fireworks
  4101.  
  4102. }
  4103. else if (submittedBrokerDetail.type == 1 && submittedBrokerDetail.commision < 1500)
  4104. {
  4105. animationType = 2; //champagne
  4106. }
  4107. else if ((submittedBrokerDetail.type == 2 || submittedBrokerDetail.type == 3) && submittedBrokerDetail.commision >= 1000)
  4108. {
  4109. animationType = 1; // fireworks
  4110.  
  4111. }
  4112. else if ((submittedBrokerDetail.type == 2 || submittedBrokerDetail.type == 3) && submittedBrokerDetail.commision < 1000)
  4113. {
  4114. animationType = 2; // champagne
  4115.  
  4116. }
  4117. brokerDetail = submittedBrokerDetail;
  4118. SaveRecordForBigScreen(brokerDetail, 1);
  4119. }
  4120. else if (submittedBrokerDetail == null && completedBrokerDetail != null)
  4121. {
  4122. animationType = 3; //stack of money
  4123. brokerDetail = completedBrokerDetail;
  4124. SaveRecordForBigScreen(brokerDetail, 2);
  4125. }
  4126. else if (submittedBrokerDetail != null && completedBrokerDetail != null)
  4127. {
  4128. animationType = 3; // stack of money
  4129. brokerDetail = completedBrokerDetail;
  4130. SaveRecordForBigScreen(brokerDetail, 2);
  4131. }
  4132. else
  4133. {
  4134. animationType = 0;
  4135. brokerDetail = null;
  4136.  
  4137. }
  4138. }
  4139. catch
  4140. {
  4141.  
  4142. }
  4143. return brokerDetail;
  4144.  
  4145. }
  4146. #endregion [Condition For Animation]
  4147.  
  4148. #region [Saving record in Bigscreen Table for maintain history]
  4149. public int SaveRecordForBigScreen(BrokerDetailForScreen detail, int status)
  4150. {
  4151. int result = 0;
  4152. try
  4153. {
  4154. if (detail != null)
  4155. {
  4156. tblBigScreenRecords bigScreen = new tblBigScreenRecords();
  4157. bigScreen.financeId = detail.financeId;
  4158. bigScreen.status = status;
  4159. bigScreen.createdDate = DateTime.Now;
  4160. ctx.tblBigScreenRecords.Add(bigScreen);
  4161. result = ctx.SaveChanges();
  4162. }
  4163. }
  4164. catch
  4165. {
  4166.  
  4167. }
  4168. return result;
  4169.  
  4170. }
  4171. #endregion [Saving record in Bigscreen Table for maintain history]
  4172.  
  4173. #region[Getting Clients for dropdown]
  4174. public List<Clients> FindClients(int parentuserid, int UserId = 0)
  4175. {
  4176. List<Clients> clients = new List<Clients>();
  4177. try
  4178. {
  4179.  
  4180. //Check User Type
  4181. Q_Application _obj = new Q_Application();
  4182. int teamId = 0;
  4183. string brokersIds = "";
  4184. int _userType = 0;
  4185. int _accountId = 0;
  4186. _userType = _obj.CheckUserType(UserId, out teamId, out _accountId, out brokersIds);
  4187. //**************************************
  4188.  
  4189. SqlParameter[] Param = new SqlParameter[2];
  4190. Param[0] = new SqlParameter("@UserType", _userType);
  4191. Param[1] = new SqlParameter("@ParentId", parentuserid); ;
  4192. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllClientsForScreen", Param);
  4193.  
  4194. clients = (from DataRow row in dt.Rows
  4195. select new Clients
  4196. {
  4197. clientid = Convert.ToInt32(((row["accountid"] == DBNull.Value || row["accountid"] == null) ? "0" : row["accountid"]).ToString()),
  4198. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  4199. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  4200. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  4201. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  4202. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  4203. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  4204. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  4205. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString())
  4206. }).ToList();
  4207. return clients;
  4208. }
  4209. catch (Exception ex)
  4210. {
  4211. return clients;
  4212. }
  4213. }
  4214. #endregion [Getiing clients for dropdown]
  4215. #region[Getting Brokers For dropdown]
  4216. public List<Clients> FindBrokerForLoggedInUserWithUserId(int accid, int userid)
  4217. {
  4218. bool flag = false;
  4219. List<Clients> brokers = new List<Clients>();
  4220. Q_Application _obj = new Q_Application();
  4221.  
  4222. try
  4223. {
  4224.  
  4225. int teamId = 0;
  4226. string brokersIds = "";
  4227. int _userType = 0;
  4228. int _accountId = 0;
  4229. _userType = _obj.CheckUserType(userid, out teamId, out _accountId, out brokersIds);
  4230.  
  4231. //Updated With Store Procedure For Navigation Delay ********* 7/7/2014 ********************************************
  4232.  
  4233. var _Id = 0;
  4234.  
  4235. if (_userType == 1)
  4236. _Id = _accountId;
  4237. else if (_userType == 2)
  4238. _Id = teamId;
  4239. else if (_userType == 3)
  4240. _Id = userid;
  4241. else if (_userType == 4)
  4242. {
  4243. int account = ctx.tblaccounts.Where(u => u.accountid == userid).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
  4244. _Id = account;
  4245. }
  4246.  
  4247. SqlParameter[] Param = new SqlParameter[2];
  4248. Param[0] = new SqlParameter("@UserType", _userType);
  4249. Param[1] = new SqlParameter("@ID", _Id);
  4250. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "FindBrokerForLoggedInUserWithUserIdForScreen", Param);
  4251.  
  4252. brokers = (from DataRow row in dt.Rows
  4253. select new Clients
  4254. {
  4255. clientid = Convert.ToInt32(((row["clientid"] == DBNull.Value || row["clientid"] == null) ? "0" : row["clientid"]).ToString()),
  4256. parent = Convert.ToInt32(((row["parent"] == DBNull.Value || row["parent"] == null) ? "0" : row["parent"]).ToString()),
  4257. companyname = ((row["companyname"] == DBNull.Value || row["companyname"] == null) ? " " : row["companyname"]).ToString(),
  4258. TeamName = ((row["TeamName"] == DBNull.Value || row["TeamName"] == null) ? " " : row["TeamName"]).ToString(),
  4259. TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
  4260. affiliateid = ((row["affiliateid"] == DBNull.Value || row["affiliateid"] == null) ? " " : row["affiliateid"]).ToString(),
  4261. telephone = ((row["telephone"] == DBNull.Value || row["telephone"] == null) ? " " : row["telephone"]).ToString(),
  4262. email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
  4263. contactname = ((row["contactname"] == DBNull.Value || row["contactname"] == null) ? " " : row["contactname"]).ToString(),
  4264. address = Convert.ToInt32(((row["address"] == DBNull.Value || row["address"] == null) ? "0" : row["address"]).ToString()),
  4265. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  4266. AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
  4267. countLeads = Convert.ToInt32(((row["countLeads"] == DBNull.Value || row["countLeads"] == null) ? "0" : row["countLeads"]).ToString()),
  4268. }).ToList();
  4269.  
  4270. //**********************************************************************************
  4271.  
  4272. return brokers;
  4273. }
  4274. catch (Exception)
  4275. {
  4276. return brokers;
  4277. }
  4278. }
  4279. #endregion[Getting Brokers for dropdown]
  4280.  
  4281. #region [Get Monthly lead flow]
  4282. public List<MonthlyLeadFlowBrokers> GetMonthlyLeadReportForScreen(int parentuserid, int userId = 0)
  4283. {
  4284.  
  4285. List<MonthlyLeadFlowBrokers> brokers = new List<MonthlyLeadFlowBrokers>();
  4286. try
  4287. {
  4288. SqlParameter[] Param = new SqlParameter[2];
  4289. Param[0] = new SqlParameter("@parentuserid", parentuserid);
  4290. Param[1] = new SqlParameter("@filteredaccount", null);
  4291. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetMonthlyLeadFlowForScreen", Param);
  4292.  
  4293. if (dt != null)
  4294. {
  4295. brokers = (from DataRow row1 in dt.Rows
  4296. select new MonthlyLeadFlowBrokers()
  4297. {
  4298. BrokerName = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString()),
  4299. Rank = Convert.ToInt32(row1["Ranking"] == null ? "0" : row1["Ranking"].ToString()),
  4300. BrokerId = Convert.ToInt32(row1["userid"] == null ? "0" : row1["userid"].ToString()),
  4301. Total = Convert.ToInt32(row1["total"] == null ? "0" : row1["total"].ToString()),
  4302.  
  4303. }).ToList();
  4304. }
  4305.  
  4306.  
  4307. return brokers;
  4308. }
  4309. catch (Exception ex)
  4310. {
  4311. return brokers;
  4312. }
  4313. }
  4314. #endregion [Get Monthly lead flow]
  4315.  
  4316.  
  4317. #endregion [methods for big screen]
  4318.  
  4319.  
  4320.  
  4321. }
  4322. }
Add Comment
Please, Sign In to add comment