Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array values = Enum.GetValues(typeof(Occfinance.Helpers.VisitFrequencyEnum));
- List<WSSelectListItem> VisitFrequencyList = new List<WSSelectListItem>(values.Length);
- foreach (var i in values)
- {
- VisitFrequencyList.Add(new WSSelectListItem
- {
- Text = ((VisitFrequencyEnum)i).GetEnumDescription(),
- Value = ((int)i).ToString()
- });
- }
- model.VisitFrequencyList = VisitFrequencyList;
- IEnumerable<DayListEnum> dayListEnum = Enum.GetValues(typeof(DayListEnum)).Cast<DayListEnum>();
- model.DayList = (from day in dayListEnum select new WSSelectListItem { Text = day.ToString(), Value = ((int)day).ToString() }).ToList();
- string[] _allNamesparents = hdnnamearrayparents.Split(',');
- string allNamesparents = "";
- allNamesparents = QReports.GetSelectedCompaniesWithBrokerByIds(_allNamesparents);
- string[] _allNames = QReports.GetNegotiatorsNameByIds(NegotiatorIds);
- string allNames = "";
- foreach (var name in _allNames)
- {
- if (!string.IsNullOrEmpty(name))
- allNames += System.Text.RegularExpressions.Regex.Replace(name, "[^a-zA-Z0-9]+", "", System.Text.RegularExpressions.RegexOptions.Compiled).Trim() + ",";
- }
- if (string.IsNullOrWhiteSpace(hdnnamearraybrokerNames))
- {
- if (!string.IsNullOrEmpty(allNames))
- model.Clientname = allNamesparents;
- else
- model.Clientname = "All";
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(hdnnamearraybrokerNames))
- {
- if (string.IsNullOrEmpty(allNamesparents))
- model.Clientname = "Brokers: " + hdnnamearraybrokerNames;// name.brokername;
- else
- model.Clientname = allNamesparents;
- }
- }
- if (accountId > 0)
- {
- //Clinets
- WSSelectListItem defaultentry = new WSSelectListItem();
- defaultentry.Text = "select..";
- defaultentry.Value = "0";
- defaultentry.Selected = true;
- List<WSSelectListItem> items = new List<WSSelectListItem>();
- model.BrokersWithTeams = QSettings.GetBrokersWithTeams(userId);
- List<Clients> bitems = QSettings.FindBrokerForLoggedInUserWithUserId(accountId, userId);
- var bcompanyitems = (from names in bitems
- select new
- {
- companyname = names.companyname,
- clientid = names.clientid
- }).Distinct().ToList();
- companyitems = bcompanyitems.Select(r => new WSSelectListItem() { Value = r.companyname, Text = r.companyname }).ToList();
- model.CompanyData = companyitems;
- model.BrokderBag = bitems;
- model.BrokerSelectedName = hdnnamearraybroker;
- model.ClientsNames = allNames.TrimEnd(',');
- List<Clients> cItems = QClient.FindClients(accountId, userId).OrderBy(c => c.companyname).ToList();
- items = (from Clients in cItems
- select new WSSelectListItem
- {
- Text = Clients.companyname + "(" + Clients.countLeads + ")",
- Value = Clients.clientid.ToString()
- }).ToList();
- items.Insert(0, defaultentry);
- model.ClientData = items;
- List<WSSelectListItem> negitems = new List<WSSelectListItem>();
- negitems.Insert(0, defaultentry);
- model.negotiationReport = negitems;
- var brokers = "";
- int adminaccId = 0;
- if (QApplication.IsCreatedAdminUser(accountId, userId, out adminaccId, out brokers))
- {
- if (string.IsNullOrWhiteSpace(hdnnamearraybroker))
- hdnnamearraybroker = brokers;
- userId = adminaccId;
- }
- public enum UserType
- {
- [Description("Admin")]
- Admin = 1,
- [Description("Manager")]
- Manager,
- [Description("Broker")]
- Broker,
- [Description("General User")]
- GeneralUser
- }
- _userType = _obj.CheckUserType(userId, out teamId, out _accountId, out brokersIds);
- if ((_userType == (int)UserType.Manager || _userType == (int)UserType.Broker) && string.IsNullOrWhiteSpace(hdnnamearraybroker))
- hdnnamearraybroker = Convert.ToString(userId);
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- // [System.ComponentModel.ToolboxItem(false)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- [System.Web.Script.Services.ScriptService]
- public class WebService
- {
- #region [Constructor & Declarations]
- public WebService()
- {
- appService = new ApplicationService();
- clientService = new ClientService();
- }
- public UserCredentials Credential;
- Login objLogin = new Login();
- Common objCommonClass = new Common();
- Lead objLead = new Lead();
- Client.Client objClient = new Client.Client();
- Dashboard objDashboard = new Dashboard();
- Company objCompany = new Company();
- ForgetPwd objForgetPwd = new ForgetPwd();
- ApplicationService appService = null;
- ClientService clientService = null;
- EquityService equityService = new EquityService();
- FactFindService factFindService = new FactFindService();
- IntroducerService objIntroducerService = new IntroducerService();
- ReportsService reportsService = new ReportsService();
- SettingService settingService = new SettingService();
- PipelineService pipelineService = new PipelineService();
- AccountVisitsService accountvisitService = new AccountVisitsService();
- #endregion [Constructor & Declarations]
- #region [Authentication]
- /// <summary>
- /// Authenticate user
- /// </summary>
- /// <returns></returns>
- private bool Authenticate()
- {
- if (Credential != null)
- {
- if (Credential.userName == "demoac@test.com" && Credential.password == "demooccpwd")
- return true;
- else
- return false;
- }
- else
- return false;
- }
- #endregion [Authentication]
- #region Login
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public WsLogin login(string username, string password)
- {
- WsLogin model = new WsLogin();
- int userId, accountid, userType;
- string profilePic = "", brokerName = "", usertypename = "", companyname = "";
- bool IsAuthorized = objLogin.AuthenticateUser(username, password, out userId, out accountid, out userType, out profilePic, out brokerName, out usertypename, out companyname);
- model.message = IsAuthorized ? "Successful" : "Provide valid username or password";
- model.user_id = userId.ToString();
- model.account_id = accountid.ToString();
- model.status = IsAuthorized ? "true" : "false";
- model.productType = userType.ToString();
- model.ProfilePic = profilePic;
- model.UserName = brokerName;
- model.UserTypeName = usertypename;
- model.CompanyName = companyname;
- return model;
- }
- #endregion
- #region Forget Pwd
- [WebMethod]
- [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- // [SoapHeader("Credential", Required = true)]
- public WsStatusMessage forgotpassword(string email)
- {
- WsStatusMessage model = new WsStatusMessage();
- int status = objForgetPwd.ResetPassword(email);
- model.message = status == 1 ? "Successful" : email.IsEmail() ? "Email does not exist" : "Provide valid email id";
- model.status = status == 1 ? "true" : "false";
- return model;
- }
- #endregion
- }
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- [System.Web.Script.Services.ScriptService]
- public class UserCredentials : System.Web.Services.Protocols.SoapHeader
- {
- public string userName { get; set; }
- public string password { get; set; }
- }
- public class BasicAuthHttpModule : IHttpModule
- {
- public void Dispose()
- {
- }
- public void Init(HttpApplication application)
- {
- application.AuthenticateRequest += new
- EventHandler(this.OnAuthenticateRequest);
- application.EndRequest += new
- EventHandler(this.OnEndRequest);
- }
- public void OnAuthenticateRequest(object source, EventArgs
- eventArgs)
- {
- HttpApplication app = (HttpApplication)source;
- if (!app.Context.Request.Url.OriginalString.Contains(".asmx"))
- {
- return;
- }
- string authHeader = app.Request.Headers["Authorization"];
- if (!string.IsNullOrEmpty(authHeader))
- {
- string authStr = app.Request.Headers["Authorization"];
- if (authStr == null || authStr.Length == 0)
- {
- return;
- }
- authStr = authStr.Trim();
- if (authStr.IndexOf("Basic", 0) != 0)
- {
- return;
- }
- authStr = authStr.Trim();
- string encodedCredentials = authStr.Substring(6);
- byte[] decodedBytes =
- Convert.FromBase64String(encodedCredentials);
- string s = new ASCIIEncoding().GetString(decodedBytes);
- string[] userPass = s.Split(new char[] { ':' });
- string username = userPass[0];
- string password = userPass[1];
- if (!Validate(username, password))
- {
- DenyAccess(app);
- return;
- }
- }
- else
- {
- app.Response.StatusCode = 401;
- app.Response.End();
- }
- }
- public bool Validate(string username, string password)
- {
- if (username == "demoac@test.com" && password == "demooccpwd")
- return true;
- else
- return false;
- }
- public void OnEndRequest(object source, EventArgs eventArgs)
- {
- if (HttpContext.Current.Response.StatusCode == 401)
- {
- HttpContext context = HttpContext.Current;
- context.Response.StatusCode = 401;
- context.Response.AddHeader("WWW-Authenticate", "Basic Realm");
- }
- }
- private void DenyAccess(HttpApplication app)
- {
- app.Response.StatusCode = 401;
- app.Response.StatusDescription = "Access Denied";
- app.Response.Write("401 Access Denied");
- app.CompleteRequest();
- }
- }
- public bool AuthenticateUser(string username, string password, out int userId)
- {
- bool result = false;
- userId = 0;
- try
- {
- 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
- if (!result)
- {
- 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
- if (!result)
- {
- 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
- if (!result)
- {
- 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
- }
- }
- }
- if (result)
- {
- userId = ctx.tblusers.Where(u => u.username == username.Trim() && u.password == password.Trim() && u.active == true).Select(u => u.userid).FirstOrDefault();
- }
- return result;
- }
- catch
- { }
- return result;
- }
- #endregion
- public AtendanceStatus GetAvailableHoursDays(int userId, DateTime activityDate, int year)
- {
- AtendanceStatus _AtendanceStatus = new AtendanceStatus();
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@UserId", userId);
- Param[1] = new SqlParameter("@ActivityDate", activityDate);
- Param[2] = new SqlParameter("@Year", year);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAvailableHoursDays", Param);
- try
- {
- var d = (from DataRow row in dt.Rows
- select new AtendanceStatus
- {
- AllowedDays = Convert.ToDecimal(((row["AllowedDays"] == DBNull.Value || row["AllowedDays"] == null) ? "0" : row["AllowedDays"])),
- AllowedHours = Convert.ToDecimal(((row["AllowedHours"] == DBNull.Value || row["AllowedHours"] == null) ? "0" : row["AllowedHours"])),
- UsedDays = Convert.ToDecimal(((row["UsedDays"] == DBNull.Value || row["UsedDays"] == null) ? "0" : row["UsedDays"])),
- UsedHours = Convert.ToDecimal(((row["UsedHours"] == DBNull.Value || row["UsedHours"] == null) ? "0" : row["UsedHours"])),
- }).ToList();
- if (d != null && d.Count() > 0)
- _AtendanceStatus = d[0];
- }
- catch
- {
- }
- return _AtendanceStatus ?? new AtendanceStatus();
- }
- public int GetTotalDays(int acountId)
- {
- int DefaultId = 1;
- try
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@AcountId", acountId);
- Param[1] = new SqlParameter("@DefaultId", 0);
- Param[1].Direction = ParameterDirection.Output;
- SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "GetDefaultSettings", Param);
- DefaultId = Convert.ToInt32(Param[1] != null ? Param[1].SqlValue.ToString() : "1"); // return userid
- }
- catch
- {
- }
- return DefaultId;
- }
- public void GetSetPermission(int loginUserId)
- {
- try
- {
- if (SessionWrapper.PermissionSession == null)
- {
- PermissionSession objS = new PermissionSession();
- SessionWrapper.PermissionSession = objS;
- }
- SessionWrapper.PermissionSession.UserId = loginUserId;
- Q_Application obj = new Q_Application();
- if (obj.CheckIsSuperAdmin(loginUserId) == 1)
- {
- SessionWrapper.PermissionSession.IsFullPermission = true;
- SessionWrapper.PermissionSession.IsViewAllData = true;
- SessionWrapper.PermissionSession.IsUpdateAllData = true;
- SessionWrapper.PermissionSession.IsPrintAllData = true;
- }
- else
- {
- SessionWrapper.PermissionSession.IsFullPermission = false;
- List<UserPermissionModel> _permissions = new List<UserPermissionModel>();
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@UserId", loginUserId);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "tblUserPermissionGetByUserId", Param);
- _permissions = (from DataRow row in dt.Rows
- select new UserPermissionModel
- {
- userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
- PermissionId = Convert.ToInt32(((row["PermissionId"] == DBNull.Value || row["PermissionId"] == null) ? "0" : row["PermissionId"]).ToString()),
- PermissionNames = Convert.ToString((row["PermissionName"] == DBNull.Value || row["PermissionName"] == null) ? "" : row["PermissionName"]),
- }).ToList();
- if (_permissions.Any(c => c.userid == loginUserId && c.PermissionId == (int)Permission.ViewData))
- {
- SessionWrapper.PermissionSession.IsViewAllData = true;
- }
- else
- {
- SessionWrapper.PermissionSession.IsViewAllData = false;
- }
- if (_permissions.Any(c => c.userid == loginUserId && c.PermissionId == (int)Permission.UpdateData))
- {
- SessionWrapper.PermissionSession.IsUpdateAllData = true;
- }
- else
- {
- SessionWrapper.PermissionSession.IsUpdateAllData = false;
- }
- if (_permissions.Any(c => c.userid == loginUserId && c.PermissionId == (int)Permission.PrintReport))
- {
- SessionWrapper.PermissionSession.IsPrintAllData = true;
- }
- else
- {
- SessionWrapper.PermissionSession.IsPrintAllData = false;
- }
- }
- }
- catch
- {
- }
- }
- public Clients FindClientByLoggedUser(int userId)
- {
- Clients result = new Clients();
- bool flag = false;
- try
- {
- flag = ctx.tblusers.Any(d => d.userid == userId && d.active == true && d.broker.HasValue && d.broker.Value == true);
- if (flag == true)
- {
- result = ctx.tblusers.Where(u => u.userid == userId && u.active == true).Select(u => new Clients()
- {
- clientid = u.account,
- parent = u.tblaccount.parent,
- companyname = u.tblaccount.companyname,
- affiliateid = u.tblaccount.affiliateid,
- telephone = u.tblaccount.telephone,
- email = u.username,
- contactname = u.brokername,
- address = u.tblaccount.address,
- username = u.brokername,
- PrimaryContact = u.PrimaryContact,
- SecondaryContact = u.SecondaryContact,
- Address1 = u.Address1,
- Address2 = u.Address2,
- OtherDetails = u.OtherDetails,
- Title = u.Title,
- FAX = u.FAX,
- Qualification = u.Qualification,
- countLeads = u.tblaccount.tblcontacts.Count()
- }).FirstOrDefault();
- }
- else
- {
- // This is for the general user
- 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)))
- {
- result = ctx.tblusers.Where(u => u.userid == userId && u.active == true).Select(u => new Clients()
- {
- clientid = u.account,
- parent = u.tblaccount.parent,
- companyname = u.tblaccount.companyname,
- affiliateid = u.tblaccount.affiliateid,
- telephone = u.tblaccount.telephone,
- email = u.username,
- contactname = u.brokername,
- address = u.tblaccount.address,
- username = u.brokername,
- PrimaryContact = u.PrimaryContact,
- SecondaryContact = u.SecondaryContact,
- Address1 = u.Address1,
- Address2 = u.Address2,
- OtherDetails = u.OtherDetails,
- Title = u.Title,
- FAX = u.FAX,
- Qualification = u.Qualification,
- countLeads = u.tblaccount.tblcontacts.Count()
- }).FirstOrDefault();
- }
- else
- {
- result = ctx.tblusers.Where(u => u.userid == userId && !u.tblaccount.parent.HasValue && u.active == true).Select(u => new Clients()
- {
- clientid = u.account,
- parent = u.tblaccount.parent,
- companyname = u.tblaccount.companyname,
- affiliateid = u.tblaccount.affiliateid,
- telephone = u.tblaccount.telephone,
- email = u.username,
- contactname = u.brokername,
- address = u.tblaccount.address,
- username = u.brokername,
- PrimaryContact = u.PrimaryContact,
- SecondaryContact = u.SecondaryContact,
- Address1 = u.Address1,
- Address2 = u.Address2,
- OtherDetails = u.OtherDetails,
- Title = u.Title,
- FAX = u.FAX,
- Qualification = u.Qualification,
- countLeads = u.tblaccount.tblcontacts.Count()
- }).FirstOrDefault();
- }
- }
- return result;
- }
- catch (Exception)
- {
- return result;
- }
- }
- public bool IsManager(int userId, out int teamId, out string brokers)
- {
- bool _chk = false;
- teamId = 0;
- brokers = "";
- try
- {
- 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)))
- {
- _chk = true;
- teamId = ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault() != null ? (ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault().TeamId ?? 0) : 0;
- }
- if (teamId > 0)
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@TeamId", teamId);
- var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetTeamMembersIdsByTeamId", Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- brokers = Convert.ToString(dt.Rows[0]["BrokersIds"]).Trim().TrimEnd(',');
- }
- }
- }
- catch
- {
- }
- return _chk;
- }
- using Code;
- using MailChimp;
- using Mandrill;
- using Occfinance.Code;
- using Occfinance.Common;
- using Occfinance.Models;
- using Occfinance_Data;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Web;
- //using Codes;
- using System.IO;
- using System.Configuration;
- using Occfinance.Services.Services.Helpers;
- using Occfinance.Services.Services.Application;
- namespace Occfinance.Services.Services
- {
- public class MailServices
- {
- db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
- Q_Application QApplication = new Q_Application();
- List<Occfinance.Models.StatusCount> _listStatusCount = new List<Occfinance.Models.StatusCount>();
- 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 )
- {
- int _chk = 0;
- var _contentURL = "occfinance.com";
- try
- {
- if (string.IsNullOrWhiteSpace(subject))
- subject = "Mail From OCC Finance";
- string _McAPIKey = Convert.ToString(ConfigurationManager.AppSettings["MailChimpApikey"] ?? "");
- MailChimpManager _mcmanager = new MailChimpManager(Convert.ToString(ConfigurationManager.AppSettings["MailChimpApikey"] ?? ""));
- var _mailDrilEmails = new List<EmailAddress>();
- var _mandrillMessage = new List<EmailMessage>();
- List<ManDRILLModel> _mandrillOBJ = new List<ManDRILLModel>();
- if (chk == 1)
- {
- AddUpdate(templateid, name, subject, body, userid, useraccountid);
- }
- IQueryable<ApplicationLead> allLead = null;
- allLead = QApplication.GetAllLead(out _listStatusCount, useraccountid.StringToInt(), userid.StringToInt(), filter.financetype, "", filter.ClientID, filter.Broker, filter.Status, filter.Lender, filter.Solicitor, filter.RequiredFolloUp);
- //Get new latest NoteId *****************************
- Q_Application _qA = new Q_Application();
- //int _noteid = _qA.getNoteID();
- //***************************************************
- if (!string.IsNullOrWhiteSpace(EmailId) && FinanceId != 0 && toall == 0)
- {
- //int typeid = Convert.ToInt32(Session["DefaultsettingId"] ?? 1);
- //int loggedinuser = Convert.ToInt32(Session["LoggedInUserId"] ?? "0");
- // Q_Application QApplication = new Q_Application();
- //List<StatusCount> _listStatusCount = new List<StatusCount>();
- //allLead = QApplication.GetAllLead(out _listStatusCount, Convert.ToInt32(Session["LoggedInUserAccountId"]), loggedinuser, typeid, Convert.ToString(Session["Search"] ?? ""), 0, "", "", "", "", 0);
- var obj = new ApplicationJsonLead();
- if (allLead == null)
- {
- var objMain = ctx.tblfinances.Where(c => c.financeid == FinanceId).FirstOrDefault();
- obj = QApplication.GetSingleLead(0, objMain.contact ?? 0, objMain.financeid);
- }
- else
- {
- var objMain = allLead.Where(c => c.financeid == FinanceId).FirstOrDefault();
- obj = QApplication.GetSingleLead(objMain.AccountId, objMain.contactId, objMain.financeid);
- }
- bool IsUnsubscribed = false;
- //Check if contact is unsubscribed 2014-11-20
- if (WebUtility.UnsubscribeEmail(obj.contactId, 3) == 3)
- {
- return -3;
- }
- if (obj != null)
- {
- string _mailcontent = MailContentTemplate(
- body,
- obj.firstName,
- obj.lastName,
- (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
- obj.tel, _usertel, _userName, _useremail,
- obj.brokerName ?? "",
- 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) ?? "");
- //Add Notes to the note table**************************************************
- string HTML_TAG_PATTERN = @"<[^>]+>| ";
- // Create the email parameter
- try
- {
- _mailDrilEmails = new List<EmailAddress>();
- EmailAddress objEm = new EmailAddress();
- objEm.email = EmailId;
- objEm.name = obj.firstName + " " + obj.lastName;
- _mailDrilEmails.Add(objEm);
- //Man DRILL ********************************************************************
- EmailMessage message = new EmailMessage();
- message.to = _mailDrilEmails;
- message.html = _mailcontent;
- message.from_email = obj.BrokerEmail ?? "";
- message.from_name = obj.brokerName ?? "";
- message.subject = subject;
- message.inline_css = true;
- message.signing_domain = _contentURL;
- message.AddHeader("X-MC-SigningDomain", _contentURL);
- message.AddHeader("X-MC-TrackingDomain", _contentURL);
- _mandrillMessage.Add(message);
- //********************************************************************************
- // Manage The ManDRILLModel - 25-07-2014
- var objMAN = new ManDRILLModel();
- objMAN.contactId = obj.contactId;
- objMAN.financeid = obj.financeid;
- objMAN.mailcontent = _mailcontent;
- objMAN.MandrillMSG = message;
- objMAN.IsAppContact = false;
- objMAN.TemplateName = name;
- objMAN.Status = obj.status ?? 0;
- objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
- _mandrillOBJ.Add(objMAN);
- }
- catch
- {
- }
- // Track Mail
- if (!string.IsNullOrWhiteSpace(obj.OtherApplicantEmail))
- {
- if (!EmailId.GetString().Equals(obj.OtherApplicantEmail.GetString(), StringComparison.OrdinalIgnoreCase))
- {
- string _mailcontentother = MailContentTemplate(
- body,
- obj.OtherApplicantFname,
- obj.OtherApplicantSName,
- (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
- obj.OtherApplicantMobile,
- _usertel, _userName, _useremail,
- obj.brokerName ?? "",
- 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) ?? "");
- // This below functiona to subscribe the user into the mail chimp (Need to add functionality through Mail Chimp)
- // Create the email parameter
- try
- {
- _mailDrilEmails = new List<EmailAddress>();
- EmailAddress objEm = new EmailAddress();
- objEm.email = obj.OtherApplicantEmail;
- objEm.name = obj.OtherApplicantFname + " " + obj.OtherApplicantSName;
- _mailDrilEmails.Add(objEm);
- //Man DRILL ********************************************************************
- EmailMessage message = new EmailMessage();
- message.to = _mailDrilEmails;
- message.html = _mailcontentother;
- message.from_email = obj.BrokerEmail ?? "";
- message.from_name = obj.brokerName ?? "";
- message.subject = subject;
- message.inline_css = true;
- message.signing_domain = _contentURL;
- message.AddHeader("X-MC-SigningDomain", _contentURL);
- message.AddHeader("X-MC-TrackingDomain", _contentURL);
- _mandrillMessage.Add(message);
- // Manage The ManDRILLModel - 25-07-2014
- var objMAN = new ManDRILLModel();
- objMAN.contactId = obj.contactId;
- objMAN.financeid = 0;
- objMAN.mailcontent = _mailcontentother;
- objMAN.MandrillMSG = message;
- objMAN.IsAppContact = true;
- objMAN.Status = obj.status ?? 0;
- objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
- objMAN.TemplateName = name;
- _mandrillOBJ.Add(objMAN);
- //
- }
- catch
- {
- }
- // Track Mail
- }
- }
- }
- if (WebUtility.SendMailViaManDRILL(_mandrillOBJ, loggedinuserid, followUp))
- _chk = 1;
- }
- else if (toall == 2 && ContactArray != null && ContactArray.Count() > 0)
- {
- //List<MailSentStatus> _listMailStatus = new List<MailSentStatus>();
- //_listMailStatus = allLead.Select(c => new MailSentStatus
- //{
- // EmailId = c.email,
- // Status = 0
- //}).Distinct().ToList().Where(c => !string.IsNullOrWhiteSpace(c.EmailId)).ToList();
- //***************************************************************************
- var count = 0;
- List<int> lstContactIds = new List<int>();
- List<string> emails = new List<string>();
- foreach (var objC in ContactArray)
- {
- // var obj = allLead.Where(c => c.financeid == objC.financeid).FirstOrDefault();
- FinanceId = objC.financeid;
- var obj = new ApplicationJsonLead();
- if (allLead == null)
- {
- var objMain = ctx.tblfinances.Where(c => c.financeid == FinanceId).FirstOrDefault();
- obj = QApplication.GetSingleLead(0, objMain.contact ?? 0, objMain.financeid);
- }
- else
- {
- var objMain = allLead.Where(c => c.financeid == FinanceId).FirstOrDefault();
- obj = QApplication.GetSingleLead(objMain.AccountId, objMain.contactId, objMain.financeid);
- }
- List<int> lstContactId = new List<int>();
- //Check for unsubscribed contacts 2014-11-20
- if (WebUtility.UnsubscribeEmail(objC.contactid, 3) != 3)
- {
- string _mailcontent = MailContentTemplate(
- body,
- obj.firstName,
- obj.lastName,
- (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
- obj.tel,
- _userName,_usertel, _useremail,
- obj.brokerName ?? "",
- 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) ?? "");
- 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
- {
- try
- {
- // check if email exists
- if (!emails.Contains(obj.email))
- {
- emails.Add(obj.email);
- //Add Notes to the note table**************************************************
- string HTML_TAG_PATTERN = @"<[^>]+>| ";
- _mailDrilEmails = new List<EmailAddress>();
- EmailAddress objEm = new EmailAddress();
- objEm.email = obj.email;
- objEm.name = obj.firstName + " " + obj.lastName;
- _mailDrilEmails.Add(objEm);
- //Man DRILL ********************************************************************
- EmailMessage message = new EmailMessage();
- message.to = _mailDrilEmails;
- message.html = _mailcontent;
- message.from_email = obj.BrokerEmail ?? "";
- message.from_name = obj.brokerName ?? "";
- message.subject = subject;
- message.inline_css = true;
- message.signing_domain = _contentURL;
- message.AddHeader("X-MC-SigningDomain", _contentURL);
- message.AddHeader("X-MC-TrackingDomain", _contentURL);
- _mandrillMessage.Add(message);
- // Manage The ManDRILLModel - 25-07-2014
- var objMAN = new ManDRILLModel();
- objMAN.contactId = obj.contactId;
- objMAN.financeid = obj.financeid;
- objMAN.mailcontent = _mailcontent;
- objMAN.MandrillMSG = message;
- objMAN.IsAppContact = false;
- objMAN.Status = obj.status ?? 0;
- objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
- objMAN.TemplateName = name;
- _mandrillOBJ.Add(objMAN);
- }
- }
- catch
- {
- }
- }
- //******************************************************************************
- // ****************************** Send Mail to other Applicant ******************************
- if (!string.IsNullOrWhiteSpace(obj.OtherApplicantEmail))
- {
- if (!emails.Contains(obj.OtherApplicantEmail))
- {
- // check for other application email
- if (!obj.email.GetString().Equals(obj.OtherApplicantEmail.GetString(), StringComparison.OrdinalIgnoreCase))
- {
- emails.Add(obj.OtherApplicantEmail);
- string _mailcontentother = MailContentTemplate(
- body,
- obj.OtherApplicantFname,
- obj.OtherApplicantSName,
- (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
- obj.OtherApplicantMobile,
- _userName, _usertel, _useremail,
- obj.brokerName ?? "",
- 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) ?? "");
- try
- {
- _mailDrilEmails = new List<EmailAddress>();
- EmailAddress objEm = new EmailAddress();
- objEm.email = obj.OtherApplicantEmail;
- objEm.name = obj.OtherApplicantFname + " " + obj.OtherApplicantSName;
- _mailDrilEmails.Add(objEm);
- //Man DRILL ********************************************************************
- EmailMessage message = new EmailMessage();
- message.to = _mailDrilEmails;
- message.html = _mailcontentother;
- message.from_email = obj.BrokerEmail ?? "";
- message.from_name = obj.brokerName ?? "";
- message.subject = subject;
- message.inline_css = true;
- message.signing_domain = _contentURL;
- message.AddHeader("X-MC-SigningDomain", _contentURL);
- message.AddHeader("X-MC-TrackingDomain", _contentURL);
- _mandrillMessage.Add(message);
- var objMAN = new ManDRILLModel();
- objMAN.contactId = obj.OtherApplicantId;
- objMAN.financeid = 0;
- objMAN.mailcontent = _mailcontentother;
- objMAN.MandrillMSG = message;
- objMAN.IsAppContact = true;
- objMAN.notemsg = "";
- objMAN.TemplateName = name;
- objMAN.Status = obj.status ?? 0;
- _mandrillOBJ.Add(objMAN);
- }
- catch
- {
- }
- }
- }
- }
- }
- else
- {
- lstContactIds.Add(objC.contactid);
- count++;
- }
- }
- _mandrillOBJ = _mandrillOBJ.FindAll(res => !lstContactIds.Contains(res.contactId));
- if (WebUtility.SendMailViaManDRILL(_mandrillOBJ, loggedinuserid, followUp))
- _chk = 1;
- //If all the contacts are unsubscribed
- if (ContactArray.Count() == count)
- _chk = -3;
- }
- else if (toall == 1)
- {
- if (allLead == null)
- {
- _chk = -2;
- return _chk;
- }
- if (!IsMortgageClientInclude)
- {
- int userId = Convert.ToInt32(userid ?? "0");
- allLead = allLead.Where(x => x.brokerId == userId).AsQueryable();
- }
- // Mail To Send All Contacts as per Live Server *************************************
- ////Get all distinct Emails****************************************************
- //List<MailSentStatus> _listMailStatus = new List<MailSentStatus>();
- //_listMailStatus = allLead.Select(c => new MailSentStatus
- //{
- // EmailId = c.email,
- // Status = 0
- //}).Distinct().ToList().Where(c => !string.IsNullOrWhiteSpace(c.EmailId)).ToList();
- //***************************************************************************
- var count = 0;
- List<string> emails = new List<string>();
- List<int> lstContactIds = new List<int>();
- foreach (var objMain in allLead)
- {
- //if (WebUtility.UnsubscribeEmail(objMain.contactId, 3) == 3)
- //{
- // count++;
- // lstContactIds.Add(objMain.contactId);
- // continue;
- //}
- //Added for Latest Data-----------------------
- var obj = QApplication.GetSingleLead(objMain.AccountId, objMain.contactId, objMain.financeid);
- //Check for unsubscribed contacts 2014-11-20
- if (WebUtility.UnsubscribeEmail(objMain.contactId, 3) != 3)
- {
- string _mailcontent = MailContentTemplate(
- body,
- obj.firstName,
- obj.lastName,
- (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
- obj.tel,
- _userName, _usertel, _useremail,
- obj.brokerName ?? "",
- 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) ?? "");
- 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
- {
- try
- {
- // check if not exists
- if (!emails.Contains(obj.email))
- {
- emails.Add(obj.email);
- //Add Notes to the note table**************************************************
- string HTML_TAG_PATTERN = @"<[^>]+>| ";
- _mailDrilEmails = new List<EmailAddress>();
- EmailAddress objEm = new EmailAddress();
- objEm.email = obj.email;
- objEm.name = obj.firstName + " " + obj.lastName;
- _mailDrilEmails.Add(objEm);
- //Man DRILL ********************************************************************
- EmailMessage message = new EmailMessage();
- message.to = _mailDrilEmails;
- message.html = _mailcontent;
- message.from_email = obj.BrokerEmail ?? "";
- message.from_name = obj.brokerName ?? "";
- message.subject = subject;
- message.inline_css = true;
- message.signing_domain = _contentURL;
- message.AddHeader("X-MC-SigningDomain", _contentURL);
- message.AddHeader("X-MC-TrackingDomain", _contentURL);
- _mandrillMessage.Add(message);
- // Manage The ManDRILLModel - 25-07-2014
- var objMAN = new ManDRILLModel();
- objMAN.contactId = obj.contactId;
- objMAN.financeid = obj.financeid;
- objMAN.mailcontent = _mailcontent;
- objMAN.MandrillMSG = message;
- objMAN.IsAppContact = false;
- objMAN.TemplateName = name;
- objMAN.Status = obj.status ?? 0;
- objMAN.notemsg = "Email correspondence sent : " + System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(_mailcontent, HTML_TAG_PATTERN, " "), @"\s{2,}", " ");
- _mandrillOBJ.Add(objMAN);
- }
- }
- catch
- {
- }
- }
- //******************************************************************************
- // ****************************** Send Mail to other Applicant ******************************
- if (!string.IsNullOrWhiteSpace(obj.OtherApplicantEmail))
- {
- if (!emails.Contains(obj.OtherApplicantEmail))
- {
- // check for other application email
- if (!obj.email.GetString().Equals(obj.OtherApplicantEmail.GetString(), StringComparison.OrdinalIgnoreCase))
- {
- emails.Add(obj.OtherApplicantEmail);
- string _mailcontentother = MailContentTemplate(
- body,
- obj.OtherApplicantFname,
- obj.OtherApplicantSName,
- (obj.followUp.HasValue ? obj.followUp.Value.ToString("dd/MM/yyyy") : "").ToString(),
- obj.OtherApplicantMobile,
- _userName, _usertel, _useremail,
- obj.brokerName ?? "",
- 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) ?? "");
- try
- {
- _mailDrilEmails = new List<EmailAddress>();
- EmailAddress objEm = new EmailAddress();
- objEm.email = obj.OtherApplicantEmail;
- objEm.name = obj.OtherApplicantFname + " " + obj.OtherApplicantSName;
- _mailDrilEmails.Add(objEm);
- //Man DRILL ********************************************************************
- EmailMessage message = new EmailMessage();
- message.to = _mailDrilEmails;
- message.html = _mailcontent;
- message.from_email = obj.BrokerEmail ?? "";
- message.from_name = obj.brokerName ?? "";
- message.subject = subject;
- message.inline_css = true;
- message.signing_domain = _contentURL;
- message.AddHeader("X-MC-SigningDomain", _contentURL);
- message.AddHeader("X-MC-TrackingDomain", _contentURL);
- _mandrillMessage.Add(message);
- // Manage The ManDRILLModel - 25-07-2014
- var objMAN = new ManDRILLModel();
- objMAN.contactId = obj.OtherApplicantId;
- objMAN.financeid = 0;
- objMAN.mailcontent = _mailcontent;
- objMAN.MandrillMSG = message;
- objMAN.IsAppContact = false;
- objMAN.notemsg = "";
- objMAN.TemplateName = name;
- objMAN.Status = obj.status ?? 0;
- _mandrillOBJ.Add(objMAN);
- }
- catch
- {
- }
- }
- }
- }
- }
- else
- {
- lstContactIds.Add(objMain.contactId);
- count++;
- }
- //********************************************************* Other Applicant ******************************
- }
- //*********************************************************END**************************************************************************
- _mandrillOBJ = _mandrillOBJ.FindAll(res => !lstContactIds.Contains(res.contactId));
- if (WebUtility.SendMailViaManDRILLForBulkEmail(_mandrillOBJ, loggedinuserid, followUp))
- _chk = 1;
- if (allLead.Count() == count)
- _chk = -3;
- }
- }
- catch
- {
- throw;
- }
- return _chk;
- }
- public int AddUpdate(int templateid, string name, string subject, string body, string userId, string accountId)
- {
- int chk = 0;
- string _connectionstring = Convert.ToString(ConfigurationManager.ConnectionStrings["ConString1"]);
- try
- {
- var _userId = Convert.ToInt32(userId ?? "0");
- var _accountId = Convert.ToInt32(accountId ?? "0");
- if (templateid > 0)
- {
- using (SqlConnection con = new SqlConnection(_connectionstring))
- {
- using (SqlCommand cmd = new SqlCommand("MailTemplateUpdate", con))
- {
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@UserId", _userId);
- cmd.Parameters.AddWithValue("@TemplateId", templateid);
- cmd.Parameters.AddWithValue("@TemplateName", name);
- cmd.Parameters.AddWithValue("@Subject", subject);
- cmd.Parameters.AddWithValue("@Templates", body);
- cmd.Parameters.Add("@Chk", SqlDbType.Int);
- cmd.Parameters["@Chk"].Direction = ParameterDirection.Output;
- con.Open();
- cmd.ExecuteNonQuery();
- chk = Convert.ToInt32(cmd.Parameters["@Chk"].SqlValue.ToString());
- con.Close();
- con.Dispose();
- }
- }
- }
- else
- {
- using (SqlConnection con = new SqlConnection(_connectionstring))
- {
- using (SqlCommand cmd = new SqlCommand("MailTemplateAdd", con))
- {
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@UserId", _userId);
- cmd.Parameters.AddWithValue("@AccountId", _accountId);
- cmd.Parameters.AddWithValue("@TemplateName", name);
- cmd.Parameters.AddWithValue("@Subject", subject);
- cmd.Parameters.AddWithValue("@Templates", body);
- cmd.Parameters.Add("@TemplateId", SqlDbType.Int);
- cmd.Parameters["@TemplateId"].Direction = ParameterDirection.Output;
- con.Open();
- cmd.ExecuteNonQuery();
- chk = Convert.ToInt32(cmd.Parameters["@TemplateId"].SqlValue.ToString());
- con.Close();
- con.Dispose();
- }
- }
- }
- }
- catch
- {
- throw;
- }
- return chk;
- }
- 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)
- {
- StringBuilder _tempate = new StringBuilder();
- try
- {
- string siteUrl = Convert.ToString(ConfigurationManager.AppSettings["SecureURL"] ?? "http://secure.occfinance.com/");
- _tempate.Append(mailcontent);
- _tempate = _tempate
- .Replace("*|FNAME|*", FName)
- .Replace("*|LNAME|*", LName)
- .Replace("*|CONTTEL|*", contacttel)
- .Replace("*|UNAME|*", username)
- .Replace("*|UEMAIL|*", useremail)
- .Replace("*|UTEL|*", usertel)
- .Replace("*|FDATE|*", followupdate)
- .Replace("*|ADVISERN|*", brokername)
- .Replace("*|ADVISERQ|*", Qualification)
- .Replace("*|CNAME|*", CompanyName)
- .Replace("*|ADVISEREMA|*", BrokerEmail)
- .Replace("*|PNUM|*", PolicyNumber)
- .Replace("*|PRVNAME|*", ProviderName)
- .Replace("*|SNAME|*", SolicitorName)
- .Replace("*|ADVISERTEL|*", PrimaryContact)
- .Replace("*|ADVISERMOB|*", SecondaryContact)
- .Replace("*|ADVSRAD1|*", Address1)
- .Replace("*|ADVSRAD2|*", Address2)
- .Replace("*|ADVSRODL|*", OtherDetails)
- .Replace("*|ADVISERFAX|*", FAX)
- .Replace("*|ADVISERTTL|*", Title)
- .Replace("*|DISCLAIMER|*", "")
- .Replace("*|COMPANYURL|*", "")
- .Replace("*|MC:SUBJECT|*", "")
- .Replace("*|MSGBODY|*", "")
- .Replace("*|UNSUB|*", siteUrl + "/Home/UnsubscribeEmails?contactId=" + ContactId + "&type=1");
- }
- catch
- {
- throw;
- }
- return _tempate.ToString();
- }
- //public class ContactMail
- //{
- // public int financeid { get; set; }
- // public int contactid { get; set; }
- //}
- }
- }
- public AtendanceStatus GetAvailableHoursDays(int userId, DateTime activityDate, int year)
- {
- AtendanceStatus _AtendanceStatus = new AtendanceStatus();
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@UserId", userId);
- Param[1] = new SqlParameter("@ActivityDate", activityDate);
- Param[2] = new SqlParameter("@Year", year);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAvailableHoursDays", Param);
- try
- {
- var d = (from DataRow row in dt.Rows
- select new AtendanceStatus
- {
- AllowedDays = Convert.ToDecimal(((row["AllowedDays"] == DBNull.Value || row["AllowedDays"] == null) ? "0" : row["AllowedDays"])),
- AllowedHours = Convert.ToDecimal(((row["AllowedHours"] == DBNull.Value || row["AllowedHours"] == null) ? "0" : row["AllowedHours"])),
- UsedDays = Convert.ToDecimal(((row["UsedDays"] == DBNull.Value || row["UsedDays"] == null) ? "0" : row["UsedDays"])),
- UsedHours = Convert.ToDecimal(((row["UsedHours"] == DBNull.Value || row["UsedHours"] == null) ? "0" : row["UsedHours"])),
- }).ToList();
- if (d != null && d.Count() > 0)
- _AtendanceStatus = d[0];
- }
- catch
- {
- }
- return _AtendanceStatus ?? new AtendanceStatus();
- }
- public static bool SendMailMessage(System.String To, System.String Bcc, System.String Cc, System.String Subject, System.String Message, string attachmentPath = "", string frommail = "")
- {
- if (
- string.IsNullOrEmpty(To) ||
- string.IsNullOrEmpty(Subject) ||
- string.IsNullOrEmpty(Message)
- )
- return false;
- System.String From = !string.IsNullOrWhiteSpace(frommail) ? frommail : ConfigurationManager.AppSettings["SMTP_FROM"].ToString();
- try
- {
- SendNetMail(From, To, Bcc, Cc, Subject, Message, attachmentPath);
- return true;
- }
- catch
- {
- try
- {
- SendWebMail(From, To, Bcc, Cc, Subject, Message, attachmentPath);
- return true;
- }
- catch
- {
- try
- {
- System.Web.Mail.MailMessage MM = new System.Web.Mail.MailMessage();
- MM.From = From;
- MM.Subject = Subject;
- MM.To = To;
- if (!string.IsNullOrEmpty(Cc))
- MM.Cc = Cc;
- if (!string.IsNullOrEmpty(Bcc))
- MM.Bcc = Bcc;
- if (!string.IsNullOrEmpty(attachmentPath))
- {
- System.Web.Mail.MailAttachment attch = new MailAttachment(attachmentPath);
- MM.Attachments.Add(attch);
- }
- MM.Body = Message;
- MM.BodyFormat = System.Web.Mail.MailFormat.Html;
- System.Web.Mail.SmtpMail.Send(MM);
- return true;
- }
- catch
- {
- return false;
- }
- }
- }
- }
- public int ResetPassword(string email)
- {
- int status = 0;
- try
- {
- if (!ctx.tblusers.Where(c => c.username.ToLower().Trim() == email.ToLower().Trim()).Any())
- {
- status = 0;
- }
- else
- {
- var data = ctx.tblusers.Where(c => c.username.ToLower().Trim() == email.ToLower().Trim()).FirstOrDefault();
- if (data != null)
- {
- string body = "Hi, <br /><br />";
- body += "Your Password is: " + data.password + "<br />";
- body += "Regards: <br />";
- body += "Administrator <br />";
- body += "OCC Finance<br />";
- System.Threading.Tasks.Task.Run(() =>
- {
- MailHelper.SendMailMessage(email, "", "", "Password Request", body);
- });
- status = 1;
- }
- }
- }
- catch
- {
- throw;
- }
- return status;
- }
- public List<DashboardBrokers> FindDashboardBrokers(int parentUserId, int userId = 0)
- {
- bool flag = false;
- List<DashboardBrokers> clients = new List<DashboardBrokers>();
- try
- {
- var userAccount = ctx.tblaccounts.Where(u => u.parent.HasValue && u.parent.Value == parentUserId).Select(u => u.accountid).ToList();
- // var account = ctx.tblusers.Where(u => u.broker.HasValue && u.broker.Value == true && userAccount.Contains(u.account) == true).Select(u => u).ToList();
- var account = ctx.tblusers.Where(u => u.broker.HasValue && u.broker.Value == true && u.account == parentUserId).Select(u => u).ToList();
- //if (userId > 0)
- // account = account.Where(c => c.userid == userId).ToList();
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@parentuserid", parentUserId);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokerList", Param);
- if (dt != null)
- {
- clients = (from DataRow row1 in dt.Rows
- select new DashboardBrokers()
- {
- contactname = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString()),
- Completion_Average = Convert.ToInt32(row1["exaverage"] == null ? "0" : row1["exaverage"].ToString()),
- Completion_Total = Convert.ToInt32(row1["extotal"] == null ? "0" : row1["extotal"].ToString()),
- Completion_Last30 = Convert.ToInt32(row1["exlast30days"] == null ? "0" : row1["exlast30days"].ToString()),
- Completion_Change = Convert.ToInt32(row1["exChange"] == null ? "0" : row1["exChange"].ToString()),
- Decision_in_principle_Average = Convert.ToInt32(row1["dipaverage"] == null ? "0" : row1["dipaverage"].ToString()),
- Decision_in_principle_Total = Convert.ToInt32(row1["diptotal"] == null ? "0" : row1["diptotal"].ToString()),
- Decision_in_principle_Last30 = Convert.ToInt32(row1["diplast30days"] == null ? "0" : row1["diplast30days"].ToString()),
- Decision_in_principle_Change = Convert.ToInt32(row1["dipChange"] == null ? "0" : row1["dipChange"].ToString()),
- ApplicationsSubmitted_Average = Convert.ToInt32(row1["appsubaverage"] == null ? "0" : row1["appsubaverage"].ToString()),
- ApplicationsSubmitted_Total = Convert.ToInt32(row1["appsubtotal"] == null ? "0" : row1["appsubtotal"].ToString()),
- ApplicationsSubmitted_Last30 = Convert.ToInt32(row1["appsublast30days"] == null ? "0" : row1["appsublast30days"].ToString()),
- ApplicationsSubmitted_Change = Convert.ToInt32(row1["appChange"] == null ? "0" : row1["appChange"].ToString())
- }).ToList();
- }
- #region
- //foreach (DataRow row1 in dt.Rows)
- //{
- // DashboardBrokers _dsBroker = new DashboardBrokers();
- // _dsBroker.contactname = Convert.ToString(row1["brokername"] == null ? "" : row1["brokername"].ToString());
- // _dsBroker.Completion_Average = Convert.ToInt32(row1["exaverage"] == null ? "0" : row1["exaverage"].ToString());
- // _dsBroker.Completion_Total = Convert.ToInt32(row1["extotal"] == null ? "0" : row1["extotal"].ToString());
- // _dsBroker.Completion_Last30 = Convert.ToInt32(row1["exlast30days"] == null ? "0" : row1["exlast30days"].ToString());
- // _dsBroker.Completion_Change = Convert.ToInt32(row1["exChange"] == null ? "0" : row1["exChange"].ToString());
- // _dsBroker.Decision_in_principle_Average = Convert.ToInt32(row1["dipaverage"] == null ? "0" : row1["dipaverage"].ToString());
- // _dsBroker.Decision_in_principle_Total = Convert.ToInt32(row1["diptotal"] == null ? "0" : row1["diptotal"].ToString());
- // _dsBroker.Decision_in_principle_Last30 = Convert.ToInt32(row1["diplast30days"] == null ? "0" : row1["diplast30days"].ToString());
- // _dsBroker.Decision_in_principle_Change = Convert.ToInt32(row1["dipChange"] == null ? "0" : row1["dipChange"].ToString());
- // _dsBroker.ApplicationsSubmitted_Average = Convert.ToInt32(row1["appsubaverage"] == null ? "0" : row1["appsubaverage"].ToString());
- // _dsBroker.ApplicationsSubmitted_Total = Convert.ToInt32(row1["appsubtotal"] == null ? "0" : row1["appsubtotal"].ToString());
- // _dsBroker.ApplicationsSubmitted_Last30 = Convert.ToInt32(row1["appsublast30days"] == null ? "0" : row1["appsublast30days"].ToString());
- // _dsBroker.ApplicationsSubmitted_Change = Convert.ToInt32(row1["appChange"] == null ? "0" : row1["appChange"].ToString());
- // clients.Add(_dsBroker);
- //}
- #endregion
- return clients;
- }
- catch (Exception)
- {
- return clients;
- }
- }
- CREATE PROCEDURE [dbo].[GetBrokerList]
- @parentuserid int
- AS
- select b.brokername,
- count(case when fs.status = 5 and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3 as dipaverage,
- count(case when fs.status = 5 and fs.setdate > getdate()-30 then 1 else null end) as diplast30days,
- count(case when fs.status = 5 then 1 else null end) as diptotal,
- (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
- e()-30 then 1 else null end) / 3) As dipChange,
- 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
- appsubaverage,
- count(case when (fs.status = 6 or fs.status = 7) and fs.setdate > getdate()-30 then 1 else null end) as appsublast30days,
- count(case when (fs.status = 6 or fs.status = 7) then 1 else null end) as appsubtotal,
- (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 =
- 7) and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3) As appChange,
- count(case when fs.status = 8 and fs.setdate between getdate()-120 and getdate()-30 then 1 else null end) / 3 as exaverage,
- count(case when fs.status = 8 and fs.setdate > getdate()-30 then 1 else null end) as exlast30days,
- count(case when fs.status = 8 then 1 else null end) as extotal,
- (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
- between getdate()-120 and getdate()-30 then 1 else null end) / 3 ) As exChange,
- max(c.created) as lastlead
- from tblaccount a
- inner join tblcontact c on c.account = a.accountid
- inner join tbluser b on b.userid = c.broker
- inner join tblfinance f on f.contact = c.contactid
- left join tblAdminTeammebers TM ON b.userid = TM.MemberId
- 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
- fsd.status) as setdate
- from tblfinance TF, tblfinancestatus TFS
- where TFS.statusid in (5,6, 7,8)
- ) fs on fs.finance = f.financeid
- --where (c.account = @parentuserid or a.parent = @parentuserid or TM.AdminId = @parentuserid)
- where (c.account IN ( select account from tbluser where account in
- (select account from tbluser where adminid = @parentuserid) and broker = 1)
- OR TM.AdminId = @parentuserid)
- and (fs.status in (5,6, 7,8) and fs.setdate is not null)
- and (f.type = 1)
- group by b.brokername
- order by exlast30days desc
- public List<dbrdTotalWritten> DashboradTotalWritten(int loggedinUserAccountId, int loggedinUserId)
- {
- var data = ctx.dbrdTotalWrittens.Where(x => x.accountId == loggedinUserAccountId && x.userId == loggedinUserId).ToList();
- return data != null ? data : new List<dbrdTotalWritten>();
- }
- public DataSet GetAllDashboardData(int loggedinUserAccountId, int loggedinUserId)
- {
- TiledDashboard objTiledDashboard = new TiledDashboard();
- DataSet dsDashboard = objTiledDashboard.GetAllDashboardData(loggedinUserAccountId, loggedinUserId);
- return dsDashboard;
- }
- public List<CompanyModal> GetCompany(int userId, int companyType, string companyId, string companyName)
- {
- List<CompanyModal> CompanyModalList = new List<CompanyModal>();
- SqlParameter[] Param = new SqlParameter[4];
- Param[0] = new SqlParameter("@userid", userId);
- Param[1] = new SqlParameter("@companytype", companyType);
- Param[2] = new SqlParameter("@companyid", companyId);
- Param[3] = new SqlParameter("@companyname", companyName);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetCompany", Param);
- CompanyModalList = (from DataRow row in dt.Rows
- select new CompanyModal
- {
- companyid = row["companyid"].ToString(),
- companyname = row["companyname"].ToString(),
- companytype = row["companytype"].ToString(),
- emailaddress = row["emailaddress"].ToString(),
- telephone = row["telephone"].ToString()
- }).OrderBy(d => d.companyname).ToList();
- return CompanyModalList;
- }
- public int
- CheckUserType(int userId, out int teamId, out int accountId, out string brokers)
- {
- int _uType = 0; // 1- Admin, 2- Manager, 3- Broker, 4- general User
- teamId = 0;
- accountId = 0;
- brokers = "";
- try
- {
- var _objU = ctx.tblusers.Where(x => x.userid == userId).FirstOrDefault();
- if (_objU != null)
- {
- if (IsAdministrator(userId, out brokers))
- {
- _uType = 1;
- accountId = _objU.account;
- }
- else if (IsManager(userId, out teamId, out brokers))
- {
- _uType = 2;
- accountId = _objU.account;
- }
- else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && _objU.broker.HasValue && _objU.broker.Value)
- {
- _uType = 3;
- accountId = _objU.account;
- }
- else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && (!_objU.broker.HasValue || !_objU.broker.Value))
- {
- _uType = 4;
- accountId = _objU.account;
- }
- }
- return _uType;
- }
- catch
- { }
- return _uType;
- }
- public bool IsAdministrator(int userId, out string brokers)
- {
- bool _chk = false;
- brokers = "";
- try
- {
- 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)))
- {
- _chk = true;
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@AdminId", userId);
- var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetBrokersIdsByAdminId", Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- brokers = Convert.ToString(dt.Rows[0]["BrokersIds"]).Trim().TrimEnd(',');
- }
- }
- }
- catch
- {
- }
- return _chk;
- }
- public bool IsManager(int userId, out int teamId, out string brokers)
- {
- bool _chk = false;
- teamId = 0;
- brokers = "";
- try
- {
- 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)))
- {
- _chk = true;
- teamId = ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault() != null ? (ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault().TeamId ?? 0) : 0;
- }
- if (teamId > 0)
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@TeamId", teamId);
- var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetTeamMembersIdsByTeamId", Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- brokers = Convert.ToString(dt.Rows[0]["BrokersIds"]).Trim().TrimEnd(',');
- }
- }
- }
- catch
- {
- }
- return _chk;
- }
- @section css
- {
- <link href="@Url.Content("~/Content/css/validation.css")" rel="stylesheet" />
- <style>
- .subbtn {
- background-image: url("Images/updatebtn.png");
- border: 0 none;
- height: 31px;
- width: 93px;
- vertical-align: top;
- }
- </style>
- }
- <script type="text/javascript">
- function prevrow() {
- var tr = $("table#apptable > tbody > tr.activerow").prev()
- if (tr.length > 0)
- selectrow(tr);
- }
- function nextrow() {
- var tr = $("table#apptable > tbody > tr.activerow").next();
- if (tr.length > 0)
- selectrow(tr);
- }
- function selectrow(a) {
- $("table#apptable > tbody > tr").removeClass("activerow");
- $(a).addClass("activerow");
- $("textarea#companyname").val($(a).attr("companyname"));
- $("input#companyid").val($(a).attr("trcompanyid"));
- }
- function UpdateCompany_OnSuccess(data) {
- var tr = $("table#apptable > tbody > tr.activerow");
- tr.attr("companyname", data.data.companyname);
- tr.attr("trcompanyid", data.data.companyname);
- tr.find("td").eq(0).text(data.data.companyname);
- tr.find("td").eq(1).text(data.data.companyname);
- }
- function UpdateCompany_OnComplete() {
- $("#loader").hide();
- }
- function UpdateCompany_OnBegin() {
- $("#loader").show();
- }
- function FilterCompany_OnSuccess(data) {
- $("#divPartialView").html(data);
- var tr = $("table#apptable > tbody > tr.activerow");
- $("textarea#companyname").val(tr.attr("companyname"));
- $("input#companyid").val(tr.attr("trcompanyid"));
- }
- function FilterCompany_OnComplete() {
- $("#loader").hide();
- }
- function FilterCompany_OnBegin() {
- $("#loader").show();
- }
- </script>
- <div style="overflow: hidden">
- @using (Ajax.BeginForm("Filter", "Companies", new AjaxOptions()
- {
- HttpMethod = "POST",
- OnSuccess = "FilterCompany_OnSuccess",
- OnComplete = "FilterCompany_OnComplete",
- OnBegin = "FilterCompany_OnBegin",
- }))
- {
- <div id="searchcontainer" class="contentbox" style="position: relative;">
- <table>
- <tbody>
- <tr>
- <td>
- <h2>Company</h2>
- </td>
- </tr>
- <tr>
- <td>
- <input type="text" name="filtercompanyname" id="filtercompanyname" class="idleField txtField" />
- </td>
- </tr>
- </tbody>
- </table>
- <div style="text-align: right">
- <input type="submit" value="Search Company" id="btnSearchCompany">
- </div>
- </div>
- <div class="contentbox applicationpaging clearfix">
- <div class="applicationselect clearfix">
- <span style="font-size: 11pt;">Company Type:</span>
- <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();">
- <option value="1" selected="selected">Providers</option>
- <option value="2">Solicitors</option>
- </select>
- <span class="customStyleSelectBox" style="display: inline-block;">
- <span class="customStyleSelectBoxInner" id="customStyleSelectBoxInnerCompanyType" style="width: 188px; display: inline-block;">Providers
- </span>
- </span>
- </div>
- </div>
- }
- <tbody>
- @if (Model != null)
- {
- int rowId = 1;
- foreach (var item in Model)
- {
- <tr class="row @(rowId % 2 == 0 ? "even" : "odd")@(rowId == 1 ? " activerow" : "")"
- onmouseout="$(this).removeClass('highlightrow')"
- id="@rowId"
- onmouseover="$(this).addClass('highlightrow')"
- onclick="selectrow(this);"
- companyname="@item.companyname"
- trcompanyid="@item.companyid">
- <td>@item.companyid</td>
- <td>@item.companyname</td>
- <td>@(item.companytype == "1" ? "Providers" : "Solicitors")</td>
- <td>@item.emailaddress</td>
- <td>@item.telephone</td>
- </tr>
- rowId++;
- }
- }
- </tbody>
Add Comment
Please, Sign In to add comment