Guest User

Untitled

a guest
Nov 16th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.96 KB | None | 0 0
  1. Array values = Enum.GetValues(typeof(Occfinance.Helpers.VisitFrequencyEnum));
  2. List<WSSelectListItem> VisitFrequencyList = new List<WSSelectListItem>(values.Length);
  3. foreach (var i in values)
  4. {
  5. VisitFrequencyList.Add(new WSSelectListItem
  6. {
  7. Text = ((VisitFrequencyEnum)i).GetEnumDescription(),
  8. Value = ((int)i).ToString()
  9. });
  10. }
  11.  
  12.  
  13. model.VisitFrequencyList = VisitFrequencyList;
  14. IEnumerable<DayListEnum> dayListEnum = Enum.GetValues(typeof(DayListEnum)).Cast<DayListEnum>();
  15. model.DayList = (from day in dayListEnum select new WSSelectListItem { Text = day.ToString(), Value = ((int)day).ToString() }).ToList();
  16.  
  17. string[] _allNamesparents = hdnnamearrayparents.Split(',');
  18. string allNamesparents = "";
  19. allNamesparents = QReports.GetSelectedCompaniesWithBrokerByIds(_allNamesparents);
  20.  
  21.  
  22. string[] _allNames = QReports.GetNegotiatorsNameByIds(NegotiatorIds);
  23. string allNames = "";
  24. foreach (var name in _allNames)
  25. {
  26. if (!string.IsNullOrEmpty(name))
  27. allNames += System.Text.RegularExpressions.Regex.Replace(name, "[^a-zA-Z0-9]+", "", System.Text.RegularExpressions.RegexOptions.Compiled).Trim() + ",";
  28. }
  29. if (string.IsNullOrWhiteSpace(hdnnamearraybrokerNames))
  30. {
  31. if (!string.IsNullOrEmpty(allNames))
  32. model.Clientname = allNamesparents;
  33. else
  34. model.Clientname = "All";
  35. }
  36. else
  37. {
  38. if (!string.IsNullOrWhiteSpace(hdnnamearraybrokerNames))
  39. {
  40. if (string.IsNullOrEmpty(allNamesparents))
  41. model.Clientname = "Brokers: " + hdnnamearraybrokerNames;// name.brokername;
  42. else
  43. model.Clientname = allNamesparents;
  44. }
  45. }
  46.  
  47. if (accountId > 0)
  48. {
  49. //Clinets
  50. WSSelectListItem defaultentry = new WSSelectListItem();
  51. defaultentry.Text = "select..";
  52. defaultentry.Value = "0";
  53. defaultentry.Selected = true;
  54. List<WSSelectListItem> items = new List<WSSelectListItem>();
  55.  
  56. model.BrokersWithTeams = QSettings.GetBrokersWithTeams(userId);
  57. List<Clients> bitems = QSettings.FindBrokerForLoggedInUserWithUserId(accountId, userId);
  58. var bcompanyitems = (from names in bitems
  59. select new
  60. {
  61. companyname = names.companyname,
  62. clientid = names.clientid
  63. }).Distinct().ToList();
  64. companyitems = bcompanyitems.Select(r => new WSSelectListItem() { Value = r.companyname, Text = r.companyname }).ToList();
  65. model.CompanyData = companyitems;
  66. model.BrokderBag = bitems;
  67. model.BrokerSelectedName = hdnnamearraybroker;
  68. model.ClientsNames = allNames.TrimEnd(',');
  69. List<Clients> cItems = QClient.FindClients(accountId, userId).OrderBy(c => c.companyname).ToList();
  70. items = (from Clients in cItems
  71. select new WSSelectListItem
  72. {
  73. Text = Clients.companyname + "(" + Clients.countLeads + ")",
  74. Value = Clients.clientid.ToString()
  75. }).ToList();
  76. items.Insert(0, defaultentry);
  77. model.ClientData = items;
  78. List<WSSelectListItem> negitems = new List<WSSelectListItem>();
  79. negitems.Insert(0, defaultentry);
  80. model.negotiationReport = negitems;
  81. var brokers = "";
  82. int adminaccId = 0;
  83. if (QApplication.IsCreatedAdminUser(accountId, userId, out adminaccId, out brokers))
  84. {
  85. if (string.IsNullOrWhiteSpace(hdnnamearraybroker))
  86. hdnnamearraybroker = brokers;
  87. userId = adminaccId;
  88. }
  89.  
  90.  
  91. public enum UserType
  92. {
  93. [Description("Admin")]
  94. Admin = 1,
  95. [Description("Manager")]
  96. Manager,
  97. [Description("Broker")]
  98. Broker,
  99. [Description("General User")]
  100. GeneralUser
  101. }
  102.  
  103. _userType = _obj.CheckUserType(userId, out teamId, out _accountId, out brokersIds);
  104.  
  105. if ((_userType == (int)UserType.Manager || _userType == (int)UserType.Broker) && string.IsNullOrWhiteSpace(hdnnamearraybroker))
  106. hdnnamearraybroker = Convert.ToString(userId);
  107.  
  108.  
  109.  
  110.  
  111. [WebService(Namespace = "http://tempuri.org/")]
  112. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  113. // [System.ComponentModel.ToolboxItem(false)]
  114. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  115. [System.Web.Script.Services.ScriptService]
  116. public class WebService
  117. {
  118.  
  119. #region [Constructor & Declarations]
  120.  
  121. public WebService()
  122. {
  123. appService = new ApplicationService();
  124.  
  125. clientService = new ClientService();
  126. }
  127.  
  128. public UserCredentials Credential;
  129. Login objLogin = new Login();
  130. Common objCommonClass = new Common();
  131. Lead objLead = new Lead();
  132. Client.Client objClient = new Client.Client();
  133. Dashboard objDashboard = new Dashboard();
  134. Company objCompany = new Company();
  135. ForgetPwd objForgetPwd = new ForgetPwd();
  136. ApplicationService appService = null;
  137. ClientService clientService = null;
  138. EquityService equityService = new EquityService();
  139. FactFindService factFindService = new FactFindService();
  140. IntroducerService objIntroducerService = new IntroducerService();
  141. ReportsService reportsService = new ReportsService();
  142. SettingService settingService = new SettingService();
  143. PipelineService pipelineService = new PipelineService();
  144. AccountVisitsService accountvisitService = new AccountVisitsService();
  145. #endregion [Constructor & Declarations]
  146.  
  147. #region [Authentication]
  148.  
  149. /// <summary>
  150. /// Authenticate user
  151. /// </summary>
  152. /// <returns></returns>
  153. private bool Authenticate()
  154. {
  155. if (Credential != null)
  156. {
  157. if (Credential.userName == "demoac@test.com" && Credential.password == "demooccpwd")
  158. return true;
  159. else
  160. return false;
  161. }
  162. else
  163. return false;
  164. }
  165.  
  166. #endregion [Authentication]
  167.  
  168. #region Login
  169. [WebMethod]
  170. [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  171. public WsLogin login(string username, string password)
  172. {
  173.  
  174. WsLogin model = new WsLogin();
  175.  
  176. int userId, accountid, userType;
  177. string profilePic = "", brokerName = "", usertypename = "", companyname = "";
  178. bool IsAuthorized = objLogin.AuthenticateUser(username, password, out userId, out accountid, out userType, out profilePic, out brokerName, out usertypename, out companyname);
  179.  
  180. model.message = IsAuthorized ? "Successful" : "Provide valid username or password";
  181. model.user_id = userId.ToString();
  182. model.account_id = accountid.ToString();
  183. model.status = IsAuthorized ? "true" : "false";
  184.  
  185. model.productType = userType.ToString();
  186.  
  187. model.ProfilePic = profilePic;
  188. model.UserName = brokerName;
  189. model.UserTypeName = usertypename;
  190. model.CompanyName = companyname;
  191. return model;
  192. }
  193.  
  194.  
  195. #endregion
  196.  
  197. #region Forget Pwd
  198. [WebMethod]
  199. [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  200. // [SoapHeader("Credential", Required = true)]
  201. public WsStatusMessage forgotpassword(string email)
  202. {
  203. WsStatusMessage model = new WsStatusMessage();
  204. int status = objForgetPwd.ResetPassword(email);
  205.  
  206. model.message = status == 1 ? "Successful" : email.IsEmail() ? "Email does not exist" : "Provide valid email id";
  207. model.status = status == 1 ? "true" : "false";
  208.  
  209. return model;
  210. }
  211. #endregion
  212. }
  213.  
  214. [WebService(Namespace = "http://tempuri.org/")]
  215. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  216. [System.ComponentModel.ToolboxItem(false)]
  217. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  218. [System.Web.Script.Services.ScriptService]
  219. public class UserCredentials : System.Web.Services.Protocols.SoapHeader
  220. {
  221. public string userName { get; set; }
  222. public string password { get; set; }
  223. }
  224.  
  225. public class BasicAuthHttpModule : IHttpModule
  226. {
  227. public void Dispose()
  228. {
  229. }
  230.  
  231. public void Init(HttpApplication application)
  232. {
  233. application.AuthenticateRequest += new
  234. EventHandler(this.OnAuthenticateRequest);
  235. application.EndRequest += new
  236. EventHandler(this.OnEndRequest);
  237. }
  238.  
  239. public void OnAuthenticateRequest(object source, EventArgs
  240. eventArgs)
  241. {
  242. HttpApplication app = (HttpApplication)source;
  243. if (!app.Context.Request.Url.OriginalString.Contains(".asmx"))
  244. {
  245. return;
  246. }
  247. string authHeader = app.Request.Headers["Authorization"];
  248. if (!string.IsNullOrEmpty(authHeader))
  249. {
  250. string authStr = app.Request.Headers["Authorization"];
  251.  
  252. if (authStr == null || authStr.Length == 0)
  253. {
  254. return;
  255. }
  256. authStr = authStr.Trim();
  257. if (authStr.IndexOf("Basic", 0) != 0)
  258. {
  259. return;
  260. }
  261. authStr = authStr.Trim();
  262. string encodedCredentials = authStr.Substring(6);
  263. byte[] decodedBytes =
  264. Convert.FromBase64String(encodedCredentials);
  265. string s = new ASCIIEncoding().GetString(decodedBytes);
  266.  
  267. string[] userPass = s.Split(new char[] { ':' });
  268. string username = userPass[0];
  269. string password = userPass[1];
  270.  
  271. if (!Validate(username, password))
  272. {
  273. DenyAccess(app);
  274. return;
  275. }
  276. }
  277. else
  278. {
  279. app.Response.StatusCode = 401;
  280. app.Response.End();
  281. }
  282. }
  283.  
  284. public bool Validate(string username, string password)
  285. {
  286.  
  287. if (username == "demoac@test.com" && password == "demooccpwd")
  288. return true;
  289. else
  290. return false;
  291. }
  292. public void OnEndRequest(object source, EventArgs eventArgs)
  293. {
  294. if (HttpContext.Current.Response.StatusCode == 401)
  295. {
  296. HttpContext context = HttpContext.Current;
  297. context.Response.StatusCode = 401;
  298. context.Response.AddHeader("WWW-Authenticate", "Basic Realm");
  299. }
  300. }
  301.  
  302. private void DenyAccess(HttpApplication app)
  303. {
  304. app.Response.StatusCode = 401;
  305. app.Response.StatusDescription = "Access Denied";
  306. app.Response.Write("401 Access Denied");
  307. app.CompleteRequest();
  308. }
  309. }
  310.  
  311. public bool AuthenticateUser(string username, string password, out int userId)
  312. {
  313. bool result = false;
  314. userId = 0;
  315. try
  316. {
  317. 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
  318. if (!result)
  319. {
  320. 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
  321. if (!result)
  322. {
  323. 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
  324. if (!result)
  325. {
  326. 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
  327. }
  328. }
  329. }
  330.  
  331. if (result)
  332. {
  333. userId = ctx.tblusers.Where(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true).Select(u => u.userid).FirstOrDefault();
  334.  
  335. }
  336. return result;
  337. }
  338. catch
  339. { }
  340. return result;
  341. }
  342. #endregion
  343.  
  344. public AtendanceStatus GetAvailableHoursDays(int userId, DateTime activityDate, int year)
  345. {
  346. AtendanceStatus _AtendanceStatus = new AtendanceStatus();
  347. SqlParameter[] Param = new SqlParameter[3];
  348. Param[0] = new SqlParameter("@UserId", userId);
  349. Param[1] = new SqlParameter("@ActivityDate", activityDate);
  350. Param[2] = new SqlParameter("@Year", year);
  351.  
  352. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAvailableHoursDays", Param);
  353. try
  354. {
  355. var d = (from DataRow row in dt.Rows
  356. select new AtendanceStatus
  357. {
  358. AllowedDays = Convert.ToDecimal(((row["AllowedDays"] == DBNull.Value || row["AllowedDays"] == null) ? "0" : row["AllowedDays"])),
  359. AllowedHours = Convert.ToDecimal(((row["AllowedHours"] == DBNull.Value || row["AllowedHours"] == null) ? "0" : row["AllowedHours"])),
  360. UsedDays = Convert.ToDecimal(((row["UsedDays"] == DBNull.Value || row["UsedDays"] == null) ? "0" : row["UsedDays"])),
  361. UsedHours = Convert.ToDecimal(((row["UsedHours"] == DBNull.Value || row["UsedHours"] == null) ? "0" : row["UsedHours"])),
  362. }).ToList();
  363.  
  364. if (d != null && d.Count() > 0)
  365. _AtendanceStatus = d[0];
  366. }
  367. catch
  368. {
  369. }
  370. return _AtendanceStatus ?? new AtendanceStatus();
  371. }
  372.  
  373. public int GetTotalDays(int acountId)
  374. {
  375. int DefaultId = 1;
  376. try
  377. {
  378. SqlParameter[] Param = new SqlParameter[2];
  379. Param[0] = new SqlParameter("@AcountId", acountId);
  380. Param[1] = new SqlParameter("@DefaultId", 0);
  381. Param[1].Direction = ParameterDirection.Output;
  382.  
  383. SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "GetDefaultSettings", Param);
  384.  
  385. DefaultId = Convert.ToInt32(Param[1] != null ? Param[1].SqlValue.ToString() : "1"); // return userid
  386. }
  387. catch
  388. {
  389. }
  390.  
  391. return DefaultId;
  392.  
  393. }
  394.  
  395. public void GetSetPermission(int loginUserId)
  396. {
  397. try
  398. {
  399. if (SessionWrapper.PermissionSession == null)
  400. {
  401. PermissionSession objS = new PermissionSession();
  402. SessionWrapper.PermissionSession = objS;
  403. }
  404. SessionWrapper.PermissionSession.UserId = loginUserId;
  405.  
  406. Q_Application obj = new Q_Application();
  407. if (obj.CheckIsSuperAdmin(loginUserId) == 1)
  408. {
  409. SessionWrapper.PermissionSession.IsFullPermission = true;
  410. SessionWrapper.PermissionSession.IsViewAllData = true;
  411. SessionWrapper.PermissionSession.IsUpdateAllData = true;
  412. SessionWrapper.PermissionSession.IsPrintAllData = true;
  413. }
  414. else
  415. {
  416. SessionWrapper.PermissionSession.IsFullPermission = false;
  417.  
  418. List<UserPermissionModel> _permissions = new List<UserPermissionModel>();
  419. SqlParameter[] Param = new SqlParameter[1];
  420. Param[0] = new SqlParameter("@UserId", loginUserId);
  421. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "tblUserPermissionGetByUserId", Param);
  422. _permissions = (from DataRow row in dt.Rows
  423. select new UserPermissionModel
  424. {
  425. userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
  426. PermissionId = Convert.ToInt32(((row["PermissionId"] == DBNull.Value || row["PermissionId"] == null) ? "0" : row["PermissionId"]).ToString()),
  427. PermissionNames = Convert.ToString((row["PermissionName"] == DBNull.Value || row["PermissionName"] == null) ? "" : row["PermissionName"]),
  428.  
  429. }).ToList();
  430.  
  431. if (_permissions.Any(c => c.userid == loginUserId && c.PermissionId == (int)Permission.ViewData))
  432. {
  433.  
  434. SessionWrapper.PermissionSession.IsViewAllData = true;
  435. }
  436. else
  437. {
  438. SessionWrapper.PermissionSession.IsViewAllData = false;
  439. }
  440.  
  441. if (_permissions.Any(c => c.userid == loginUserId && c.PermissionId == (int)Permission.UpdateData))
  442. {
  443.  
  444. SessionWrapper.PermissionSession.IsUpdateAllData = true;
  445. }
  446. else
  447. {
  448. SessionWrapper.PermissionSession.IsUpdateAllData = false;
  449. }
  450.  
  451. if (_permissions.Any(c => c.userid == loginUserId && c.PermissionId == (int)Permission.PrintReport))
  452. {
  453. SessionWrapper.PermissionSession.IsPrintAllData = true;
  454. }
  455. else
  456. {
  457. SessionWrapper.PermissionSession.IsPrintAllData = false;
  458. }
  459.  
  460.  
  461. }
  462.  
  463. }
  464.  
  465. catch
  466. {
  467. }
  468. }
  469.  
  470. public Clients FindClientByLoggedUser(int userId)
  471. {
  472. Clients result = new Clients();
  473. bool flag = false;
  474. try
  475. {
  476. flag = ctx.tblusers.Any(d => d.userid == userId && d.active == true && d.broker.HasValue && d.broker.Value == true);
  477. if (flag == true)
  478. {
  479. result = ctx.tblusers.Where(u => u.userid == userId && u.active == true).Select(u => new Clients()
  480. {
  481. clientid = u.account,
  482. parent = u.tblaccount.parent,
  483. companyname = u.tblaccount.companyname,
  484. affiliateid = u.tblaccount.affiliateid,
  485. telephone = u.tblaccount.telephone,
  486. email = u.username,
  487. contactname = u.brokername,
  488. address = u.tblaccount.address,
  489. username = u.brokername,
  490. PrimaryContact = u.PrimaryContact,
  491. SecondaryContact = u.SecondaryContact,
  492. Address1 = u.Address1,
  493. Address2 = u.Address2,
  494. OtherDetails = u.OtherDetails,
  495. Title = u.Title,
  496. FAX = u.FAX,
  497. Qualification = u.Qualification,
  498. countLeads = u.tblaccount.tblcontacts.Count()
  499. }).FirstOrDefault();
  500. }
  501. else
  502. {
  503. // This is for the general user
  504. 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)))
  505. {
  506. result = ctx.tblusers.Where(u => u.userid == userId && u.active == true).Select(u => new Clients()
  507. {
  508. clientid = u.account,
  509. parent = u.tblaccount.parent,
  510. companyname = u.tblaccount.companyname,
  511. affiliateid = u.tblaccount.affiliateid,
  512. telephone = u.tblaccount.telephone,
  513. email = u.username,
  514. contactname = u.brokername,
  515. address = u.tblaccount.address,
  516. username = u.brokername,
  517. PrimaryContact = u.PrimaryContact,
  518. SecondaryContact = u.SecondaryContact,
  519. Address1 = u.Address1,
  520. Address2 = u.Address2,
  521. OtherDetails = u.OtherDetails,
  522. Title = u.Title,
  523. FAX = u.FAX,
  524. Qualification = u.Qualification,
  525. countLeads = u.tblaccount.tblcontacts.Count()
  526. }).FirstOrDefault();
  527. }
  528. else
  529. {
  530. result = ctx.tblusers.Where(u => u.userid == userId && !u.tblaccount.parent.HasValue && u.active == true).Select(u => new Clients()
  531. {
  532. clientid = u.account,
  533. parent = u.tblaccount.parent,
  534. companyname = u.tblaccount.companyname,
  535. affiliateid = u.tblaccount.affiliateid,
  536. telephone = u.tblaccount.telephone,
  537. email = u.username,
  538. contactname = u.brokername,
  539. address = u.tblaccount.address,
  540. username = u.brokername,
  541. PrimaryContact = u.PrimaryContact,
  542. SecondaryContact = u.SecondaryContact,
  543. Address1 = u.Address1,
  544. Address2 = u.Address2,
  545. OtherDetails = u.OtherDetails,
  546. Title = u.Title,
  547. FAX = u.FAX,
  548. Qualification = u.Qualification,
  549. countLeads = u.tblaccount.tblcontacts.Count()
  550. }).FirstOrDefault();
  551. }
  552. }
  553. return result;
  554. }
  555. catch (Exception)
  556. {
  557. return result;
  558. }
  559. }
  560.  
  561. public bool IsManager(int userId, out int teamId, out string brokers)
  562. {
  563. bool _chk = false;
  564. teamId = 0;
  565. brokers = "";
  566. try
  567. {
  568. if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == true && u.broker.Value == true)))
  569. {
  570. _chk = true;
  571. teamId = ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault() != null ? (ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault().TeamId ?? 0) : 0;
  572. }
  573.  
  574. if (teamId > 0)
  575. {
  576. SqlParameter[] Param = new SqlParameter[2];
  577. Param[0] = new SqlParameter("@TeamId", teamId);
  578.  
  579. var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetTeamMembersIdsByTeamId", Param);
  580. if (dt != null && dt.Rows.Count > 0)
  581. {
  582. brokers = Convert.ToString(dt.Rows[0]["BrokersIds"]).Trim().TrimEnd(',');
  583. }
  584.  
  585. }
  586.  
  587. }
  588. catch
  589. {
  590. }
  591. return _chk;
  592. }
  593.  
  594. using Code;
  595. using MailChimp;
  596. using Mandrill;
  597. using Occfinance.Code;
  598. using Occfinance.Common;
  599. using Occfinance.Models;
  600. using Occfinance_Data;
  601. using System;
  602. using System.Collections.Generic;
  603. using System.Data;
  604. using System.Data.SqlClient;
  605. using System.Globalization;
  606. using System.Linq;
  607. using System.Text;
  608. using System.Web;
  609. //using Codes;
  610. using System.IO;
  611. using System.Configuration;
  612. using Occfinance.Services.Services.Helpers;
  613. using Occfinance.Services.Services.Application;
  614. namespace Occfinance.Services.Services
  615. {
  616. public class MailServices
  617. {
  618. db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
  619. Q_Application QApplication = new Q_Application();
  620. List<Occfinance.Models.StatusCount> _listStatusCount = new List<Occfinance.Models.StatusCount>();
  621. public int SendEmail(string userid, string useraccountid, LeadSearchCriteria filter,int loggedinuserid, string _userName, string _usertel, string _useremail, int templateid, int chk, string name, string EmailId, int FinanceId, int toall, List<ContactMail> ContactArray, string subject, string body, bool followUp /* added on 28 01 2015 for followup */, bool IsMortgageClientInclude )
  622. {
  623.  
  624. int _chk = 0;
  625. var _contentURL = "occfinance.com";
  626.  
  627. try
  628. {
  629. if (string.IsNullOrWhiteSpace(subject))
  630. subject = "Mail From OCC Finance";
  631.  
  632. string _McAPIKey = Convert.ToString(ConfigurationManager.AppSettings["MailChimpApikey"] ?? "");
  633. MailChimpManager _mcmanager = new MailChimpManager(Convert.ToString(ConfigurationManager.AppSettings["MailChimpApikey"] ?? ""));
  634. var _mailDrilEmails = new List<EmailAddress>();
  635. var _mandrillMessage = new List<EmailMessage>();
  636. List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
  637.  
  638.  
  639. if (chk == 1)
  640. {
  641. AddUpdate(templateid, name, subject, body, userid, useraccountid);
  642. }
  643.  
  644. IQueryable<ApplicationLead> allLead = null;
  645.  
  646. allLead = QApplication.GetAllLead(out _listStatusCount, useraccountid.StringToInt(), userid.StringToInt(), filter.financetype, "", filter.ClientID, filter.Broker, filter.Status, filter.Lender, filter.Solicitor, filter.RequiredFolloUp);
  647.  
  648. //Get new latest NoteId *****************************
  649. Q_Application _qA = new Q_Application();
  650. //int _noteid = _qA.getNoteID();
  651. //***************************************************
  652.  
  653. if (!string.IsNullOrWhiteSpace(EmailId) && FinanceId != 0 && toall == 0)
  654. {
  655.  
  656.  
  657. //int typeid = Convert.ToInt32(Session["DefaultsettingId"] ?? 1);
  658. //int loggedinuser = Convert.ToInt32(Session["LoggedInUserId"] ?? "0");
  659. // Q_Application QApplication = new Q_Application();
  660. //List<StatusCount> _listStatusCount = new List<StatusCount>();
  661. //allLead = QApplication.GetAllLead(out _listStatusCount, Convert.ToInt32(Session["LoggedInUserAccountId"]), loggedinuser, typeid, Convert.ToString(Session["Search"] ?? ""), 0, "", "", "", "", 0);
  662.  
  663. var obj = new ApplicationJsonLead();
  664. if (allLead == null)
  665. {
  666. var objMain = ctx.tblfinances.Where(c => c.financeid == FinanceId).FirstOrDefault();
  667. obj = QApplication.GetSingleLead(0, objMain.contact ?? 0, objMain.financeid);
  668. }
  669. else
  670. {
  671. var objMain = allLead.Where(c => c.financeid == FinanceId).FirstOrDefault();
  672. obj = QApplication.GetSingleLead(objMain.AccountId, objMain.contactId, objMain.financeid);
  673. }
  674. bool IsUnsubscribed = false;
  675.  
  676. //Check if contact is unsubscribed 2014-11-20
  677. if (WebUtility.UnsubscribeEmail(obj.contactId, 3) == 3)
  678. {
  679. return -3;
  680. }
  681.  
  682.  
  683. if (obj != null)
  684. {
  685. string _mailcontent = MailContentTemplate(
  686. body,
  687. obj.firstName,
  688. obj.lastName,
  689. (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
  690. obj.tel, _usertel, _userName, _useremail,
  691. obj.brokerName ?? "",
  692. obj.clientname ?? "", obj.brokerName ?? "", obj.PolicyNumber ?? "", obj.Lender ?? "", obj.Soliciter ?? "", obj.PrimaryContact ?? "", obj.SecondaryContact ?? "", obj.Address1 ?? "", obj.Address2 ?? "", obj.OtherDetails ?? "", obj.Title ?? "", obj.FAX ?? "", obj.Qualification ?? "", Convert.ToString(obj.contactId) ?? "");
  693.  
  694.  
  695.  
  696. //Add Notes to the note table**************************************************
  697. string HTML_TAG_PATTERN = @"<[^>]+>|&nbsp;";
  698.  
  699. // Create the email parameter
  700. try
  701. {
  702. _mailDrilEmails = new List<EmailAddress>();
  703. EmailAddress objEm = new EmailAddress();
  704. objEm.email = EmailId;
  705. objEm.name = obj.firstName + " " + obj.lastName;
  706. _mailDrilEmails.Add(objEm);
  707.  
  708. //Man DRILL ********************************************************************
  709.  
  710. EmailMessage message = new EmailMessage();
  711. message.to = _mailDrilEmails;
  712. message.html = _mailcontent;
  713. message.from_email = obj.BrokerEmail ?? "";
  714. message.from_name = obj.brokerName ?? "";
  715. message.subject = subject;
  716. message.inline_css = true;
  717. message.signing_domain = _contentURL;
  718. message.AddHeader("X-MC-SigningDomain", _contentURL);
  719. message.AddHeader("X-MC-TrackingDomain", _contentURL);
  720. _mandrillMessage.Add(message);
  721.  
  722. //********************************************************************************
  723.  
  724. // Manage The ManDRILLModel - 25-07-2014
  725.  
  726. var objMAN = new ManDRILLModel();
  727. objMAN.contactId = obj.contactId;
  728. objMAN.financeid = obj.financeid;
  729. objMAN.mailcontent = _mailcontent;
  730. objMAN.MandrillMSG = message;
  731. objMAN.IsAppContact = false;
  732. objMAN.TemplateName = name;
  733. objMAN.Status = obj.status ?? 0;
  734. objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
  735.  
  736. _mandrillOBJ.Add(objMAN);
  737.  
  738. }
  739. catch
  740. {
  741. }
  742. // Track Mail
  743.  
  744.  
  745. if (!string.IsNullOrWhiteSpace(obj.OtherApplicantEmail))
  746. {
  747. if (!EmailId.GetString().Equals(obj.OtherApplicantEmail.GetString(), StringComparison.OrdinalIgnoreCase))
  748. {
  749. string _mailcontentother = MailContentTemplate(
  750. body,
  751. obj.OtherApplicantFname,
  752. obj.OtherApplicantSName,
  753. (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
  754. obj.OtherApplicantMobile,
  755. _usertel, _userName, _useremail,
  756. obj.brokerName ?? "",
  757. obj.clientname ?? "", obj.BrokerEmail ?? "", obj.PolicyNumber ?? "", obj.Lender ?? "", obj.Soliciter ?? "", obj.PrimaryContact ?? "", obj.SecondaryContact ?? "", obj.Address1 ?? "", obj.Address2 ?? "", obj.OtherDetails ?? "", obj.Title ?? "", obj.FAX ?? "", obj.Qualification ?? "", Convert.ToString(obj.contactId) ?? "");
  758.  
  759.  
  760.  
  761. // This below functiona to subscribe the user into the mail chimp (Need to add functionality through Mail Chimp)
  762. // Create the email parameter
  763. try
  764. {
  765. _mailDrilEmails = new List<EmailAddress>();
  766. EmailAddress objEm = new EmailAddress();
  767. objEm.email = obj.OtherApplicantEmail;
  768. objEm.name = obj.OtherApplicantFname + " " + obj.OtherApplicantSName;
  769. _mailDrilEmails.Add(objEm);
  770.  
  771. //Man DRILL ********************************************************************
  772. EmailMessage message = new EmailMessage();
  773. message.to = _mailDrilEmails;
  774. message.html = _mailcontentother;
  775. message.from_email = obj.BrokerEmail ?? "";
  776. message.from_name = obj.brokerName ?? "";
  777. message.subject = subject;
  778. message.inline_css = true;
  779. message.signing_domain = _contentURL;
  780. message.AddHeader("X-MC-SigningDomain", _contentURL);
  781. message.AddHeader("X-MC-TrackingDomain", _contentURL);
  782. _mandrillMessage.Add(message);
  783.  
  784. // Manage The ManDRILLModel - 25-07-2014
  785.  
  786. var objMAN = new ManDRILLModel();
  787. objMAN.contactId = obj.contactId;
  788. objMAN.financeid = 0;
  789. objMAN.mailcontent = _mailcontentother;
  790. objMAN.MandrillMSG = message;
  791. objMAN.IsAppContact = true;
  792. objMAN.Status = obj.status ?? 0;
  793. objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
  794. objMAN.TemplateName = name;
  795. _mandrillOBJ.Add(objMAN);
  796.  
  797. //
  798. }
  799. catch
  800. {
  801. }
  802. // Track Mail
  803. }
  804. }
  805.  
  806. }
  807.  
  808. if (WebUtility.SendMailViaManDRILL(_mandrillOBJ, loggedinuserid, followUp))
  809. _chk = 1;
  810.  
  811. }
  812. else if (toall == 2 && ContactArray != null && ContactArray.Count() > 0)
  813. {
  814. //List<MailSentStatus> _listMailStatus = new List<MailSentStatus>();
  815. //_listMailStatus = allLead.Select(c => new MailSentStatus
  816. //{
  817. // EmailId = c.email,
  818. // Status = 0
  819. //}).Distinct().ToList().Where(c => !string.IsNullOrWhiteSpace(c.EmailId)).ToList();
  820. //***************************************************************************
  821. var count = 0;
  822. List<int> lstContactIds = new List<int>();
  823. List<string> emails = new List<string>();
  824. foreach (var objC in ContactArray)
  825. {
  826.  
  827. // var obj = allLead.Where(c => c.financeid == objC.financeid).FirstOrDefault();
  828.  
  829.  
  830.  
  831. FinanceId = objC.financeid;
  832.  
  833.  
  834. var obj = new ApplicationJsonLead();
  835. if (allLead == null)
  836. {
  837. var objMain = ctx.tblfinances.Where(c => c.financeid == FinanceId).FirstOrDefault();
  838. obj = QApplication.GetSingleLead(0, objMain.contact ?? 0, objMain.financeid);
  839. }
  840. else
  841. {
  842. var objMain = allLead.Where(c => c.financeid == FinanceId).FirstOrDefault();
  843. obj = QApplication.GetSingleLead(objMain.AccountId, objMain.contactId, objMain.financeid);
  844. }
  845. List<int> lstContactId = new List<int>();
  846. //Check for unsubscribed contacts 2014-11-20
  847. if (WebUtility.UnsubscribeEmail(objC.contactid, 3) != 3)
  848. {
  849. string _mailcontent = MailContentTemplate(
  850. body,
  851. obj.firstName,
  852. obj.lastName,
  853. (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
  854. obj.tel,
  855. _userName,_usertel, _useremail,
  856. obj.brokerName ?? "",
  857. obj.clientname ?? "", obj.BrokerEmail ?? "", obj.PolicyNumber ?? "", obj.Lender ?? "", obj.Soliciter ?? "", obj.PrimaryContact ?? "", obj.SecondaryContact ?? "", obj.Address1 ?? "", obj.Address2 ?? "", obj.OtherDetails ?? "", obj.Title ?? "", obj.FAX ?? "", obj.Qualification ?? "", Convert.ToString(obj.contactId) ?? "");
  858.  
  859.  
  860. if (!string.IsNullOrWhiteSpace(obj.email)) // && _listMailStatus.Where(c => c.EmailId == obj.email && c.Status == 1).Count() == 0 // Apply within if condition once mail will be sent once for a single contact regardsless of multiple products
  861. {
  862. try
  863. {
  864. // check if email exists
  865. if (!emails.Contains(obj.email))
  866. {
  867. emails.Add(obj.email);
  868. //Add Notes to the note table**************************************************
  869. string HTML_TAG_PATTERN = @"<[^>]+>|&nbsp;";
  870. _mailDrilEmails = new List<EmailAddress>();
  871. EmailAddress objEm = new EmailAddress();
  872. objEm.email = obj.email;
  873. objEm.name = obj.firstName + " " + obj.lastName;
  874. _mailDrilEmails.Add(objEm);
  875.  
  876. //Man DRILL ********************************************************************
  877. EmailMessage message = new EmailMessage();
  878. message.to = _mailDrilEmails;
  879. message.html = _mailcontent;
  880. message.from_email = obj.BrokerEmail ?? "";
  881. message.from_name = obj.brokerName ?? "";
  882. message.subject = subject;
  883. message.inline_css = true;
  884. message.signing_domain = _contentURL;
  885. message.AddHeader("X-MC-SigningDomain", _contentURL);
  886. message.AddHeader("X-MC-TrackingDomain", _contentURL);
  887. _mandrillMessage.Add(message);
  888. // Manage The ManDRILLModel - 25-07-2014
  889.  
  890. var objMAN = new ManDRILLModel();
  891. objMAN.contactId = obj.contactId;
  892. objMAN.financeid = obj.financeid;
  893. objMAN.mailcontent = _mailcontent;
  894. objMAN.MandrillMSG = message;
  895. objMAN.IsAppContact = false;
  896. objMAN.Status = obj.status ?? 0;
  897. objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
  898. objMAN.TemplateName = name;
  899. _mandrillOBJ.Add(objMAN);
  900. }
  901. }
  902. catch
  903. {
  904. }
  905.  
  906. }
  907.  
  908.  
  909. //******************************************************************************
  910.  
  911. // ****************************** Send Mail to other Applicant ******************************
  912. if (!string.IsNullOrWhiteSpace(obj.OtherApplicantEmail))
  913. {
  914. if (!emails.Contains(obj.OtherApplicantEmail))
  915. {
  916. // check for other application email
  917. if (!obj.email.GetString().Equals(obj.OtherApplicantEmail.GetString(), StringComparison.OrdinalIgnoreCase))
  918. {
  919. emails.Add(obj.OtherApplicantEmail);
  920. string _mailcontentother = MailContentTemplate(
  921. body,
  922. obj.OtherApplicantFname,
  923. obj.OtherApplicantSName,
  924. (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
  925. obj.OtherApplicantMobile,
  926. _userName, _usertel, _useremail,
  927. obj.brokerName ?? "",
  928. obj.clientname ?? "", obj.BrokerEmail ?? "", obj.PolicyNumber ?? "", obj.Lender ?? "", obj.Soliciter ?? "", obj.PrimaryContact ?? "", obj.SecondaryContact ?? "", obj.Address1 ?? "", obj.Address2 ?? "", obj.OtherDetails ?? "", obj.Title ?? "", obj.FAX ?? "", obj.Qualification ?? "", Convert.ToString(obj.contactId) ?? "");
  929.  
  930. try
  931. {
  932. _mailDrilEmails = new List<EmailAddress>();
  933. EmailAddress objEm = new EmailAddress();
  934. objEm.email = obj.OtherApplicantEmail;
  935. objEm.name = obj.OtherApplicantFname + " " + obj.OtherApplicantSName;
  936. _mailDrilEmails.Add(objEm);
  937.  
  938. //Man DRILL ********************************************************************
  939. EmailMessage message = new EmailMessage();
  940. message.to = _mailDrilEmails;
  941. message.html = _mailcontentother;
  942. message.from_email = obj.BrokerEmail ?? "";
  943. message.from_name = obj.brokerName ?? "";
  944. message.subject = subject;
  945. message.inline_css = true;
  946. message.signing_domain = _contentURL;
  947. message.AddHeader("X-MC-SigningDomain", _contentURL);
  948. message.AddHeader("X-MC-TrackingDomain", _contentURL);
  949. _mandrillMessage.Add(message);
  950. var objMAN = new ManDRILLModel();
  951. objMAN.contactId = obj.OtherApplicantId;
  952. objMAN.financeid = 0;
  953. objMAN.mailcontent = _mailcontentother;
  954. objMAN.MandrillMSG = message;
  955. objMAN.IsAppContact = true;
  956. objMAN.notemsg = "";
  957. objMAN.TemplateName = name;
  958. objMAN.Status = obj.status ?? 0;
  959. _mandrillOBJ.Add(objMAN);
  960. }
  961. catch
  962. {
  963. }
  964. }
  965. }
  966. }
  967. }
  968. else
  969. {
  970. lstContactIds.Add(objC.contactid);
  971. count++;
  972. }
  973. }
  974. _mandrillOBJ = _mandrillOBJ.FindAll(res => !lstContactIds.Contains(res.contactId));
  975. if (WebUtility.SendMailViaManDRILL(_mandrillOBJ, loggedinuserid, followUp))
  976. _chk = 1;
  977. //If all the contacts are unsubscribed
  978. if (ContactArray.Count() == count)
  979. _chk = -3;
  980.  
  981. }
  982. else if (toall == 1)
  983. {
  984.  
  985. if (allLead == null)
  986. {
  987. _chk = -2;
  988. return _chk;
  989. }
  990. if (!IsMortgageClientInclude)
  991. {
  992. int userId = Convert.ToInt32(userid ?? "0");
  993. allLead = allLead.Where(x => x.brokerId == userId).AsQueryable();
  994. }
  995. // Mail To Send All Contacts as per Live Server *************************************
  996.  
  997. ////Get all distinct Emails****************************************************
  998. //List<MailSentStatus> _listMailStatus = new List<MailSentStatus>();
  999. //_listMailStatus = allLead.Select(c => new MailSentStatus
  1000. //{
  1001. // EmailId = c.email,
  1002. // Status = 0
  1003. //}).Distinct().ToList().Where(c => !string.IsNullOrWhiteSpace(c.EmailId)).ToList();
  1004. //***************************************************************************
  1005. var count = 0;
  1006. List<string> emails = new List<string>();
  1007. List<int> lstContactIds = new List<int>();
  1008. foreach (var objMain in allLead)
  1009. {
  1010.  
  1011. //if (WebUtility.UnsubscribeEmail(objMain.contactId, 3) == 3)
  1012. //{
  1013. // count++;
  1014. // lstContactIds.Add(objMain.contactId);
  1015. // continue;
  1016. //}
  1017. //Added for Latest Data-----------------------
  1018.  
  1019. var obj = QApplication.GetSingleLead(objMain.AccountId, objMain.contactId, objMain.financeid);
  1020.  
  1021.  
  1022. //Check for unsubscribed contacts 2014-11-20
  1023. if (WebUtility.UnsubscribeEmail(objMain.contactId, 3) != 3)
  1024. {
  1025. string _mailcontent = MailContentTemplate(
  1026. body,
  1027. obj.firstName,
  1028. obj.lastName,
  1029. (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
  1030. obj.tel,
  1031. _userName, _usertel, _useremail,
  1032. obj.brokerName ?? "",
  1033. obj.clientname ?? "", obj.BrokerEmail ?? "", obj.PolicyNumber ?? "", obj.Lender ?? "", obj.Soliciter ?? "", obj.PrimaryContact ?? "", obj.SecondaryContact ?? "", obj.Address1 ?? "", obj.Address2 ?? "", obj.OtherDetails ?? "", obj.Title ?? "", obj.FAX ?? "", obj.Qualification ?? "", Convert.ToString(obj.contactId) ?? "");
  1034.  
  1035.  
  1036. if (!string.IsNullOrWhiteSpace(obj.email)) // && _listMailStatus.Where(c => c.EmailId == obj.email && c.Status == 1).Count() == 0 // Apply within if condition once mail will be sent once for a single contact regardsless of multiple products
  1037. {
  1038. try
  1039. {
  1040. // check if not exists
  1041. if (!emails.Contains(obj.email))
  1042. {
  1043. emails.Add(obj.email);
  1044. //Add Notes to the note table**************************************************
  1045. string HTML_TAG_PATTERN = @"<[^>]+>|&nbsp;";
  1046. _mailDrilEmails = new List<EmailAddress>();
  1047. EmailAddress objEm = new EmailAddress();
  1048. objEm.email = obj.email;
  1049. objEm.name = obj.firstName + " " + obj.lastName;
  1050. _mailDrilEmails.Add(objEm);
  1051.  
  1052. //Man DRILL ********************************************************************
  1053. EmailMessage message = new EmailMessage();
  1054. message.to = _mailDrilEmails;
  1055. message.html = _mailcontent;
  1056. message.from_email = obj.BrokerEmail ?? "";
  1057. message.from_name = obj.brokerName ?? "";
  1058. message.subject = subject;
  1059. message.inline_css = true;
  1060. message.signing_domain = _contentURL;
  1061. message.AddHeader("X-MC-SigningDomain", _contentURL);
  1062. message.AddHeader("X-MC-TrackingDomain", _contentURL);
  1063. _mandrillMessage.Add(message);
  1064. // Manage The ManDRILLModel - 25-07-2014
  1065.  
  1066. var objMAN = new ManDRILLModel();
  1067. objMAN.contactId = obj.contactId;
  1068. objMAN.financeid = obj.financeid;
  1069. objMAN.mailcontent = _mailcontent;
  1070. objMAN.MandrillMSG = message;
  1071. objMAN.IsAppContact = false;
  1072. objMAN.TemplateName = name;
  1073. objMAN.Status = obj.status ?? 0;
  1074. objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
  1075.  
  1076. _mandrillOBJ.Add(objMAN);
  1077. }
  1078. }
  1079. catch
  1080. {
  1081. }
  1082. }
  1083.  
  1084.  
  1085. //******************************************************************************
  1086.  
  1087. // ****************************** Send Mail to other Applicant ******************************
  1088. if (!string.IsNullOrWhiteSpace(obj.OtherApplicantEmail))
  1089. {
  1090. if (!emails.Contains(obj.OtherApplicantEmail))
  1091. {
  1092. // check for other application email
  1093. if (!obj.email.GetString().Equals(obj.OtherApplicantEmail.GetString(), StringComparison.OrdinalIgnoreCase))
  1094. {
  1095. emails.Add(obj.OtherApplicantEmail);
  1096. string _mailcontentother = MailContentTemplate(
  1097. body,
  1098. obj.OtherApplicantFname,
  1099. obj.OtherApplicantSName,
  1100. (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
  1101. obj.OtherApplicantMobile,
  1102. _userName, _usertel, _useremail,
  1103. obj.brokerName ?? "",
  1104. obj.clientname ?? "", obj.BrokerEmail ?? "", obj.PolicyNumber ?? "", obj.Lender ?? "", obj.Soliciter ?? "", obj.PrimaryContact ?? "", obj.SecondaryContact ?? "", obj.Address1 ?? "", obj.Address2 ?? "", obj.OtherDetails ?? "", obj.Title ?? "", obj.FAX ?? "", obj.Qualification ?? "", Convert.ToString(obj.contactId) ?? "");
  1105.  
  1106. try
  1107. {
  1108. _mailDrilEmails = new List<EmailAddress>();
  1109. EmailAddress objEm = new EmailAddress();
  1110. objEm.email = obj.OtherApplicantEmail;
  1111. objEm.name = obj.OtherApplicantFname + " " + obj.OtherApplicantSName;
  1112. _mailDrilEmails.Add(objEm);
  1113.  
  1114. //Man DRILL ********************************************************************
  1115. EmailMessage message = new EmailMessage();
  1116. message.to = _mailDrilEmails;
  1117. message.html = _mailcontent;
  1118. message.from_email = obj.BrokerEmail ?? "";
  1119. message.from_name = obj.brokerName ?? "";
  1120. message.subject = subject;
  1121. message.inline_css = true;
  1122. message.signing_domain = _contentURL;
  1123. message.AddHeader("X-MC-SigningDomain", _contentURL);
  1124. message.AddHeader("X-MC-TrackingDomain", _contentURL);
  1125. _mandrillMessage.Add(message);
  1126. // Manage The ManDRILLModel - 25-07-2014
  1127.  
  1128. var objMAN = new ManDRILLModel();
  1129. objMAN.contactId = obj.OtherApplicantId;
  1130. objMAN.financeid = 0;
  1131. objMAN.mailcontent = _mailcontent;
  1132. objMAN.MandrillMSG = message;
  1133. objMAN.IsAppContact = false;
  1134. objMAN.notemsg = "";
  1135. objMAN.TemplateName = name;
  1136. objMAN.Status = obj.status ?? 0;
  1137. _mandrillOBJ.Add(objMAN);
  1138. }
  1139. catch
  1140. {
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. else
  1147. {
  1148. lstContactIds.Add(objMain.contactId);
  1149. count++;
  1150. }
  1151.  
  1152. //********************************************************* Other Applicant ******************************
  1153.  
  1154. }
  1155.  
  1156. //*********************************************************END**************************************************************************
  1157. _mandrillOBJ = _mandrillOBJ.FindAll(res => !lstContactIds.Contains(res.contactId));
  1158. if (WebUtility.SendMailViaManDRILLForBulkEmail(_mandrillOBJ, loggedinuserid, followUp))
  1159. _chk = 1;
  1160. if (allLead.Count() == count)
  1161. _chk = -3;
  1162. }
  1163. }
  1164. catch
  1165. {
  1166. throw;
  1167. }
  1168.  
  1169. return _chk;
  1170. }
  1171.  
  1172.  
  1173. public int AddUpdate(int templateid, string name, string subject, string body, string userId, string accountId)
  1174. {
  1175. int chk = 0;
  1176. string _connectionstring = Convert.ToString(ConfigurationManager.ConnectionStrings["ConString1"]);
  1177. try
  1178. {
  1179.  
  1180. var _userId = Convert.ToInt32(userId ?? "0");
  1181. var _accountId = Convert.ToInt32(accountId ?? "0");
  1182.  
  1183. if (templateid > 0)
  1184. {
  1185. using (SqlConnection con = new SqlConnection(_connectionstring))
  1186. {
  1187. using (SqlCommand cmd = new SqlCommand("MailTemplateUpdate", con))
  1188. {
  1189. cmd.CommandType = CommandType.StoredProcedure;
  1190. cmd.Parameters.AddWithValue("@UserId", _userId);
  1191. cmd.Parameters.AddWithValue("@TemplateId", templateid);
  1192. cmd.Parameters.AddWithValue("@TemplateName", name);
  1193. cmd.Parameters.AddWithValue("@Subject", subject);
  1194. cmd.Parameters.AddWithValue("@Templates", body);
  1195. cmd.Parameters.Add("@Chk", SqlDbType.Int);
  1196. cmd.Parameters["@Chk"].Direction = ParameterDirection.Output;
  1197. con.Open();
  1198. cmd.ExecuteNonQuery();
  1199. chk = Convert.ToInt32(cmd.Parameters["@Chk"].SqlValue.ToString());
  1200. con.Close();
  1201. con.Dispose();
  1202. }
  1203. }
  1204.  
  1205. }
  1206. else
  1207. {
  1208. using (SqlConnection con = new SqlConnection(_connectionstring))
  1209. {
  1210. using (SqlCommand cmd = new SqlCommand("MailTemplateAdd", con))
  1211. {
  1212. cmd.CommandType = CommandType.StoredProcedure;
  1213. cmd.Parameters.AddWithValue("@UserId", _userId);
  1214. cmd.Parameters.AddWithValue("@AccountId", _accountId);
  1215. cmd.Parameters.AddWithValue("@TemplateName", name);
  1216. cmd.Parameters.AddWithValue("@Subject", subject);
  1217. cmd.Parameters.AddWithValue("@Templates", body);
  1218. cmd.Parameters.Add("@TemplateId", SqlDbType.Int);
  1219. cmd.Parameters["@TemplateId"].Direction = ParameterDirection.Output;
  1220. con.Open();
  1221. cmd.ExecuteNonQuery();
  1222. chk = Convert.ToInt32(cmd.Parameters["@TemplateId"].SqlValue.ToString());
  1223. con.Close();
  1224. con.Dispose();
  1225. }
  1226. }
  1227. }
  1228.  
  1229. }
  1230. catch
  1231. {
  1232. throw;
  1233.  
  1234. }
  1235. return chk;
  1236. }
  1237.  
  1238. public string MailContentTemplate(string mailcontent, string FName, string LName, string followupdate, string contacttel, string usertel, string username, string useremail, string brokername, string CompanyName, string BrokerEmail, string PolicyNumber, string ProviderName, string SolicitorName, string PrimaryContact, string SecondaryContact, string Address1, string Address2, string OtherDetails, string Title, string FAX, string Qualification, string ContactId)
  1239. {
  1240. StringBuilder _tempate = new StringBuilder();
  1241. try
  1242. {
  1243. string siteUrl = Convert.ToString(ConfigurationManager.AppSettings["SecureURL"] ?? "http://secure.occfinance.com/");
  1244. _tempate.Append(mailcontent);
  1245. _tempate = _tempate
  1246. .Replace("*|FNAME|*", FName)
  1247. .Replace("*|LNAME|*", LName)
  1248. .Replace("*|CONTTEL|*", contacttel)
  1249. .Replace("*|UNAME|*", username)
  1250. .Replace("*|UEMAIL|*", useremail)
  1251. .Replace("*|UTEL|*", usertel)
  1252. .Replace("*|FDATE|*", followupdate)
  1253. .Replace("*|ADVISERN|*", brokername)
  1254. .Replace("*|ADVISERQ|*", Qualification)
  1255. .Replace("*|CNAME|*", CompanyName)
  1256. .Replace("*|ADVISEREMA|*", BrokerEmail)
  1257. .Replace("*|PNUM|*", PolicyNumber)
  1258. .Replace("*|PRVNAME|*", ProviderName)
  1259. .Replace("*|SNAME|*", SolicitorName)
  1260. .Replace("*|ADVISERTEL|*", PrimaryContact)
  1261. .Replace("*|ADVISERMOB|*", SecondaryContact)
  1262. .Replace("*|ADVSRAD1|*", Address1)
  1263. .Replace("*|ADVSRAD2|*", Address2)
  1264. .Replace("*|ADVSRODL|*", OtherDetails)
  1265. .Replace("*|ADVISERFAX|*", FAX)
  1266. .Replace("*|ADVISERTTL|*", Title)
  1267. .Replace("*|DISCLAIMER|*", "")
  1268. .Replace("*|COMPANYURL|*", "")
  1269. .Replace("*|MC:SUBJECT|*", "")
  1270. .Replace("*|MSGBODY|*", "")
  1271. .Replace("*|UNSUB|*", siteUrl + "/Home/UnsubscribeEmails?contactId=" + ContactId + "&type=1");
  1272.  
  1273.  
  1274. }
  1275. catch
  1276. {
  1277. throw;
  1278. }
  1279.  
  1280. return _tempate.ToString();
  1281. }
  1282.  
  1283. //public class ContactMail
  1284. //{
  1285. // public int financeid { get; set; }
  1286. // public int contactid { get; set; }
  1287. //}
  1288.  
  1289. }
  1290. }
  1291.  
  1292. public AtendanceStatus GetAvailableHoursDays(int userId, DateTime activityDate, int year)
  1293. {
  1294. AtendanceStatus _AtendanceStatus = new AtendanceStatus();
  1295. SqlParameter[] Param = new SqlParameter[3];
  1296. Param[0] = new SqlParameter("@UserId", userId);
  1297. Param[1] = new SqlParameter("@ActivityDate", activityDate);
  1298. Param[2] = new SqlParameter("@Year", year);
  1299.  
  1300. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAvailableHoursDays", Param);
  1301. try
  1302. {
  1303. var d = (from DataRow row in dt.Rows
  1304. select new AtendanceStatus
  1305. {
  1306. AllowedDays = Convert.ToDecimal(((row["AllowedDays"] == DBNull.Value || row["AllowedDays"] == null) ? "0" : row["AllowedDays"])),
  1307. AllowedHours = Convert.ToDecimal(((row["AllowedHours"] == DBNull.Value || row["AllowedHours"] == null) ? "0" : row["AllowedHours"])),
  1308. UsedDays = Convert.ToDecimal(((row["UsedDays"] == DBNull.Value || row["UsedDays"] == null) ? "0" : row["UsedDays"])),
  1309. UsedHours = Convert.ToDecimal(((row["UsedHours"] == DBNull.Value || row["UsedHours"] == null) ? "0" : row["UsedHours"])),
  1310. }).ToList();
  1311.  
  1312. if (d != null && d.Count() > 0)
  1313. _AtendanceStatus = d[0];
  1314. }
  1315. catch
  1316. {
  1317. }
  1318. return _AtendanceStatus ?? new AtendanceStatus();
  1319. }
  1320.  
  1321. public static bool SendMailMessage(System.String To, System.String Bcc, System.String Cc, System.String Subject, System.String Message, string attachmentPath = "", string frommail = "")
  1322. {
  1323.  
  1324. if (
  1325. string.IsNullOrEmpty(To) ||
  1326. string.IsNullOrEmpty(Subject) ||
  1327. string.IsNullOrEmpty(Message)
  1328. )
  1329. return false;
  1330.  
  1331.  
  1332. System.String From = !string.IsNullOrWhiteSpace(frommail) ? frommail : ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
  1333.  
  1334. try
  1335. {
  1336. SendNetMail(From, To, Bcc, Cc, Subject, Message, attachmentPath);
  1337. return true;
  1338. }
  1339. catch
  1340. {
  1341. try
  1342. {
  1343. SendWebMail(From, To, Bcc, Cc, Subject, Message, attachmentPath);
  1344. return true;
  1345. }
  1346. catch
  1347. {
  1348. try
  1349. {
  1350. System.Web.Mail.MailMessage MM = new System.Web.Mail.MailMessage();
  1351. MM.From = From;
  1352. MM.Subject = Subject;
  1353. MM.To = To;
  1354. if (!string.IsNullOrEmpty(Cc))
  1355. MM.Cc = Cc;
  1356. if (!string.IsNullOrEmpty(Bcc))
  1357. MM.Bcc = Bcc;
  1358. if (!string.IsNullOrEmpty(attachmentPath))
  1359. {
  1360. System.Web.Mail.MailAttachment attch = new MailAttachment(attachmentPath);
  1361. MM.Attachments.Add(attch);
  1362. }
  1363. MM.Body = Message;
  1364. MM.BodyFormat = System.Web.Mail.MailFormat.Html;
  1365. System.Web.Mail.SmtpMail.Send(MM);
  1366. return true;
  1367. }
  1368. catch
  1369. {
  1370. return false;
  1371. }
  1372. }
  1373. }
  1374.  
  1375. }
  1376.  
  1377. public int ResetPassword(string email)
  1378. {
  1379. int status = 0;
  1380. try
  1381. {
  1382. if (!ctx.tblusers.Where(c => c.username.ToLower().Trim() == email.ToLower().Trim()).Any())
  1383. {
  1384. status = 0;
  1385. }
  1386. else
  1387. {
  1388. var data = ctx.tblusers.Where(c => c.username.ToLower().Trim() == email.ToLower().Trim()).FirstOrDefault();
  1389. if (data != null)
  1390. {
  1391. string body = "Hi, <br /><br />";
  1392. body += "Your Password is: " + data.password + "<br />";
  1393. body += "Regards: <br />";
  1394. body += "Administrator <br />";
  1395. body += "OCC Finance<br />";
  1396.  
  1397. System.Threading.Tasks.Task.Run(() =>
  1398. {
  1399. MailHelper.SendMailMessage(email, "", "", "Password Request", body);
  1400. });
  1401.  
  1402. status = 1;
  1403. }
  1404. }
  1405.  
  1406. }
  1407. catch
  1408. {
  1409. throw;
  1410. }
  1411. return status;
  1412. }
  1413.  
  1414. public List<DashboardBrokers> FindDashboardBrokers(int parentUserId, int userId = 0)
  1415. {
  1416. bool flag = false;
  1417. List<DashboardBrokers> clients = new List<DashboardBrokers>();
  1418. try
  1419. {
  1420.  
  1421. var userAccount = ctx.tblaccounts.Where(u => u.parent.HasValue && u.parent.Value == parentUserId).Select(u => u.accountid).ToList();
  1422.  
  1423. // var account = ctx.tblusers.Where(u => u.broker.HasValue && u.broker.Value == true && userAccount.Contains(u.account) == true).Select(u => u).ToList();
  1424.  
  1425. var account = ctx.tblusers.Where(u => u.broker.HasValue && u.broker.Value == true && u.account == parentUserId).Select(u => u).ToList();
  1426. //if (userId > 0)
  1427. // account = account.Where(c => c.userid == userId).ToList();
  1428.  
  1429.  
  1430. SqlParameter[] Param = new SqlParameter[1];
  1431. Param[0] = new SqlParameter("@parentuserid", parentUserId);
  1432. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokerList", Param);
  1433.  
  1434. if (dt != null)
  1435. {
  1436. clients = (from DataRow row1 in dt.Rows
  1437. select new DashboardBrokers()
  1438. {
  1439. contactname = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString()),
  1440. Completion_Average = Convert.ToInt32(row1["exaverage"] == null ? "0" : row1["exaverage"].ToString()),
  1441. Completion_Total = Convert.ToInt32(row1["extotal"] == null ? "0" : row1["extotal"].ToString()),
  1442. Completion_Last30 = Convert.ToInt32(row1["exlast30days"] == null ? "0" : row1["exlast30days"].ToString()),
  1443. Completion_Change = Convert.ToInt32(row1["exChange"] == null ? "0" : row1["exChange"].ToString()),
  1444. Decision_in_principle_Average = Convert.ToInt32(row1["dipaverage"] == null ? "0" : row1["dipaverage"].ToString()),
  1445. Decision_in_principle_Total = Convert.ToInt32(row1["diptotal"] == null ? "0" : row1["diptotal"].ToString()),
  1446. Decision_in_principle_Last30 = Convert.ToInt32(row1["diplast30days"] == null ? "0" : row1["diplast30days"].ToString()),
  1447. Decision_in_principle_Change = Convert.ToInt32(row1["dipChange"] == null ? "0" : row1["dipChange"].ToString()),
  1448. ApplicationsSubmitted_Average = Convert.ToInt32(row1["appsubaverage"] == null ? "0" : row1["appsubaverage"].ToString()),
  1449. ApplicationsSubmitted_Total = Convert.ToInt32(row1["appsubtotal"] == null ? "0" : row1["appsubtotal"].ToString()),
  1450. ApplicationsSubmitted_Last30 = Convert.ToInt32(row1["appsublast30days"] == null ? "0" : row1["appsublast30days"].ToString()),
  1451. ApplicationsSubmitted_Change = Convert.ToInt32(row1["appChange"] == null ? "0" : row1["appChange"].ToString())
  1452.  
  1453. }).ToList();
  1454. }
  1455. #region
  1456. //foreach (DataRow row1 in dt.Rows)
  1457. //{
  1458. // DashboardBrokers _dsBroker = new DashboardBrokers();
  1459.  
  1460. // _dsBroker.contactname = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString());
  1461.  
  1462. // _dsBroker.Completion_Average = Convert.ToInt32(row1["exaverage"] == null ? "0" : row1["exaverage"].ToString());
  1463. // _dsBroker.Completion_Total = Convert.ToInt32(row1["extotal"] == null ? "0" : row1["extotal"].ToString());
  1464. // _dsBroker.Completion_Last30 = Convert.ToInt32(row1["exlast30days"] == null ? "0" : row1["exlast30days"].ToString());
  1465. // _dsBroker.Completion_Change = Convert.ToInt32(row1["exChange"] == null ? "0" : row1["exChange"].ToString());
  1466.  
  1467. // _dsBroker.Decision_in_principle_Average = Convert.ToInt32(row1["dipaverage"] == null ? "0" : row1["dipaverage"].ToString());
  1468. // _dsBroker.Decision_in_principle_Total = Convert.ToInt32(row1["diptotal"] == null ? "0" : row1["diptotal"].ToString());
  1469. // _dsBroker.Decision_in_principle_Last30 = Convert.ToInt32(row1["diplast30days"] == null ? "0" : row1["diplast30days"].ToString());
  1470. // _dsBroker.Decision_in_principle_Change = Convert.ToInt32(row1["dipChange"] == null ? "0" : row1["dipChange"].ToString());
  1471.  
  1472. // _dsBroker.ApplicationsSubmitted_Average = Convert.ToInt32(row1["appsubaverage"] == null ? "0" : row1["appsubaverage"].ToString());
  1473. // _dsBroker.ApplicationsSubmitted_Total = Convert.ToInt32(row1["appsubtotal"] == null ? "0" : row1["appsubtotal"].ToString());
  1474. // _dsBroker.ApplicationsSubmitted_Last30 = Convert.ToInt32(row1["appsublast30days"] == null ? "0" : row1["appsublast30days"].ToString());
  1475. // _dsBroker.ApplicationsSubmitted_Change = Convert.ToInt32(row1["appChange"] == null ? "0" : row1["appChange"].ToString());
  1476.  
  1477. // clients.Add(_dsBroker);
  1478. //}
  1479. #endregion
  1480. return clients;
  1481. }
  1482. catch (Exception)
  1483. {
  1484. return clients;
  1485. }
  1486. }
  1487.  
  1488.  
  1489. CREATE PROCEDURE [dbo].[GetBrokerList]
  1490.  
  1491. @parentuserid int
  1492.  
  1493. AS
  1494. select b.brokername,
  1495.  
  1496. count(case when fs.status = 5 and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3 as dipaverage,
  1497. count(case when fs.status = 5 and fs.setdate > getdate()-30 then 1 else null end) as diplast30days,
  1498. count(case when fs.status = 5 then 1 else null end) as diptotal,
  1499. (count(case when fs.status = 5 and fs.setdate > getdate()-30 then 1 else null end) - count(case when fs.status = 5 and fs.setdate between getdate()-120 and getdat
  1500. e()-30 then 1 else null end) / 3) As dipChange,
  1501. count(case when (fs.status = 6 or fs.status = 7) and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3 as
  1502. appsubaverage,
  1503. count(case when (fs.status = 6 or fs.status = 7) and fs.setdate > getdate()-30 then 1 else null end) as appsublast30days,
  1504. count(case when (fs.status = 6 or fs.status = 7) then 1 else null end) as appsubtotal,
  1505. (count(case when (fs.status = 6 or fs.status = 7) and fs.setdate > getdate()-30 then 1 else null end) - count(case when (fs.status = 6 or fs.status =
  1506. 7) and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3) As appChange,
  1507. count(case when fs.status = 8 and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3 as exaverage,
  1508. count(case when fs.status = 8 and fs.setdate > getdate()-30 then 1 else null end) as exlast30days,
  1509. count(case when fs.status = 8 then 1 else null end) as extotal,
  1510. (count(case when fs.status = 8 and fs.setdate > getdate()-30 then 1 else null end) - count(case when fs.status = 8 and fs.setdate
  1511. between getdate()-120 and getdate()-30 then 1 else null end) / 3 ) As exChange,
  1512. max(c.created) as lastlead
  1513. from tblaccount a
  1514. inner join tblcontact c on c.account = a.accountid
  1515. inner join tbluser b on b.userid = c.broker
  1516. inner join tblfinance f on f.contact = c.contactid
  1517.  
  1518. left join tblAdminTeammebers TM ON b.userid = TM.MemberId
  1519.  
  1520. inner join (select TF.financeid as finance, TFS.statusid as status, (select top 1 createdate from tblfinance_statusdate fsd where fsd.financeid = TF.financeid and fsd.status >= TFS.statusid order by
  1521. fsd.status) as setdate
  1522.  
  1523.  
  1524.  
  1525. from tblfinance TF, tblfinancestatus TFS
  1526. where TFS.statusid in (5,6, 7,8)
  1527. ) fs on fs.finance = f.financeid
  1528.  
  1529. --where (c.account = @parentuserid or a.parent = @parentuserid or TM.AdminId = @parentuserid)
  1530. where (c.account IN ( select account from tbluser where account in
  1531. (select account from tbluser where adminid = @parentuserid) and broker = 1)
  1532. OR TM.AdminId = @parentuserid)
  1533.  
  1534. and (fs.status in (5,6, 7,8) and fs.setdate is not null)
  1535. and (f.type = 1)
  1536. group by b.brokername
  1537. order by exlast30days desc
  1538.  
  1539.  
  1540.  
  1541. public List<dbrdTotalWritten> DashboradTotalWritten(int loggedinUserAccountId, int loggedinUserId)
  1542. {
  1543. var data = ctx.dbrdTotalWrittens.Where(x => x.accountId == loggedinUserAccountId && x.userId == loggedinUserId).ToList();
  1544. return data != null ? data : new List<dbrdTotalWritten>();
  1545. }
  1546.  
  1547. public DataSet GetAllDashboardData(int loggedinUserAccountId, int loggedinUserId)
  1548. {
  1549. TiledDashboard objTiledDashboard = new TiledDashboard();
  1550. DataSet dsDashboard = objTiledDashboard.GetAllDashboardData(loggedinUserAccountId, loggedinUserId);
  1551. return dsDashboard;
  1552. }
  1553. public List<CompanyModal> GetCompany(int userId, int companyType, string companyId, string companyName)
  1554. {
  1555. List<CompanyModal> CompanyModalList = new List<CompanyModal>();
  1556. SqlParameter[] Param = new SqlParameter[4];
  1557. Param[0] = new SqlParameter("@userid", userId);
  1558. Param[1] = new SqlParameter("@companytype", companyType);
  1559. Param[2] = new SqlParameter("@companyid", companyId);
  1560. Param[3] = new SqlParameter("@companyname", companyName);
  1561.  
  1562. DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetCompany", Param);
  1563.  
  1564. CompanyModalList = (from DataRow row in dt.Rows
  1565. select new CompanyModal
  1566. {
  1567. companyid = row["companyid"].ToString(),
  1568. companyname = row["companyname"].ToString(),
  1569. companytype = row["companytype"].ToString(),
  1570. emailaddress = row["emailaddress"].ToString(),
  1571. telephone = row["telephone"].ToString()
  1572. }).OrderBy(d => d.companyname).ToList();
  1573. return CompanyModalList;
  1574. }
  1575. public int
  1576. CheckUserType(int userId, out int teamId, out int accountId, out string brokers)
  1577. {
  1578. int _uType = 0; // 1- Admin, 2- Manager, 3- Broker, 4- general User
  1579. teamId = 0;
  1580. accountId = 0;
  1581. brokers = "";
  1582. try
  1583. {
  1584. var _objU = ctx.tblusers.Where(x => x.userid == userId).FirstOrDefault();
  1585. if (_objU != null)
  1586. {
  1587. if (IsAdministrator(userId, out brokers))
  1588. {
  1589. _uType = 1;
  1590. accountId = _objU.account;
  1591.  
  1592. }
  1593. else if (IsManager(userId, out teamId, out brokers))
  1594. {
  1595. _uType = 2;
  1596. accountId = _objU.account;
  1597. }
  1598. else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && _objU.broker.HasValue && _objU.broker.Value)
  1599. {
  1600. _uType = 3;
  1601. accountId = _objU.account;
  1602. }
  1603. else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && (!_objU.broker.HasValue || !_objU.broker.Value))
  1604. {
  1605. _uType = 4;
  1606. accountId = _objU.account;
  1607. }
  1608.  
  1609.  
  1610. }
  1611. return _uType;
  1612. }
  1613. catch
  1614. { }
  1615. return _uType;
  1616. }
  1617.  
  1618. public bool IsAdministrator(int userId, out string brokers)
  1619. {
  1620. bool _chk = false;
  1621. brokers = "";
  1622. try
  1623. {
  1624. 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)))
  1625. {
  1626. _chk = true;
  1627.  
  1628. SqlParameter[] Param = new SqlParameter[1];
  1629. Param[0] = new SqlParameter("@AdminId", userId);
  1630.  
  1631. var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokersIdsByAdminId", Param);
  1632. if (dt != null && dt.Rows.Count > 0)
  1633. {
  1634. brokers = Convert.ToString(dt.Rows[0]["BrokersIds"]).Trim().TrimEnd(',');
  1635. }
  1636.  
  1637. }
  1638.  
  1639. }
  1640. catch
  1641. {
  1642. }
  1643. return _chk;
  1644. }
  1645.  
  1646. public bool IsManager(int userId, out int teamId, out string brokers)
  1647. {
  1648. bool _chk = false;
  1649. teamId = 0;
  1650. brokers = "";
  1651. try
  1652. {
  1653. if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == true && u.broker.Value == true)))
  1654. {
  1655. _chk = true;
  1656. teamId = ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault() != null ? (ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault().TeamId ?? 0) : 0;
  1657. }
  1658.  
  1659. if (teamId > 0)
  1660. {
  1661. SqlParameter[] Param = new SqlParameter[2];
  1662. Param[0] = new SqlParameter("@TeamId", teamId);
  1663.  
  1664. var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetTeamMembersIdsByTeamId", Param);
  1665. if (dt != null && dt.Rows.Count > 0)
  1666. {
  1667. brokers = Convert.ToString(dt.Rows[0]["BrokersIds"]).Trim().TrimEnd(',');
  1668. }
  1669.  
  1670. }
  1671.  
  1672. }
  1673. catch
  1674. {
  1675. }
  1676. return _chk;
  1677. }
  1678.  
  1679.  
  1680. @section css
  1681. {
  1682. <link href="@Url.Content("~/Content/css/validation.css")" rel="stylesheet" />
  1683. <style>
  1684. .subbtn {
  1685. background-image: url("Images/updatebtn.png");
  1686. border: 0 none;
  1687. height: 31px;
  1688. width: 93px;
  1689. vertical-align: top;
  1690. }
  1691. </style>
  1692. }
  1693.  
  1694. <script type="text/javascript">
  1695. function prevrow() {
  1696. var tr = $("table#apptable > tbody > tr.activerow").prev()
  1697. if (tr.length > 0)
  1698. selectrow(tr);
  1699. }
  1700.  
  1701. function nextrow() {
  1702. var tr = $("table#apptable > tbody > tr.activerow").next();
  1703. if (tr.length > 0)
  1704. selectrow(tr);
  1705. }
  1706.  
  1707. function selectrow(a) {
  1708. $("table#apptable > tbody > tr").removeClass("activerow");
  1709. $(a).addClass("activerow");
  1710. $("textarea#companyname").val($(a).attr("companyname"));
  1711. $("input#companyid").val($(a).attr("trcompanyid"));
  1712. }
  1713.  
  1714. function UpdateCompany_OnSuccess(data) {
  1715. var tr = $("table#apptable > tbody > tr.activerow");
  1716. tr.attr("companyname", data.data.companyname);
  1717. tr.attr("trcompanyid", data.data.companyname);
  1718. tr.find("td").eq(0).text(data.data.companyname);
  1719. tr.find("td").eq(1).text(data.data.companyname);
  1720. }
  1721.  
  1722. function UpdateCompany_OnComplete() {
  1723. $("#loader").hide();
  1724. }
  1725.  
  1726. function UpdateCompany_OnBegin() {
  1727. $("#loader").show();
  1728. }
  1729.  
  1730. function FilterCompany_OnSuccess(data) {
  1731. $("#divPartialView").html(data);
  1732. var tr = $("table#apptable > tbody > tr.activerow");
  1733. $("textarea#companyname").val(tr.attr("companyname"));
  1734. $("input#companyid").val(tr.attr("trcompanyid"));
  1735. }
  1736.  
  1737. function FilterCompany_OnComplete() {
  1738. $("#loader").hide();
  1739. }
  1740.  
  1741. function FilterCompany_OnBegin() {
  1742. $("#loader").show();
  1743. }
  1744. </script>
  1745. <div style="overflow: hidden">
  1746. @using (Ajax.BeginForm("Filter", "Companies", new AjaxOptions()
  1747. {
  1748. HttpMethod = "POST",
  1749. OnSuccess = "FilterCompany_OnSuccess",
  1750. OnComplete = "FilterCompany_OnComplete",
  1751. OnBegin = "FilterCompany_OnBegin",
  1752. }))
  1753. {
  1754. <div id="searchcontainer" class="contentbox" style="position: relative;">
  1755. <table>
  1756. <tbody>
  1757. <tr>
  1758. <td>
  1759. <h2>Company</h2>
  1760. </td>
  1761. </tr>
  1762. <tr>
  1763. <td>
  1764. <input type="text" name="filtercompanyname" id="filtercompanyname" class="idleField txtField" />
  1765. </td>
  1766. </tr>
  1767. </tbody>
  1768. </table>
  1769. <div style="text-align: right">
  1770. <input type="submit" value="Search Company" id="btnSearchCompany">
  1771. </div>
  1772. </div>
  1773. <div class="contentbox applicationpaging clearfix">
  1774. <div class="applicationselect clearfix">
  1775. <span style="font-size: 11pt;">Company Type:</span>
  1776. <select id="CompanyType" name="CompanyType" class="searchselect" style="font-size: 13px; width: 200px; position: absolute; opacity: 0; height: 26px;" onchange="$('#customStyleSelectBoxInnerCompanyType').text($(this).find('option:selected').text());$(this.form).submit();">
  1777. <option value="1" selected="selected">Providers</option>
  1778. <option value="2">Solicitors</option>
  1779. </select>
  1780. <span class="customStyleSelectBox" style="display: inline-block;">
  1781. <span class="customStyleSelectBoxInner" id="customStyleSelectBoxInnerCompanyType" style="width: 188px; display: inline-block;">Providers
  1782. </span>
  1783. </span>
  1784. </div>
  1785. </div>
  1786. }
  1787.  
  1788. <tbody>
  1789. @if (Model != null)
  1790. {
  1791. int rowId = 1;
  1792. foreach (var item in Model)
  1793. {
  1794. <tr class="row @(rowId % 2 == 0 ? "even" : "odd")@(rowId == 1 ? " activerow" : "")"
  1795. onmouseout="$(this).removeClass('highlightrow')"
  1796. id="@rowId"
  1797. onmouseover="$(this).addClass('highlightrow')"
  1798. onclick="selectrow(this);"
  1799. companyname="@item.companyname"
  1800. trcompanyid="@item.companyid">
  1801. <td>@item.companyid</td>
  1802. <td>@item.companyname</td>
  1803. <td>@(item.companytype == "1" ? "Providers" : "Solicitors")</td>
  1804. <td>@item.emailaddress</td>
  1805. <td>@item.telephone</td>
  1806. </tr>
  1807. rowId++;
  1808. }
  1809. }
  1810. </tbody>
Add Comment
Please, Sign In to add comment