Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Q_Application
- {
- #region [Declarations]
- public db_occfinance_5572Entities ctx = new db_occfinance_5572Entities();
- System.Web.HttpContext con = HttpContext.Current;
- #endregion [Declarations]
- #region Find Broker for logged in user
- /// <summary>
- /// Getting Finance Type
- /// </summary>
- /// <returns></returns>
- public List<tblfinancetype> GetFinanceType()
- {
- List<tblfinancetype> financetype = new List<tblfinancetype>();
- try
- {
- financetype = ctx.tblfinancetypes.ToList();
- return financetype;
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetFinanceType", ex.Message);
- return financetype;
- }
- }
- #endregion
- #region Check Whether the status of the product is changed or not
- /// <summary>
- /// Checking Status Update
- /// </summary>
- /// <param name="financeId"></param>
- /// <param name="newStatusId"></param>
- /// <param name="oldStatusId"></param>
- /// <returns></returns>
- public bool CheckStatusUpdate(int financeId, int newStatusId, out int oldStatusId)
- {
- bool _chk = false;
- oldStatusId = 0;
- try
- {
- var _oldStatusId = 0;
- var oldstatusIddata = ctx.tblfinances.Where(c => c.financeid == financeId).FirstOrDefault();
- if (oldstatusIddata != null)
- {
- _oldStatusId = oldstatusIddata.status ?? 0;
- oldStatusId = _oldStatusId;
- }
- if (_oldStatusId != newStatusId)
- {
- _chk = true;
- }
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "CheckStatusUpdate", ex.Message);
- }
- return _chk;
- }
- #endregion
- #region Find Filter By Status According to ApplicationId
- /// <summary>
- /// Find Filter by status
- /// </summary>
- /// <param name="applicationid"></param>
- /// <returns></returns>
- public List<tblfinancestatu> FindFilterByStatus(int applicationid)
- {
- var cntlists = ctx.tblfinancestatus.Where(c => c.type == applicationid).ToList();
- return cntlists;
- }
- /// <summary>
- /// Getting Filter by statuss
- /// </summary>
- /// <param name="applicationId"></param>
- /// <param name="account"></param>
- /// <param name="broker"></param>
- /// <returns></returns>
- public List<tblfinancestatu> GetFilterByStatus(int applicationId, int account, int broker)
- {
- List<tblfinancestatu> fstatus = new List<tblfinancestatu>();
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@applicationId", applicationId);
- Param[1] = new SqlParameter("@account", account);
- Param[2] = new SqlParameter("@broker", broker);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetFilterByStatus", Param);
- fstatus = (from DataRow row in dt.Rows
- select new tblfinancestatu
- {
- type = Convert.ToInt32(((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]).ToString()),
- statusid = Convert.ToInt32(((row["statusid"] == DBNull.Value || row["statusid"] == null) ? "0" : row["statusid"]).ToString()),
- name = ((row["name"] == DBNull.Value || row["name"] == null) ? " " : row["name"]).ToString()
- }).ToList();
- return fstatus;
- }
- /// <summary>
- /// Get Finances list by type
- /// </summary>
- /// <param name="financetype"></param>
- /// <param name="userid"></param>
- /// <returns></returns>
- public List<tblfinance> getFinancesListByType(int financetype = 1, int userid = 0)
- {
- var data = ctx.tblfinances.Where(c => c.type == financetype && c.status.Value != 34 && c.status.Value != 35 && c.status.Value != 36 && c.status.Value != 37 && c.status.Value != 38).ToList();
- if (data != null)
- if (this.IsAdmin(userid))
- data = data.Where(x => x.type.Value == financetype).ToList();
- else
- data = data.Where(x => x.type.Value == financetype && x.tblcontact.broker == userid).ToList();
- return data;
- }
- /// <summary>
- /// Getting Finances
- /// </summary>
- /// <param name="financetype"></param>
- /// <returns></returns>
- public List<tblfinance> getFinances(int financetype = 1)
- {
- return ctx.tblfinances.Where(c => c.type == financetype && c.status.Value != 34 && c.status.Value != 35 && c.status.Value != 36 && c.status.Value != 37 && c.status.Value != 38).ToList();
- }
- /// <summary>
- /// Counting Finance Type
- /// </summary>
- /// <param name="type"></param>
- /// <param name="status"></param>
- /// <param name="userid"></param>
- /// <returns></returns>
- public int countFinancetype(int type, int status, int userid)
- {
- var data = ctx.tblfinances.Where(c => c.type == type && c.status.Value != 34 && c.status.Value != 35 && c.status.Value != 36 && c.status.Value != 37 && c.status.Value != 38).GroupBy(x => x.contact).SelectMany(x => x.Take(1)).ToList();
- if (data != null)
- if (this.IsAdmin(userid))
- return data.Where(x => x.type.Value == type && x.status.Value == status).Count();
- else
- return data.Where(x => x.type.Value == type && x.status.Value == status && x.tblcontact.broker == userid).Count();
- else
- return 0;
- }
- /// <summary>
- /// Getting List of finance type count
- /// </summary>
- /// <param name="type"></param>
- /// <param name="userid"></param>
- /// <returns></returns>
- public List<tblfinance> ListcountFinancetype(int type, int userid)
- {
- var data = ctx.tblfinances.Where(c => c.type == type && c.status.Value != 34 && c.status.Value != 35 && c.status.Value != 36 && c.status.Value != 37 && c.status.Value != 38).GroupBy(x => x.contact).SelectMany(x => x.Take(1)).ToList();
- if (data != null)
- if (this.IsAdmin(userid))
- data = data.Where(x => x.type.Value == type).ToList();
- else
- data = data.Where(x => x.type.Value == type && x.tblcontact.broker == userid).ToList();
- return data;
- }
- /// <summary>
- /// Getting count method for Finance type on load
- /// </summary>
- /// <param name="type"></param>
- /// <param name="status"></param>
- /// <param name="userid"></param>
- /// <param name="loggedinuserId"></param>
- /// <returns></returns>
- public int countFinancetypeonLoad(int type, int status, int userid, int loggedinuserId)
- {
- var data = ctx.tblfinances.GroupBy(x => x.contact).SelectMany(x => x.Take(1)).ToList();
- if (data != null)
- if (this.IsAdmin(userid))
- return data.Where(x => x.type.Value == type && x.status.Value == status && (x.followup == null || x.followup.Value < System.DateTime.Now)).Count();
- else
- return data.Where(x => x.type.Value == type && x.status.Value == status && x.tblcontact.account == userid && (x.followup == null || x.followup.Value < System.DateTime.Now)).Count();
- else
- return 0;
- }
- #endregion
- #region Get all lead from database
- /// <summary>
- /// Getting All lead
- /// </summary>
- /// <param name="ListStatusCountData"></param>
- /// <param name="accountid"></param>
- /// <param name="userId"></param>
- /// <param name="type"></param>
- /// <param name="SearchText"></param>
- /// <param name="ClientId"></param>
- /// <param name="BrokerId"></param>
- /// <param name="Status"></param>
- /// <param name="Lender"></param>
- /// <param name="Solicitor"></param>
- /// <param name="isHideNotRequire"></param>
- /// <returns></returns>
- public IQueryable<ApplicationLead> GetAllLead(out List<StatusCount> ListStatusCountData, int accountid, int userId, int type = 1, string SearchText = "", int ClientId = 0, string BrokerId = "", string Status = "", string Lender = "", string Solicitor = "", int isHideNotRequire = 1,string substatus = "",int financeId=0)
- {
- Q_Application _obj = new Q_Application();
- IQueryable<ApplicationLead> leadData = null;
- ListStatusCountData = new List<StatusCount>();
- int teamId = 0;
- string brokersIds = "";
- int _userType = 0;
- int _accountId = 0;
- int ID = 0;
- _userType = _obj.CheckUserType(userId, out teamId, out _accountId, out brokersIds);
- if (_userType == (int)UserType.GeneralUser) // General user
- ID = accountid;
- else if (_userType == (int)UserType.Admin) // Admin
- ID = accountid;
- else if (_userType == (int)UserType.Manager)// Manager
- ID = teamId;
- else if (_userType == (int)UserType.Broker) // Broker
- ID = userId;
- SqlParameter[] Param = new SqlParameter[12];
- Param[0] = new SqlParameter("@UserType", _userType);
- Param[1] = new SqlParameter("@ID", ID);
- Param[2] = new SqlParameter("@Type", type);
- Param[3] = new SqlParameter("@isHideNotRequire", isHideNotRequire);
- if (!string.IsNullOrWhiteSpace(SearchText))
- Param[4] = new SqlParameter("@SearchText", SearchText);
- if (ClientId > 0)
- Param[5] = new SqlParameter("@ClientId", ClientId);
- if (!string.IsNullOrWhiteSpace(BrokerId))
- Param[6] = new SqlParameter("@BrokerId", BrokerId);
- if (!string.IsNullOrWhiteSpace(Status))
- Param[7] = new SqlParameter("@Status", Status);
- if (!string.IsNullOrWhiteSpace(Lender))
- Param[8] = new SqlParameter("@Lender", Lender);
- if (!string.IsNullOrWhiteSpace(Solicitor))
- Param[9] = new SqlParameter("@Solicitor", Solicitor);
- if (!string.IsNullOrWhiteSpace(substatus))
- Param[10] = new SqlParameter("@SubStatus", substatus);
- if (financeId > 0)
- Param[11] = new SqlParameter("@FinanceId", financeId);
- DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetAllAppData_Update", Param);
- if (ds.Tables.Count > 0)
- {
- leadData = (from DataRow row in ds.Tables[0].Rows
- select new ApplicationLead()
- {
- AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
- financeid = Convert.ToInt32(((row["financeid"] == DBNull.Value || row["financeid"] == null) ? "0" : row["financeid"]).ToString()),
- clientId = Convert.ToInt32(((row["clientId"] == DBNull.Value || row["clientId"] == null) ? "0" : row["clientId"]).ToString()),
- contactId = Convert.ToInt32(((row["contactId"] == DBNull.Value || row["contactId"] == null) ? "0" : row["contactId"]).ToString()),
- brokerId = Convert.ToInt32(((row["brokerId"] == DBNull.Value || row["brokerId"] == null) ? "0" : row["brokerId"]).ToString()),
- brokerName = ((row["brokerName"] == DBNull.Value || row["brokerName"] == null) ? " " : row["brokerName"]).ToString(),
- clientname = ((row["clientname"] == DBNull.Value || row["clientname"] == null) ? " " : row["clientname"]).ToString(),
- firstName = ((row["firstName"] == DBNull.Value || row["firstName"] == null) ? " " : row["firstName"]).ToString(),
- lastName = ((row["lastName"] == DBNull.Value || row["lastName"] == null) ? " " : row["lastName"]).ToString(),
- Add = (row["Add"] == DBNull.Value || row["Add"] == null) ? (DateTime?)null : Convert.ToDateTime(row["Add"]),
- Updated = (row["Updated"] == DBNull.Value || row["Updated"] == null) ? (DateTime?)null : Convert.ToDateTime(row["Updated"]),
- contact = (row["contact"] == DBNull.Value || row["contact"] == null) ? (DateTime?)null : Convert.ToDateTime(row["contact"]),
- followUp = (row["followUp"] == DBNull.Value || row["followUp"] == null) ? (DateTime?)null : Convert.ToDateTime(row["followUp"]),
- email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
- tel = ((row["tel"] == DBNull.Value || row["tel"] == null) ? " " : row["tel"]).ToString(),
- sla = ((row["sla"] == DBNull.Value || row["sla"] == null) ? " " : row["sla"]).ToString(),
- lead = ((row["lead"] == DBNull.Value || row["lead"] == null) ? " " : row["lead"]).ToString(),
- neg = ((row["neg"] == DBNull.Value || row["neg"] == null) ? " " : row["neg"]).ToString(),
- branch = ((row["branch"] == DBNull.Value || row["branch"] == null) ? " " : row["branch"]).ToString(),
- status = Convert.ToInt32(((row["status"] == DBNull.Value || row["status"] == null) ? "0" : row["status"]).ToString()),
- type = Convert.ToInt32(((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]).ToString()),
- StatusName = ((row["StatusName"] == DBNull.Value || row["StatusName"] == null) ? " " : row["StatusName"]).ToString(),
- Lender = ((row["Lender"] == DBNull.Value || row["Lender"] == null) ? " " : row["Lender"]).ToString(),
- Soliciter = ((row["Soliciter"] == DBNull.Value || row["Soliciter"] == null) ? " " : row["Soliciter"]).ToString(),
- BrokerEmail = ((row["BrokerEmail"] == DBNull.Value || row["BrokerEmail"] == null) ? " " : row["BrokerEmail"]).ToString(),
- PolicyNumber = ((row["PolicyNumber"] == DBNull.Value || row["PolicyNumber"] == null) ? " " : row["PolicyNumber"]).ToString(),
- TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
- OtherApplicantEmail = ((row["OtherApplicantEmail"] == DBNull.Value || row["OtherApplicantEmail"] == null) ? " " : row["OtherApplicantEmail"]).ToString(),
- OtherApplicantId = Convert.ToInt32(((row["OtherApplicantId"] == DBNull.Value || row["OtherApplicantId"] == null) ? "0" : row["OtherApplicantId"]).ToString()),
- OtherApplicantFname = ((row["OtherApplicantFname"] == DBNull.Value || row["OtherApplicantFname"] == null) ? " " : row["OtherApplicantFname"]).ToString(),
- OtherApplicantMobile = ((row["OtherApplicantMobile"] == DBNull.Value || row["OtherApplicantMobile"] == null) ? " " : row["OtherApplicantMobile"]).ToString(),
- OtherApplicantSName = ((row["OtherApplicantSName"] == DBNull.Value || row["OtherApplicantSName"] == null) ? " " : row["OtherApplicantSName"]).ToString(),
- AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
- statusinterval = Convert.ToInt32(((row["statusinterval"] == DBNull.Value || row["statusinterval"] == null) ? 0 : row["statusinterval"]).ToString()),
- RecurrenceID = !string.IsNullOrEmpty(row["RecurrenceID"].ToString()) ? Convert.ToInt32(row["RecurrenceID"].ToString()) : new Nullable<int>(),
- RecurrenceException = !string.IsNullOrEmpty(row["RecurrenceException"].ToString()) ? row["RecurrenceException"].ToString() : null,
- RecurrenceRule = !string.IsNullOrEmpty(row["RecurrenceRule"].ToString()) ? row["RecurrenceRule"].ToString() : null,
- RID = null,
- PrimaryContact = ((row["PrimaryContact"] == DBNull.Value || row["PrimaryContact"] == null) ? " " : row["PrimaryContact"]).ToString(),
- SecondaryContact = ((row["SecondaryContact"] == DBNull.Value || row["SecondaryContact"] == null) ? " " : row["SecondaryContact"]).ToString(),
- Address1 = ((row["Address1"] == DBNull.Value || row["Address1"] == null) ? " " : row["Address1"]).ToString(),
- Address2 = ((row["Address2"] == DBNull.Value || row["Address2"] == null) ? " " : row["Address2"]).ToString(),
- OtherDetails = ((row["OtherDetails"] == DBNull.Value || row["OtherDetails"] == null) ? " " : row["OtherDetails"]).ToString(),
- Title = ((row["Title"] == DBNull.Value || row["Title"] == null) ? " " : row["Title"]).ToString(),
- FAX = ((row["FAX"] == DBNull.Value || row["FAX"] == null) ? " " : row["FAX"]).ToString(),
- Qualification = ((row["Qualification"] == DBNull.Value || row["Qualification"] == null) ? " " : row["Qualification"]).ToString(),
- LastNote = ((row["LastNote"] == DBNull.Value || row["LastNote"] == null) ? " " : row["LastNote"]).ToString(),
- FinanceAddress = ((row["FinanceAddress"] == DBNull.Value || row["FinanceAddress"] == null) ? " " : row["FinanceAddress"]).ToString(),
- SubStatusName = ((row["SubStatusName"] == DBNull.Value || row["SubStatusName"] == null) ? "" : row["SubStatusName"]).ToString(),
- SubStatusId = Convert.ToInt32(((row["SubStatusId"] == DBNull.Value || row["SubStatusId"] == null) ? "0" : row["status"]).ToString()),
- }).AsQueryable();
- }
- if (ds.Tables.Count > 1)
- {
- ListStatusCountData = (from DataRow row in ds.Tables[1].Rows
- select new StatusCount()
- {
- Type = Convert.ToInt32(((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]).ToString()),
- StatusId = Convert.ToInt32(((row["statusid"] == DBNull.Value || row["statusid"] == null) ? "0" : row["statusid"]).ToString()),
- TotalCount = Convert.ToInt32(((row["TotalCount"] == DBNull.Value || row["TotalCount"] == null) ? "0" : row["TotalCount"]).ToString()),
- StatusName = ((row["name"] == DBNull.Value || row["name"] == null) ? " " : row["name"]).ToString()
- }).ToList();
- }
- List<StatusCount> ListSubStatusCountData = new List<StatusCount>();
- if (ds.Tables.Count > 2)
- {
- ListSubStatusCountData = (from DataRow row in ds.Tables[2].Rows
- select new StatusCount()
- {
- Type = Convert.ToInt32(((row["StatusId"] == DBNull.Value || row["StatusId"] == null) ? "0" : row["StatusId"]).ToString()),
- StatusId = Convert.ToInt32(((row["SubstatusId"] == DBNull.Value || row["SubstatusId"] == null) ? "0" : row["SubstatusId"]).ToString()),
- TotalCount = Convert.ToInt32(((row["ToTalCount"] == DBNull.Value || row["ToTalCount"] == null) ? "0" : row["ToTalCount"]).ToString()),
- StatusName = ((row["Substatusname"] == DBNull.Value || row["Substatusname"] == null) ? " " : row["Substatusname"]).ToString()
- }).ToList();
- }
- HttpContext.Current.Session["ListSubStatusCountData"] = ListSubStatusCountData;
- return leadData;
- }
- /// <summary>
- /// GetAll Save Events
- /// </summary>
- /// <param name="accountid"></param>
- /// <param name="userId"></param>
- /// <returns></returns>
- public IQueryable<ApplicationLead> RecurredSavedEvent()
- {
- IQueryable<ApplicationLead> leadData = null;
- DataSet ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetAllAppDataWithSaveEvents_Update");
- if (ds.Tables.Count > 0)
- {
- leadData = (from DataRow row in ds.Tables[0].Rows
- select new ApplicationLead()
- {
- AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
- financeid = Convert.ToInt32(((row["financeid"] == DBNull.Value || row["financeid"] == null) ? "0" : row["financeid"]).ToString()),
- clientId = Convert.ToInt32(((row["clientId"] == DBNull.Value || row["clientId"] == null) ? "0" : row["clientId"]).ToString()),
- contactId = Convert.ToInt32(((row["contactId"] == DBNull.Value || row["contactId"] == null) ? "0" : row["contactId"]).ToString()),
- brokerId = Convert.ToInt32(((row["brokerId"] == DBNull.Value || row["brokerId"] == null) ? "0" : row["brokerId"]).ToString()),
- brokerName = ((row["brokerName"] == DBNull.Value || row["brokerName"] == null) ? " " : row["brokerName"]).ToString(),
- clientname = ((row["clientname"] == DBNull.Value || row["clientname"] == null) ? " " : row["clientname"]).ToString(),
- firstName = ((row["firstName"] == DBNull.Value || row["firstName"] == null) ? " " : row["firstName"]).ToString(),
- lastName = ((row["lastName"] == DBNull.Value || row["lastName"] == null) ? " " : row["lastName"]).ToString(),
- Add = (row["Add"] == DBNull.Value || row["Add"] == null) ? (DateTime?)null : Convert.ToDateTime(row["Add"]),
- Updated = (row["Updated"] == DBNull.Value || row["Updated"] == null) ? (DateTime?)null : Convert.ToDateTime(row["Updated"]),
- contact = (row["contact"] == DBNull.Value || row["contact"] == null) ? (DateTime?)null : Convert.ToDateTime(row["contact"]),
- followUp = (row["followUp"] == DBNull.Value || row["followUp"] == null) ? (DateTime?)null : Convert.ToDateTime(row["followUp"]),
- email = ((row["email"] == DBNull.Value || row["email"] == null) ? " " : row["email"]).ToString(),
- tel = ((row["tel"] == DBNull.Value || row["tel"] == null) ? " " : row["tel"]).ToString(),
- sla = ((row["sla"] == DBNull.Value || row["sla"] == null) ? " " : row["sla"]).ToString(),
- lead = ((row["lead"] == DBNull.Value || row["lead"] == null) ? " " : row["lead"]).ToString(),
- neg = ((row["neg"] == DBNull.Value || row["neg"] == null) ? " " : row["neg"]).ToString(),
- branch = ((row["branch"] == DBNull.Value || row["branch"] == null) ? " " : row["branch"]).ToString(),
- status = Convert.ToInt32(((row["status"] == DBNull.Value || row["status"] == null) ? "0" : row["status"]).ToString()),
- type = Convert.ToInt32(((row["type"] == DBNull.Value || row["type"] == null) ? "0" : row["type"]).ToString()),
- StatusName = ((row["StatusName"] == DBNull.Value || row["StatusName"] == null) ? " " : row["StatusName"]).ToString(),
- Lender = ((row["Lender"] == DBNull.Value || row["Lender"] == null) ? " " : row["Lender"]).ToString(),
- Soliciter = ((row["Soliciter"] == DBNull.Value || row["Soliciter"] == null) ? " " : row["Soliciter"]).ToString(),
- BrokerEmail = ((row["BrokerEmail"] == DBNull.Value || row["BrokerEmail"] == null) ? " " : row["BrokerEmail"]).ToString(),
- PolicyNumber = ((row["PolicyNumber"] == DBNull.Value || row["PolicyNumber"] == null) ? " " : row["PolicyNumber"]).ToString(),
- TeamId = Convert.ToInt32(((row["TeamId"] == DBNull.Value || row["TeamId"] == null) ? "0" : row["TeamId"]).ToString()),
- OtherApplicantEmail = ((row["OtherApplicantEmail"] == DBNull.Value || row["OtherApplicantEmail"] == null) ? " " : row["OtherApplicantEmail"]).ToString(),
- OtherApplicantId = Convert.ToInt32(((row["OtherApplicantId"] == DBNull.Value || row["OtherApplicantId"] == null) ? "0" : row["OtherApplicantId"]).ToString()),
- OtherApplicantFname = ((row["OtherApplicantFname"] == DBNull.Value || row["OtherApplicantFname"] == null) ? " " : row["OtherApplicantFname"]).ToString(),
- OtherApplicantMobile = ((row["OtherApplicantMobile"] == DBNull.Value || row["OtherApplicantMobile"] == null) ? " " : row["OtherApplicantMobile"]).ToString(),
- OtherApplicantSName = ((row["OtherApplicantSName"] == DBNull.Value || row["OtherApplicantSName"] == null) ? " " : row["OtherApplicantSName"]).ToString(),
- AdminId = Convert.ToInt32(((row["AdminId"] == DBNull.Value || row["AdminId"] == null) ? "0" : row["AdminId"]).ToString()),
- statusinterval = Convert.ToInt32(((row["statusinterval"] == DBNull.Value || row["statusinterval"] == null) ? 0 : row["statusinterval"]).ToString()),
- RecurrenceID = !string.IsNullOrEmpty(row["RecurrenceID"].ToString()) ? Convert.ToInt32(row["RecurrenceID"].ToString()) : new Nullable<int>(),
- RecurrenceException = !string.IsNullOrEmpty(row["RecurrenceException"].ToString()) ? row["RecurrenceException"].ToString() : null,
- RecurrenceRule = !string.IsNullOrEmpty(row["RecurrenceRule"].ToString()) ? row["RecurrenceRule"].ToString() : null,
- RID = !string.IsNullOrEmpty(row["ID"].ToString()) ? Convert.ToInt32(row["ID"].ToString()) : new Nullable<int>(),
- //Convert.ToInt32(((row["ID"] == DBNull.Value || row["ID"] == null) ? "0" : row["ID"]).ToString()),
- }).AsQueryable();
- }
- return leadData;
- }
- public tbluser LoggedUserName(int UserId)
- {
- return ctx.tblusers.Where(x => x.userid == UserId && x.active == true).SingleOrDefault();
- }
- #endregion
- #region Get Individua lead from database
- /// <summary>
- /// getting Single lead for application page
- /// </summary>
- /// <param name="accountid"></param>
- /// <param name="contactId"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public ApplicationJsonLead GetSingleLead(int accountid, int contactId = 0, int financeid = 0)
- {
- var q = (from c in ctx.tblcontacts
- join a in ctx.tblaccounts on c.account equals a.accountid
- join u in ctx.tblusers on c.broker equals u.userid
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join fs in ctx.tblfinancestatus on ft.status equals fs.statusid
- join o in ctx.tblOtherApplicants on c.contactid equals o.MainContactId into othercontact
- from o in othercontact.DefaultIfEmpty()
- orderby c.address descending
- select new ApplicationJsonLead()
- {
- AccountId = u.account,
- financeid = ft.financeid,
- clientId = a.accountid,
- contactId = c.contactid,
- brokerId = u.userid,
- brokerName = u.brokername,
- clientname = a.companyname,
- firstName = c.firstname,
- lastName = c.lastname,
- Add = c.created,
- Updated = c.modified,
- contact = c.lastcontact,
- followUp = ft.followup,
- email = c.email,
- tel = c.telephone,
- sla = c.slamet == true ? "Y" : "",
- lead = "D",
- neg = ctx.tblNegotiators.Where(negt => negt.Id == c.NegrefId).FirstOrDefault().Negotiator,//c.negref,
- branch = ctx.tblBranches.Where(brn => brn.Id == c.BranchId).FirstOrDefault().Branch,//c.branch,
- parentContactId = c.parentContactId ?? 0,
- status = ft.status,
- type = ft.type,
- StatusName = fs.name,
- Lender = ft.provider,
- Soliciter = ctx.tblfinance_mortgage.Where(x => x.financeid == ft.financeid).FirstOrDefault().solicitor,
- BrokerEmail = u.username,
- PolicyNumber = ft.policyreference ?? "",
- TeamId = u.TeamId ?? 0,
- OtherApplicantEmail = o.Email,
- OtherApplicantId = o.OtherApplicantId == null ? 0 : o.OtherApplicantId,
- OtherApplicantFname = o.FirstName ?? "",
- OtherApplicantMobile = o.MobileNumber ?? "",
- OtherApplicantSName = o.SurName ?? "",
- AdminId = u.AdminId ?? 0,
- PrimaryContact = u.PrimaryContact ?? "",
- SecondaryContact = u.SecondaryContact ?? "",
- Address1 = u.Address1 ?? "",
- Address2 = u.Address2 ?? "",
- OtherDetails = u.OtherDetails ?? "",
- Title = u.Title ?? "",
- FAX = u.FAX ?? "",
- Qualification = u.Qualification ?? "",
- FinanceAddress = ft.Address1 ?? "",
- SubStatusId = ft.subFinanceStatus ?? 0
- }).Where(c => c.contactId == contactId && c.financeid == financeid).FirstOrDefault();
- if(q != null)
- {
- db_occfinance_5572Entities _ctx = new db_occfinance_5572Entities();
- var v = _ctx.tblfinancesubstatus.Where(x => x.SubstatusId == q.SubStatusId).FirstOrDefault();
- if (v != null)
- q.SubStatusName = v.Substatusname;
- else
- q.SubStatusName = "";
- }
- return q ?? new ApplicationJsonLead();
- }
- #endregion
- #region [Update Application Form 2015-03-31]
- /// <summary>
- /// Update application form
- /// </summary>
- /// <param name="MortgageList"></param>
- /// <param name="LifeList"></param>
- /// <param name="BuildinbContentList"></param>
- /// <param name="PensionList"></param>
- /// <param name="InvestmentList"></param>
- /// <param name="_address"></param>
- /// <param name="Contactdetails"></param>
- /// <param name="userid"></param>
- /// <param name="OtherApplicant"></param>
- public void UpdateApplicationForm(Boolean mortage_notes_allow, string client, string branch, string neg, List<Mortgage> MortgageList, List<Life> LifeList, List<BuildingContent> BuildinbContentList, List<Pensions> PensionList, List<Investment> InvestmentList, Address _address, ApplicationForm Contactdetails, out int leadTransfer, int? userid = null, OtherApplicant OtherApplicant = null)
- {
- try
- {
- Q_NewLead QNewLead = new Q_NewLead();
- var negrefid = QNewLead.GetNegotiatorId(neg);
- var branchid = QNewLead.GetBranchId(branch);
- leadTransfer = 0;
- //Added By Kabir 31_01_2014
- int financeId = 0;
- int status = 0;
- string newremortage = null;
- string remortgageContact = null;
- //*************************
- //int _noteid = getNoteID();
- int addrid = 0;
- #region finance_Address
- //Address
- int addressid = ctx.tblcontacts.Where(x => x.contactid == _address.contactid).Select(x => x.address.Value).FirstOrDefault();
- tbladdress address = ctx.tbladdresses.Where(x => x.addressid == addressid).FirstOrDefault();
- if (addressid != 0)
- {
- tbladdress newaddress = new tbladdress();
- if (address != null)
- {
- //update
- address.address1 = _address.address_line1;
- address.address2 = _address.address_line2;
- address.town = _address.address_city;
- address.country = "";
- address.postcode = _address.address_postcode;
- ctx.SaveChanges();
- addrid = addressid;
- }
- else
- {
- //insert
- //newaddress.addressid = _address.contactid;
- newaddress.address1 = _address.address_line1;
- newaddress.address2 = _address.address_line2;
- newaddress.town = _address.address_city;
- newaddress.postcode = _address.address_postcode;
- ctx.tbladdresses.Add(newaddress);
- ctx.SaveChanges();
- addrid = newaddress.addressid;
- }
- }
- else
- {
- tbladdress newaddress = new tbladdress();
- newaddress.address1 = _address.address_line1;
- newaddress.address2 = _address.address_line2;
- newaddress.town = _address.address_city;
- newaddress.postcode = _address.address_postcode;
- ctx.tbladdresses.Add(newaddress);
- ctx.SaveChanges();
- addrid = newaddress.addressid;
- }
- #endregion
- #region update Contact details
- var isBroker = ctx.tblusers.Where(x => x.userid == userid && x.broker == true && x.administrator == false && x.active == true).FirstOrDefault();
- var contact = ctx.tblcontacts.Where(x => x.contactid == Contactdetails.contactid).FirstOrDefault();
- bool isInsuranceBroker = IsInsuranceBroker(userid ?? 0);
- bool isNotInsuranceBroker = IsInsuranceBroker(Contactdetails.Broker);
- if (contact != null)
- {
- if (isBroker != null)
- {
- if (isInsuranceBroker == isNotInsuranceBroker)
- {
- if (contact.broker != Contactdetails.Broker)
- {
- if (Contactdetails.Broker != userid)
- {
- var IsAlready = ctx.tblLeadTransferHistories.Where(x => x.contactId == Contactdetails.contactid && x.status == 1).FirstOrDefault();
- if (IsAlready == null)
- {
- tblLeadTransferHistory leadRequest = new tblLeadTransferHistory();
- leadRequest.contactId = Contactdetails.contactid;
- leadRequest.odlBroker = contact.broker;
- leadRequest.newBroker = Contactdetails.Broker;
- leadRequest.createDate = System.DateTime.Now;
- leadRequest.status = 1;
- ctx.tblLeadTransferHistories.Add(leadRequest);
- leadTransfer = 3;//Request has been sent successfully
- }
- else
- {
- leadTransfer = 2;// For this contact request is already pending
- }
- }
- else
- {
- leadTransfer = 1;//broker not transfered
- }
- }
- }
- else
- {
- leadTransfer = 0;//this is the case when insurance broker is updating the record of mortgage broker
- contact.broker = Contactdetails.Broker;
- }
- }
- else
- {
- leadTransfer = 0;//not broker
- contact.broker = Contactdetails.Broker;
- }
- if (Convert.ToInt32(client) == 1583028)
- {
- var pCid = Contactdetails.parentContactId.Split('_').ToList();
- int PId;
- int.TryParse(pCid[0], out PId);
- if (PId == 0)
- {
- if (negrefid != 0)
- {
- var parentContact = ctx.tblcontacts.Where(x => ((x.firstname.ToUpper().Trim() ?? "") + " " + (x.lastname.ToUpper().Trim() ?? "")).Trim() == neg.ToUpper().Trim() && x.contactid != contact.contactid && x.account != 1582971).OrderByDescending(x => x.contactid).Select(x => x.contactid).ToList();
- if (parentContact.Count > 1)
- {
- if (((contact.parentContactId ?? 0) == 0) && ((contact.parentNegId ?? 0) == 0))
- {
- contact.parentContactId = parentContact.FirstOrDefault();
- }
- }
- else
- {
- if (parentContact.Count == 1)
- {
- if (contact.NegrefId != negrefid)
- {
- contact.parentContactId = parentContact.FirstOrDefault();
- contact.parentNegId = 0;
- }
- if (((contact.parentContactId ?? 0) == 0) && ((contact.parentNegId ?? 0) == 0))
- {
- contact.parentContactId = parentContact.FirstOrDefault();
- contact.parentNegId = 0;
- }
- }
- else
- {
- int parentNegId = ctx.tblClientReferralNeg.Where(x => x.NegName.Trim().ToUpper() == neg.Trim().ToUpper()).Select(x => x.NegId).FirstOrDefault();
- contact.parentNegId = parentNegId;
- contact.parentContactId = 0;
- }
- }
- }
- else
- {
- contact.parentContactId = 0;
- contact.parentNegId = 0;
- }
- }
- else
- {
- if (pCid.Count == 1)
- {
- contact.parentContactId = PId;
- contact.parentNegId = 0;
- }
- else
- {
- contact.parentNegId = PId;
- contact.parentContactId = 0;
- }
- }
- }
- else
- {
- contact.parentContactId = 0;
- contact.parentNegId = 0;
- }
- if (isInsuranceBroker)
- {
- var LI = ctx.tblLinkInsuranceHistory.Where(x => x.ContactId == Contactdetails.contactid && x.MortgageBroker == Contactdetails.Broker).FirstOrDefault();
- if (LI != null)
- LI.UpdatedDate = System.DateTime.Now;
- }
- contact.BranchId = branchid;
- contact.account = Convert.ToInt32(client);
- contact.NegrefId = negrefid;
- contact.firstname = Contactdetails.FirstName;
- contact.lastname = Contactdetails.LastName;
- contact.email = Contactdetails.Email;
- contact.telephone = Contactdetails.Telephone;
- if (Contactdetails.ContactIn2Hrs == 0)
- contact.slamet = null;
- if (Contactdetails.ContactIn2Hrs == 1)
- contact.slamet = true;
- if (Contactdetails.ContactIn2Hrs == 2)
- contact.slamet = false;
- contact.ninumber = _address.ninnumber;
- contact.dob = Helper.GetDate(_address.dob);
- contact.jobtitle = _address.jobtitle;
- contact.employer = _address.employer;
- contact.accountdetails = _address.accountant;
- contact.married = Helper.GetDate(_address.weddinganniversary);
- contact.dependants = _address.dependents;
- contact.method = Contactdetails.Method;
- contact.address = addrid;
- if (Contactdetails.IsOfferQualified == true)
- {
- contact.offerqualified = true;
- }
- else
- {
- contact.offerqualified = false;
- }
- if (Contactdetails.IsContactTodayY == true)
- {
- contact.lastcontact = System.DateTime.Now;
- }
- ctx.SaveChanges();
- //Other Contact Data: Date- 12/6/2014
- if (OtherApplicant != null)
- {
- if (OtherApplicant.OtherApplicantId > 0) // Update
- {
- var _Other = ctx.tblOtherApplicants.Where(c => c.OtherApplicantId == OtherApplicant.OtherApplicantId).FirstOrDefault();
- if (_Other != null)
- {
- _Other.Email = OtherApplicant.Email;
- _Other.FirstName = OtherApplicant.FirstName;
- _Other.SurName = OtherApplicant.SurName;
- _Other.MobileNumber = OtherApplicant.MobileNumber;
- _Other.UpdateDate = DateTime.Now;
- _Other.UpdateBy = userid;
- _Other.address1 = OtherApplicant.address_line1;
- _Other.address2 = OtherApplicant.address_line2;
- _Other.town = OtherApplicant.address_city;
- _Other.postcode = OtherApplicant.address_postcode;
- _Other.ninumber = OtherApplicant.ninnumber;
- _Other.jobtitle = OtherApplicant.jobtitle;
- _Other.dependants = OtherApplicant.dependents;
- _Other.employer = OtherApplicant.employer;
- _Other.accountdetails = OtherApplicant.accountant;
- _Other.dob = Helper.GetDate(OtherApplicant.dob);
- _Other.married = Helper.GetDate(OtherApplicant.weddinganniversary);
- // Delete condition, when all the values are null
- if (string.IsNullOrWhiteSpace(_Other.FirstName) && string.IsNullOrWhiteSpace(_Other.SurName) && string.IsNullOrWhiteSpace(_Other.MobileNumber) && string.IsNullOrWhiteSpace(_Other.Email) && string.IsNullOrWhiteSpace(_Other.address1) && string.IsNullOrWhiteSpace(_Other.address2) && string.IsNullOrWhiteSpace(_Other.town) && string.IsNullOrWhiteSpace(_Other.postcode) && string.IsNullOrWhiteSpace(_Other.ninumber) && string.IsNullOrWhiteSpace(_Other.jobtitle) && (_Other.married) == null && string.IsNullOrWhiteSpace(_Other.dependants) && string.IsNullOrWhiteSpace(_Other.accountdetails) && string.IsNullOrWhiteSpace(_Other.employer) && (_Other.dob) == null)
- {
- ctx.tblOtherApplicants.Remove(_Other);
- }
- ctx.SaveChanges();
- }
- }
- else // Add
- {
- if ((OtherApplicant != null && (!string.IsNullOrWhiteSpace(OtherApplicant.FirstName) || !string.IsNullOrWhiteSpace(OtherApplicant.SurName) || !string.IsNullOrWhiteSpace(OtherApplicant.Email) || !string.IsNullOrWhiteSpace(OtherApplicant.MobileNumber) || !string.IsNullOrWhiteSpace(OtherApplicant.address_line1) || !string.IsNullOrWhiteSpace(OtherApplicant.address_line2) || !string.IsNullOrWhiteSpace(OtherApplicant.address_city) || !string.IsNullOrWhiteSpace(OtherApplicant.address_postcode) || !string.IsNullOrWhiteSpace(OtherApplicant.ninnumber) || !string.IsNullOrWhiteSpace(OtherApplicant.jobtitle) || (OtherApplicant.weddinganniversary) != null || !string.IsNullOrWhiteSpace(OtherApplicant.dependents) || !string.IsNullOrWhiteSpace(OtherApplicant.accountant) || (OtherApplicant.dob) != null || !string.IsNullOrWhiteSpace(OtherApplicant.employer))) && !ctx.tblOtherApplicants.Where(c => c.MainContactId == contact.contactid).Any())
- {
- var _Other = new tblOtherApplicant();
- _Other.Email = OtherApplicant.Email;
- _Other.FirstName = OtherApplicant.FirstName;
- _Other.SurName = OtherApplicant.SurName;
- _Other.MobileNumber = OtherApplicant.MobileNumber;
- _Other.AddDate = DateTime.Now;
- _Other.EntryBy = userid;
- _Other.IsDelete = false;
- _Other.IsActive = true;
- _Other.MainContactId = contact.contactid;
- _Other.address1 = OtherApplicant.address_line1;
- _Other.address2 = OtherApplicant.address_line2;
- _Other.town = OtherApplicant.address_city;
- _Other.postcode = OtherApplicant.address_postcode;
- _Other.ninumber = OtherApplicant.ninnumber;
- _Other.jobtitle = OtherApplicant.jobtitle;
- _Other.dependants = OtherApplicant.dependents;
- _Other.employer = OtherApplicant.employer;
- _Other.accountdetails = OtherApplicant.accountant;
- _Other.dob = Helper.GetDate(OtherApplicant.dob);
- _Other.married = Helper.GetDate(OtherApplicant.weddinganniversary);
- ctx.tblOtherApplicants.Add(_Other);
- ctx.SaveChanges();
- }
- }
- }
- //***********************************
- }
- #endregion
- #region finance_mortage
- foreach (Mortgage mortage in MortgageList)
- {
- int oldStatusId;
- var _chkUpdate = (CheckStatusUpdate(mortage.mortage_financeid, mortage.mortage_mortgagesubtype, out oldStatusId));
- if (mortage.mortage_financeid != 0)
- {
- tblfinance finance = ctx.tblfinances.Where(x => x.financeid == mortage.mortage_financeid).FirstOrDefault();
- if (finance != null)
- {
- //tblfinance_mortgage
- tblfinance_mortgage finance_mortgage = ctx.tblfinance_mortgage.Where(x => x.financeid == mortage.mortage_financeid).FirstOrDefault();
- if (finance_mortgage != null && mortage.mortage_mortgagesubtype != 0)
- {
- //update mortage
- finance_mortgage.solicitor = mortage.mortage_solicitor;
- finance_mortgage.purchase = mortage.mortage_propertyvalue;
- finance_mortgage.mortgagesubtype = mortage.mortage_reason;
- finance_mortgage.deposit = mortage.mortage_deposit;
- finance_mortgage.income = mortage.mortage_income;
- finance_mortgage.rterm = mortage.mortage_rterm;
- finance_mortgage.completed = Helper.GetDate(mortage.mortage_completiondate);
- finance_mortgage.exchanged = Helper.GetDate(mortage.mortage_exchangedate);
- finance_mortgage.remortgagedate = Helper.GetDate(mortage.mortage_remortagedate);
- newremortage = mortage.newremortgagedate;
- //Added on 2014-11-24
- finance_mortgage.remortgagecontact = Helper.GetDate(mortage.mortgage_remortgagecontact);
- remortgageContact = mortage.remortgagecontact;
- finance_mortgage.Rate = mortage.mortage_rate;
- finance_mortgage.RateType = mortage.RateType;
- //update finance.
- if (finance != null)
- {
- var flag = false;
- if (Convert.ToInt32(finance.status) != mortage.mortage_mortgagesubtype)
- {
- flag = true;
- }
- else if (finance.subtype != mortage.mortage_type)
- {
- flag = true;
- }
- else if (finance.policyreference != mortage.mortage_mortageaccountno)
- {
- flag = true;
- }
- else if (finance.followup != Helper.GetFollowUp(mortage.mortage_date, mortage.mortage_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : mortage.mortage_time))
- {
- flag = true;
- }
- else if (finance.provider != mortage.mortage_lender)
- {
- flag = true;
- }
- else if (finance.amount != mortage.mortage_amount)
- {
- flag = true;
- }
- else if (finance.premium != mortage.mortage_premium)
- {
- flag = true;
- }
- else if (finance.commission != mortage.mortage_commission)
- {
- flag = true;
- }
- else if (finance.datelive != Helper.GetDate(mortage.mortage_datelive))
- {
- flag = true;
- }
- else if (finance.dateexpire != Helper.GetDate(mortage.mortage_expires))
- {
- flag = true;
- }
- else if (finance.fundvalue != mortage.mortage_propertyvalue)
- {
- flag = true;
- }
- else if (finance.Address1 != mortage.mortgage_address1)
- {
- flag = true;
- }
- else if (finance.Address2 != mortage.mortgage_address2)
- {
- flag = true;
- }
- else if (finance.Town != mortage.mortgage_town)
- {
- flag = true;
- }
- else if (finance.County != mortage.mortgage_county)
- {
- flag = true;
- }
- else if (finance.Postcode != mortage.mortgage_postcode)
- {
- flag = true;
- }
- else if(finance.subFinanceStatus != mortage.mortgage_SubFinanceStatus)
- {
- flag = true;
- }
- else if (finance.ClientFee != null || mortage.mortgage_Clientfee != 0)
- {
- if (finance.ClientFee != mortage.mortgage_Clientfee)
- {
- flag = true;
- }
- }
- else
- {
- flag = false;
- }
- if (flag)
- {
- finance.status = mortage.mortage_mortgagesubtype;
- finance.subtype = mortage.mortage_type;
- finance.policyreference = mortage.mortage_mortageaccountno;
- finance.followup = Helper.GetFollowUp(mortage.mortage_date, mortage.mortage_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : mortage.mortage_time);
- finance.provider = mortage.mortage_lender;
- finance.amount = mortage.mortage_amount;
- finance.premium = mortage.mortage_premium;
- finance.commission = mortage.mortage_commission;
- finance.details = null;
- finance.updated = System.DateTime.Now;
- finance.datelive = Helper.GetDate(mortage.mortage_datelive);
- finance.dateexpire = Helper.GetDate(mortage.mortage_expires);
- finance.fundvalue = mortage.mortage_propertyvalue;
- finance.Address1 = mortage.mortgage_address1;
- finance.Address2 = mortage.mortgage_address2;
- finance.Town = mortage.mortgage_town;
- finance.County = mortage.mortgage_county;
- finance.Postcode = mortage.mortgage_postcode;
- finance.ClientFee = mortage.mortgage_Clientfee;
- finance.subFinanceStatus = mortage.mortgage_SubFinanceStatus;
- }
- }
- }
- else
- {
- tblfinance_mortgage newfinancemortage = new tblfinance_mortgage();
- newfinancemortage.financeid = mortage.mortage_financeid;
- newfinancemortage.solicitor = mortage.mortage_solicitor;
- newfinancemortage.purchase = mortage.mortage_propertyvalue;
- newfinancemortage.mortgagesubtype = mortage.mortage_mortgagesubtype;
- newfinancemortage.deposit = mortage.mortage_deposit;
- newfinancemortage.income = mortage.mortage_income;
- newfinancemortage.rterm = mortage.mortage_rterm;
- newfinancemortage.completed = Helper.GetDate(mortage.mortage_completiondate);
- newfinancemortage.exchanged = Helper.GetDate(mortage.mortage_exchangedate);
- newfinancemortage.remortgagedate = Helper.GetDate(mortage.mortage_remortagedate);
- //Added on 2014-11-24
- newfinancemortage.remortgagecontact = Helper.GetDate(mortage.mortgage_remortgagecontact);
- newfinancemortage.Rate = mortage.mortage_rate;
- newfinancemortage.RateType = mortage.RateType;
- ctx.tblfinance_mortgage.Add(newfinancemortage);
- }
- }
- }
- else
- {
- if (mortage.mortage_mortgagesubtype != 0)
- {
- tblfinance newfinance = new tblfinance();
- newfinance.status = mortage.mortage_mortgagesubtype;
- newfinance.subtype = mortage.mortage_type;
- newfinance.policyreference = mortage.mortage_mortageaccountno;
- if (mortage.mortage_mortgagesubtype == (int)MortgageStatus.Remortgage)
- {
- newfinance.followup = (mortage.mortage_date != null ? mortage.mortage_date.GetDateTime() : null);
- }
- else
- newfinance.followup = Helper.GetFollowUp(mortage.mortage_date, mortage.mortage_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : mortage.mortage_time);
- newfinance.parentFinanceId = mortage.mortage_remortgageComplete;
- newfinance.provider = mortage.mortage_lender;
- newfinance.amount = mortage.mortage_amount;
- newfinance.premium = mortage.mortage_premium;
- newfinance.commission = mortage.mortage_commission;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(mortage.mortage_datelive);
- newfinance.dateexpire = Helper.GetDate(mortage.mortage_expires);
- newfinance.fundvalue = mortage.mortage_propertyvalue;
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Mortgages;
- newfinance.created = System.DateTime.Now;
- newfinance.Address1 = mortage.mortgage_address1;
- newfinance.Address2 = mortage.mortgage_address2;
- newfinance.Town = mortage.mortgage_town;
- newfinance.County = mortage.mortgage_county;
- newfinance.Postcode = mortage.mortgage_postcode;
- newfinance.ClientFee = mortage.mortgage_Clientfee;
- newfinance.subFinanceStatus = mortage.mortgage_SubFinanceStatus;
- ctx.tblfinances.Add(newfinance);
- tblfinance_mortgage newfinancemortage = new tblfinance_mortgage();
- newfinancemortage.solicitor = mortage.mortage_solicitor;
- newfinancemortage.purchase = mortage.mortage_propertyvalue;
- newfinancemortage.mortgagesubtype = mortage.mortage_mortgagesubtype;
- newfinancemortage.deposit = mortage.mortage_deposit;
- newfinancemortage.income = mortage.mortage_income;
- newfinancemortage.rterm = mortage.mortage_rterm;
- newfinancemortage.completed = Helper.GetDate(mortage.mortage_completiondate);
- newfinancemortage.exchanged = Helper.GetDate(mortage.mortage_exchangedate);
- newfinancemortage.remortgagedate = Helper.GetDate(mortage.mortage_remortagedate);
- //Added on 2014-11-24
- newfinancemortage.remortgagecontact = Helper.GetDate(mortage.mortgage_remortgagecontact);
- newfinancemortage.Rate = mortage.mortage_rate;
- newfinancemortage.RateType = mortage.RateType;
- ctx.tblfinance_mortgage.Add(newfinancemortage);
- }
- }
- if (mortage.mortage_mortgagesubtype != 0)
- {
- financeId = mortage.mortage_financeid;
- status = mortage.mortage_mortgagesubtype;
- if (mortage.mortage_notes != null)
- {
- tblnote mortagenote = new tblnote();
- mortagenote.financeid = mortage.mortage_financeid;
- mortagenote.contact = _address.contactid;
- mortagenote.note = mortage.mortage_notes.Length > 8000 ? mortage.mortage_notes.Substring(0, 7999) : mortage.mortage_notes;
- mortagenote.created = System.DateTime.Now;
- mortagenote.UserId = userid;
- mortagenote.allowInReport = mortage_notes_allow;
- ctx.tblnotes.Add(mortagenote);
- }
- else
- {
- if (_chkUpdate)
- {
- tblnote mortagenoteforstatus = new tblnote();
- mortagenoteforstatus.financeid = mortage.mortage_financeid;
- mortagenoteforstatus.contact = _address.contactid;
- if (oldStatusId != 0)
- {
- mortagenoteforstatus.note = string.Format("Status changes from {0} to {1} on {2} at {3} by {4}", ctx.tblfinancestatus.Where(x => x.statusid == oldStatusId).Select(x => x.name).FirstOrDefault(), ctx.tblfinancestatus.Where(x => x.statusid == mortage.mortage_mortgagesubtype).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- else
- {
- mortagenoteforstatus.note = string.Format(" Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == mortage.mortage_mortgagesubtype).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- mortagenoteforstatus.created = System.DateTime.Now;
- mortagenoteforstatus.UserId = userid;
- ctx.tblnotes.Add(mortagenoteforstatus);
- //_noteid++;
- }
- }
- }
- ctx.SaveChanges();
- }
- #endregion
- #region finance_Life
- //Insurance or life
- foreach (Life life in LifeList)
- {
- int oldStatusId;
- var _chkLifeupdate = CheckStatusUpdate(life.life_financeid, life.life_status, out oldStatusId);
- if (life.life_financeid != 0 && life.life_status != 0)
- {
- var queryInsurance = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join fi in ctx.tblfinance_insurance on ft.financeid equals fi.financeid
- where ft.contact == _address.contactid && ft.type == life.life_financetype && ft.financeid == life.life_financeid
- select new { fi }).FirstOrDefault();
- if (queryInsurance != null && life.life_financeid > 0)
- {
- tblfinance_insurance finance_insurance = ctx.tblfinance_insurance.Where(x => x.financeid == queryInsurance.fi.financeid).FirstOrDefault();
- if (finance_insurance != null)
- {
- //update
- finance_insurance.smoker = life.life_issmoker;
- finance_insurance.height = life.life_height;
- finance_insurance.weight = life.life_weight;
- finance_insurance.doctor = life.life_doctor;
- }
- else
- {
- //insert
- tblfinance_insurance newfinance_insurance = new tblfinance_insurance();
- newfinance_insurance.smoker = life.life_issmoker;
- newfinance_insurance.height = life.life_height;
- newfinance_insurance.weight = life.life_weight;
- newfinance_insurance.doctor = life.life_doctor;
- newfinance_insurance.financeid = life.life_financeid;
- ctx.tblfinance_insurance.Add(newfinance_insurance);
- }
- //update finance.
- tblfinance finance_life = ctx.tblfinances.Where(x => x.financeid == queryInsurance.fi.financeid).FirstOrDefault();
- if (finance_life != null)
- {
- var flag = false;
- if (finance_life.status != life.life_status)
- {
- flag = true;
- }
- else if (finance_life.subtype != life.life_policytype)
- {
- flag = true;
- }
- else if (finance_life.policyreference != life.life_policyref)
- {
- flag = true;
- }
- else if (finance_life.followup != Helper.GetFollowUp(life.life_date, life.life_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : life.life_time))
- {
- flag = true;
- }
- else if (finance_life.provider != life.life_provider)
- {
- flag = true;
- }
- else if (finance_life.amount != life.life_amount)
- {
- flag = true;
- }
- else if (finance_life.premium != life.life_premium)
- {
- flag = true;
- }
- else if (finance_life.commission != life.life_commission)
- {
- flag = true;
- }
- else if (finance_life.details != life.life_medical)
- {
- flag = true;
- }
- else if (finance_life.datelive != Helper.GetDate(life.life_datelive))
- {
- flag = true;
- }
- else if (finance_life.dateexpire != Helper.GetDate(life.life_expires))
- {
- flag = true;
- }
- else if (finance_life.isPolicyForOtherApplicant != life.life_isPolicyForOtherApplicant)
- {
- flag = true;
- }
- else if (finance_life.ClientFee != null || life.life_Clientfee != 0)
- {
- if (finance_life.ClientFee != life.life_Clientfee)
- {
- flag = true;
- }
- }
- else
- {
- flag = false;
- }
- if (flag)
- {
- finance_life.status = life.life_status;
- finance_life.subtype = life.life_policytype;
- finance_life.policyreference = life.life_policyref;
- finance_life.followup = Helper.GetFollowUp(life.life_date, life.life_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : life.life_time);
- finance_life.provider = life.life_provider;
- finance_life.amount = life.life_amount;
- finance_life.premium = life.life_premium;
- finance_life.commission = life.life_commission;
- finance_life.details = life.life_medical;
- finance_life.updated = System.DateTime.Now;
- finance_life.datelive = Helper.GetDate(life.life_datelive);
- finance_life.dateexpire = Helper.GetDate(life.life_expires);
- //Added Client Fee 27-10-2014
- finance_life.ClientFee = life.life_Clientfee;
- //********************************
- //added on 03-04-2015
- finance_life.isPolicyForOtherApplicant = life.life_isPolicyForOtherApplicant;
- }
- }
- }
- else
- {
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Life;
- newfinance.status = life.life_status;
- newfinance.subtype = life.life_policytype;
- newfinance.policyreference = life.life_policyref;
- newfinance.followup = Helper.GetFollowUp(life.life_date, life.life_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : life.life_time);
- newfinance.provider = life.life_provider;
- newfinance.amount = life.life_amount;
- newfinance.premium = life.life_premium;
- newfinance.commission = life.life_commission;
- newfinance.details = life.life_medical;
- newfinance.updated = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(life.life_datelive);
- newfinance.dateexpire = Helper.GetDate(life.life_expires);
- newfinance.created = System.DateTime.Now;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = life.life_Clientfee;
- //********************************
- //added on 03-04-2015
- newfinance.isPolicyForOtherApplicant = life.life_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_insurance newfinance_insurance = new tblfinance_insurance();
- newfinance_insurance.smoker = life.life_issmoker;
- newfinance_insurance.height = life.life_height;
- newfinance_insurance.weight = life.life_weight;
- newfinance_insurance.doctor = life.life_doctor;
- ctx.tblfinance_insurance.Add(newfinance_insurance);
- }
- }
- else
- {
- if (life.life_status != 0)
- {
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Life;
- newfinance.status = life.life_status;
- newfinance.subtype = life.life_policytype;
- newfinance.policyreference = life.life_policyref;
- newfinance.followup = Helper.GetFollowUp(life.life_date, life.life_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : life.life_time);
- newfinance.provider = life.life_provider;
- newfinance.amount = life.life_amount;
- newfinance.premium = life.life_premium;
- newfinance.commission = life.life_commission;
- newfinance.details = life.life_medical;
- newfinance.updated = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(life.life_datelive);
- newfinance.dateexpire = Helper.GetDate(life.life_expires);
- newfinance.created = System.DateTime.Now;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = life.life_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = life.life_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_insurance newfinance_insurance = new tblfinance_insurance();
- newfinance_insurance.smoker = life.life_issmoker;
- newfinance_insurance.height = life.life_height;
- newfinance_insurance.weight = life.life_weight;
- newfinance_insurance.doctor = life.life_doctor;
- ctx.tblfinance_insurance.Add(newfinance_insurance);
- }
- }
- if (life.life_status != 0)
- {
- financeId = life.life_financeid;
- status = life.life_status;
- if (life.life_notes != null)
- {
- tblnote lifenote = new tblnote();
- lifenote.financeid = life.life_financeid;
- lifenote.contact = _address.contactid;
- lifenote.note = life.life_notes.Length > 8000 ? life.life_notes.Substring(0, 7999) : life.life_notes;
- lifenote.created = System.DateTime.Now;
- lifenote.UserId = userid;
- lifenote.allowInReport = mortage_notes_allow;
- ctx.tblnotes.Add(lifenote);
- }
- else
- {
- if (_chkLifeupdate)
- {
- tblnote lifenoteforstatus = new tblnote();
- lifenoteforstatus.financeid = life.life_financeid;
- lifenoteforstatus.contact = _address.contactid;
- if (oldStatusId != 0)
- {
- lifenoteforstatus.note = string.Format("Status changes from {0} to {1} on {2} at {3} by {4}", ctx.tblfinancestatus.Where(x => x.statusid == oldStatusId).Select(x => x.name).FirstOrDefault(), ctx.tblfinancestatus.Where(x => x.statusid == life.life_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- else
- {
- lifenoteforstatus.note = string.Format("Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == life.life_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- lifenoteforstatus.created = System.DateTime.Now;
- lifenoteforstatus.UserId = userid;
- ctx.tblnotes.Add(lifenoteforstatus);
- }
- }
- }
- ctx.SaveChanges();
- }
- #endregion
- #region finance_Building
- foreach (BuildingContent buildingcontent in BuildinbContentList)
- {
- int oldStatusId;
- var _chkbuildingUpdate = CheckStatusUpdate(buildingcontent.buildingcontent_financeid, buildingcontent.buildingcontent_status, out oldStatusId);
- if (buildingcontent.buildingcontent_financeid != 0 && buildingcontent.buildingcontent_status != 0)
- {
- var queryBuilding = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join fb in ctx.tblfinance_buildings on ft.financeid equals fb.financeid
- where ft.contact == _address.contactid && ft.type == buildingcontent.buildingcontent_financetype && ft.financeid == buildingcontent.buildingcontent_financeid
- select new { fb }).FirstOrDefault();
- if (queryBuilding != null || buildingcontent.buildingcontent_financeid > 0)
- {
- tblfinance_buildings buildings = ctx.tblfinance_buildings.Where(x => x.financeid == queryBuilding.fb.financeid).FirstOrDefault();
- if (buildings != null)
- {
- //update
- buildings.rebuild = buildingcontent.buildingcontent_rebuildvalue;
- buildings.alarm = buildingcontent.buildingcontent_isalarmed;
- }
- else
- {
- //insert
- tblfinance_buildings newfinance_building = new tblfinance_buildings();
- newfinance_building.rebuild = buildingcontent.buildingcontent_rebuildvalue;
- newfinance_building.alarm = buildingcontent.buildingcontent_isalarmed;
- newfinance_building.financeid = buildingcontent.buildingcontent_financeid;
- ctx.tblfinance_buildings.Add(newfinance_building);
- }
- //update finance.
- tblfinance finance_building = ctx.tblfinances.Where(x => x.financeid == queryBuilding.fb.financeid).FirstOrDefault();
- if (finance_building != null)
- {
- var flag = false;
- if (finance_building.status != buildingcontent.buildingcontent_status)
- {
- flag = true;
- }
- else if (finance_building.policyreference != buildingcontent.buildingcontent_policyref)
- {
- flag = true;
- }
- else if (finance_building.followup != Helper.GetFollowUp(buildingcontent.buildingcontent_date, buildingcontent.buildingcontent_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : buildingcontent.buildingcontent_time))
- {
- flag = true;
- }
- else if (finance_building.provider != buildingcontent.buildingcontent_provider)
- {
- flag = true;
- }
- else if (finance_building.amount != buildingcontent.buildingcontent_amount)
- {
- flag = true;
- }
- else if (finance_building.premium != buildingcontent.buildingcontent_premium)
- {
- flag = true;
- }
- else if (finance_building.commission != buildingcontent.buildingcontent_commission)
- {
- flag = true;
- }
- else if (finance_building.subtype != buildingcontent.buildingcontent_type)
- {
- flag = true;
- }
- else if (finance_building.details != buildingcontent.buildingcontent_addcover)
- {
- flag = true;
- }
- else if (finance_building.datelive != Helper.GetDate(buildingcontent.buildingcontent_datelive))
- {
- flag = true;
- }
- else if (finance_building.dateexpire != Helper.GetDate(buildingcontent.buildingcontent_expires))
- {
- flag = true;
- }
- else if (finance_building.isPolicyForOtherApplicant != buildingcontent.buildingcontent_isPolicyForOtherApplicant)
- {
- flag = true;
- }
- else if (finance_building.ClientFee != null || buildingcontent.building_Clientfee != 0)
- {
- if (finance_building.ClientFee != buildingcontent.building_Clientfee)
- {
- flag = true;
- }
- }
- else
- {
- flag = false;
- }
- if (flag)
- {
- finance_building.status = buildingcontent.buildingcontent_status;
- finance_building.policyreference = buildingcontent.buildingcontent_policyref;
- finance_building.followup = Helper.GetFollowUp(buildingcontent.buildingcontent_date, buildingcontent.buildingcontent_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : buildingcontent.buildingcontent_time);
- finance_building.provider = buildingcontent.buildingcontent_provider;
- finance_building.amount = buildingcontent.buildingcontent_amount;
- finance_building.premium = buildingcontent.buildingcontent_premium;
- finance_building.commission = buildingcontent.buildingcontent_commission;
- finance_building.subtype = buildingcontent.buildingcontent_type;
- finance_building.details = buildingcontent.buildingcontent_addcover;
- finance_building.updated = System.DateTime.Now;
- finance_building.datelive = Helper.GetDate(buildingcontent.buildingcontent_datelive);
- finance_building.dateexpire = Helper.GetDate(buildingcontent.buildingcontent_expires);
- //Added Client Fee 27-10-2014
- finance_building.ClientFee = buildingcontent.building_Clientfee;
- //********************************
- finance_building.isPolicyForOtherApplicant = buildingcontent.buildingcontent_isPolicyForOtherApplicant;
- }
- }
- }
- else
- {
- if (buildingcontent.buildingcontent_status != 0)
- {
- //finance
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.BuildingsOrContents;
- newfinance.status = buildingcontent.buildingcontent_status;
- newfinance.subtype = buildingcontent.buildingcontent_type;
- newfinance.policyreference = buildingcontent.buildingcontent_policyref;
- newfinance.followup = Helper.GetFollowUp(buildingcontent.buildingcontent_date, buildingcontent.buildingcontent_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : buildingcontent.buildingcontent_time);
- newfinance.provider = buildingcontent.buildingcontent_provider;
- newfinance.amount = buildingcontent.buildingcontent_amount;
- newfinance.premium = buildingcontent.buildingcontent_premium;
- newfinance.commission = buildingcontent.buildingcontent_commission;
- newfinance.details = buildingcontent.buildingcontent_addcover;
- newfinance.updated = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(buildingcontent.buildingcontent_datelive);
- newfinance.dateexpire = Helper.GetDate(buildingcontent.buildingcontent_expires);
- newfinance.created = System.DateTime.Now;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = buildingcontent.building_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = buildingcontent.buildingcontent_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_buildings newfinance_building = new tblfinance_buildings();
- newfinance_building.rebuild = buildingcontent.buildingcontent_rebuildvalue;
- newfinance_building.alarm = buildingcontent.buildingcontent_isalarmed;
- ctx.tblfinance_buildings.Add(newfinance_building);
- }
- }
- }
- else
- {
- if (buildingcontent.buildingcontent_status != 0)
- {
- //finance
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.BuildingsOrContents;
- newfinance.status = buildingcontent.buildingcontent_status;
- newfinance.subtype = buildingcontent.buildingcontent_type;
- newfinance.policyreference = buildingcontent.buildingcontent_policyref;
- newfinance.followup = Helper.GetFollowUp(buildingcontent.buildingcontent_date, buildingcontent.buildingcontent_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : buildingcontent.buildingcontent_time);
- newfinance.provider = buildingcontent.buildingcontent_provider;
- newfinance.amount = buildingcontent.buildingcontent_amount;
- newfinance.premium = buildingcontent.buildingcontent_premium;
- newfinance.commission = buildingcontent.buildingcontent_commission;
- newfinance.details = buildingcontent.buildingcontent_addcover;
- newfinance.updated = System.DateTime.Now;
- newfinance.created = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(buildingcontent.buildingcontent_datelive);
- newfinance.dateexpire = Helper.GetDate(buildingcontent.buildingcontent_expires);
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = buildingcontent.building_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = buildingcontent.buildingcontent_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_buildings newfinance_building = new tblfinance_buildings();
- newfinance_building.rebuild = buildingcontent.buildingcontent_rebuildvalue;
- newfinance_building.alarm = buildingcontent.buildingcontent_isalarmed;
- ctx.tblfinance_buildings.Add(newfinance_building);
- }
- }
- if (buildingcontent.buildingcontent_status != 0)
- {
- financeId = buildingcontent.buildingcontent_financeid;
- status = buildingcontent.buildingcontent_status;
- if (buildingcontent.buildingcontent_notes != null)
- {
- tblnote buildingcontentnote = new tblnote();
- buildingcontentnote.financeid = buildingcontent.buildingcontent_financeid;
- buildingcontentnote.contact = _address.contactid;
- buildingcontentnote.note = buildingcontent.buildingcontent_notes.Length > 8000 ? buildingcontent.buildingcontent_notes.Substring(0, 7999) : buildingcontent.buildingcontent_notes;
- buildingcontentnote.created = System.DateTime.Now;
- buildingcontentnote.UserId = userid;
- buildingcontentnote.allowInReport = mortage_notes_allow;
- ctx.tblnotes.Add(buildingcontentnote);
- }
- else
- {
- if (_chkbuildingUpdate)
- {
- tblnote buildingcontentnoteforstatus = new tblnote();
- buildingcontentnoteforstatus.financeid = buildingcontent.buildingcontent_financeid;
- buildingcontentnoteforstatus.contact = _address.contactid;
- if (oldStatusId != 0)
- {
- buildingcontentnoteforstatus.note = string.Format("Status changes from {0} to {1} on {2} at {3} by {4}", ctx.tblfinancestatus.Where(x => x.statusid == oldStatusId).Select(x => x.name).FirstOrDefault(), ctx.tblfinancestatus.Where(x => x.statusid == buildingcontent.buildingcontent_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- else
- {
- buildingcontentnoteforstatus.note = string.Format("Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == buildingcontent.buildingcontent_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- buildingcontentnoteforstatus.created = System.DateTime.Now;
- buildingcontentnoteforstatus.UserId = userid;
- ctx.tblnotes.Add(buildingcontentnoteforstatus);
- }
- }
- }
- ctx.SaveChanges();
- }
- #endregion
- #region finance_Pension
- foreach (Pensions pension in PensionList)
- {
- int oldStatusId;
- var _chkPensionUpdate = CheckStatusUpdate(pension.pension_financeid, pension.pension_status, out oldStatusId);
- if (pension.pension_financeid != 0 && pension.pension_status != 0)
- {
- var queryPension = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join fp in ctx.tblfinance_pension on ft.financeid equals fp.financeid
- where ft.contact == _address.contactid && ft.type == pension.pension_financetype && ft.financeid == pension.pension_financeid
- select new { fp }).FirstOrDefault();
- if (queryPension != null || pension.pension_financeid > 0)
- {
- tblfinance_pension pensionnew = ctx.tblfinance_pension.Where(x => x.financeid == queryPension.fp.financeid).FirstOrDefault();
- if (pensionnew != null)
- {
- //update
- pensionnew.incomereq = pension.pension_incomereq;
- }
- else
- {
- //insert
- tblfinance_pension newfinance_pension = new tblfinance_pension();
- newfinance_pension.incomereq = pension.pension_incomereq;
- newfinance_pension.financeid = pension.pension_financeid;
- ctx.tblfinance_pension.Add(newfinance_pension);
- }
- tblfinance finance_pensions = ctx.tblfinances.Where(x => x.financeid == queryPension.fp.financeid).FirstOrDefault();
- if (finance_pensions != null)
- {
- //update
- //finance
- var flag = false;
- if (finance_pensions.status != pension.pension_status)
- {
- flag = true;
- }
- else if (finance_pensions.subtype != pension.pension_riskprofile)
- {
- flag = true;
- }
- else if (finance_pensions.policyreference != pension.pension_policyref)
- {
- flag = true;
- }
- else if (finance_pensions.followup != Helper.GetFollowUp(pension.pension_date, pension.pension_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : pension.pension_time))
- {
- flag = true;
- }
- else if (finance_pensions.provider != pension.pension_provider)
- {
- flag = true;
- }
- else if (finance_pensions.amount != pension.pension_amount)
- {
- flag = true;
- }
- else if (finance_pensions.premium != pension.pension_contributors)
- {
- flag = true;
- }
- else if (finance_pensions.commission != pension.pension_commission)
- {
- flag = true;
- }
- else if (finance_pensions.datelive != Helper.GetDate(pension.pension_datelive))
- {
- flag = true;
- }
- else if (finance_pensions.dateexpire != Helper.GetDate(pension.pension_expires))
- {
- flag = true;
- }
- else if (finance_pensions.fundvalue != pension.pension_fundvalue)
- {
- flag = true;
- }
- else if (finance_pensions.isPolicyForOtherApplicant != pension.pension_isPolicyForOtherApplicant)
- {
- flag = true;
- }
- else if (finance_pensions.ClientFee != null || pension.pension_Clientfee != 0)
- {
- if (finance_pensions.ClientFee != pension.pension_Clientfee)
- {
- flag = true;
- }
- }
- else
- {
- flag = false;
- }
- if (flag)
- {
- finance_pensions.status = pension.pension_status;
- finance_pensions.subtype = pension.pension_riskprofile;
- finance_pensions.policyreference = pension.pension_policyref;
- finance_pensions.followup = Helper.GetFollowUp(pension.pension_date, pension.pension_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : pension.pension_time);
- finance_pensions.provider = pension.pension_provider;
- finance_pensions.amount = pension.pension_amount;
- finance_pensions.premium = pension.pension_contributors;
- finance_pensions.commission = pension.pension_commission;
- finance_pensions.details = null;
- finance_pensions.updated = System.DateTime.Now;
- finance_pensions.datelive = Helper.GetDate(pension.pension_datelive);
- finance_pensions.dateexpire = Helper.GetDate(pension.pension_expires);
- finance_pensions.fundvalue = pension.pension_fundvalue;
- //Added Client Fee 27-10-2014
- finance_pensions.ClientFee = pension.pension_Clientfee;
- //********************************
- finance_pensions.isPolicyForOtherApplicant = pension.pension_isPolicyForOtherApplicant;
- }
- }
- }
- else
- {
- if (pension.pension_status != 0)
- {
- //finance
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Pensions;
- newfinance.status = pension.pension_status;
- newfinance.subtype = pension.pension_riskprofile;
- newfinance.policyreference = pension.pension_policyref;
- newfinance.followup = Helper.GetFollowUp(pension.pension_date, pension.pension_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : pension.pension_time);
- newfinance.provider = pension.pension_provider;
- newfinance.amount = pension.pension_amount;
- newfinance.premium = pension.pension_contributors;
- newfinance.commission = pension.pension_commission;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.created = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(pension.pension_datelive);
- newfinance.dateexpire = Helper.GetDate(pension.pension_expires);
- newfinance.fundvalue = pension.pension_fundvalue;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = pension.pension_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = pension.pension_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_pension newfinance_pension = new tblfinance_pension();
- newfinance_pension.incomereq = pension.pension_incomereq;
- ctx.tblfinance_pension.Add(newfinance_pension);
- }
- }
- }
- else
- {
- if (pension.pension_status != 0)
- {
- //finance
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Pensions;
- newfinance.status = pension.pension_status;
- newfinance.subtype = pension.pension_riskprofile;
- newfinance.policyreference = pension.pension_policyref;
- newfinance.followup = Helper.GetFollowUp(pension.pension_date, pension.pension_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : pension.pension_time);
- newfinance.provider = pension.pension_provider;
- newfinance.amount = pension.pension_amount;
- newfinance.premium = pension.pension_contributors;
- newfinance.commission = pension.pension_commission;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.created = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(pension.pension_datelive);
- newfinance.dateexpire = Helper.GetDate(pension.pension_expires);
- newfinance.fundvalue = pension.pension_fundvalue;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = pension.pension_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = pension.pension_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_pension newfinance_pension = new tblfinance_pension();
- newfinance_pension.incomereq = pension.pension_incomereq;
- ctx.tblfinance_pension.Add(newfinance_pension);
- }
- }
- if (pension.pension_status != 0)
- {
- financeId = pension.pension_financeid;
- status = pension.pension_status;
- if (pension.pension_notes != null)
- {
- tblnote pensionnote = new tblnote();
- pensionnote.financeid = pension.pension_financeid;
- pensionnote.contact = _address.contactid;
- pensionnote.note = pension.pension_notes.Length > 8000 ? pension.pension_notes.Substring(0, 7999) : pension.pension_notes;
- pensionnote.created = System.DateTime.Now;
- pensionnote.UserId = userid;
- pensionnote.allowInReport = mortage_notes_allow;
- ctx.tblnotes.Add(pensionnote);
- }
- else
- {
- if (_chkPensionUpdate)
- {
- tblnote pensionnoteforstatus = new tblnote();
- pensionnoteforstatus.financeid = pension.pension_financeid;
- pensionnoteforstatus.contact = _address.contactid;
- if (oldStatusId != 0)
- {
- pensionnoteforstatus.note = string.Format("Status changes from {0} to {1} on {2} at {3} by {4}", ctx.tblfinancestatus.Where(x => x.statusid == oldStatusId).Select(x => x.name).FirstOrDefault(), ctx.tblfinancestatus.Where(x => x.statusid == pension.pension_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- else
- {
- pensionnoteforstatus.note = string.Format("Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == pension.pension_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- pensionnoteforstatus.created = System.DateTime.Now;
- pensionnoteforstatus.UserId = userid;
- ctx.tblnotes.Add(pensionnoteforstatus);
- }
- }
- }
- ctx.SaveChanges();
- }
- #endregion
- #region finance_Investment
- // Investment
- foreach (Investment investment in InvestmentList)
- {
- int oldStatusId;
- var _chkInvestUpdate = CheckStatusUpdate(investment.investment_financeid, investment.investment_status, out oldStatusId);
- if (investment.investment_financeid != 0 && investment.investment_status != 0)
- {
- var queryInvestment = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join finv in ctx.tblfinance_investments on ft.financeid equals finv.financeid
- where ft.contact == _address.contactid && ft.type == investment.investment_financetype && ft.financeid == investment.investment_financeid
- select new { finv }).FirstOrDefault();
- if (queryInvestment != null || investment.investment_financeid > 0)
- {
- tblfinance_investments investmentnew = ctx.tblfinance_investments.Where(x => x.financeid == queryInvestment.finv.financeid).FirstOrDefault();
- if (investmentnew == null)
- {
- tblfinance_investments newfinanceinvestment = new tblfinance_investments();
- newfinanceinvestment.financeid = investment.investment_financeid;
- ctx.tblfinance_investments.Add(newfinanceinvestment);
- }
- tblfinance finance_investment = ctx.tblfinances.Where(x => x.financeid == queryInvestment.finv.financeid).FirstOrDefault();
- if (finance_investment != null)
- {
- var flag = false;
- if (finance_investment.status != investment.investment_status)
- {
- flag = true;
- }
- else if (finance_investment.subtype != investment.investment_riskprofiles)
- {
- flag = true;
- }
- else if (finance_investment.policyreference != investment.investment_policyref)
- {
- flag = true;
- }
- else if (finance_investment.followup != Helper.GetFollowUp(investment.investment_date, investment.investment_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : investment.investment_time))
- {
- flag = true;
- }
- else if (finance_investment.provider != investment.investment_provider)
- {
- flag = true;
- }
- else if (finance_investment.amount != investment.investment_amount)
- {
- flag = true;
- }
- else if (finance_investment.premium != investment.investment_contributors)
- {
- flag = true;
- }
- else if (finance_investment.commission != investment.investment_commission)
- {
- flag = true;
- }
- else if (finance_investment.datelive != Helper.GetDate(investment.investment_datelive))
- {
- flag = true;
- }
- else if (finance_investment.dateexpire != Helper.GetDate(investment.investment_expires))
- {
- flag = true;
- }
- else if (finance_investment.fundvalue != investment.investment_fundvalue)
- {
- flag = true;
- }
- else if (finance_investment.isPolicyForOtherApplicant != investment.investment_isPolicyForOtherApplicant)
- {
- flag = true;
- }
- else if (finance_investment.ClientFee != null || investment.investment_Clientfee != 0)
- {
- if (finance_investment.ClientFee != investment.investment_Clientfee)
- {
- flag = true;
- }
- }
- else
- {
- flag = false;
- }
- if (flag)
- {
- finance_investment.status = investment.investment_status;
- finance_investment.subtype = investment.investment_riskprofiles;
- finance_investment.policyreference = investment.investment_policyref;
- finance_investment.followup = Helper.GetFollowUp(investment.investment_date, investment.investment_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : investment.investment_time);
- finance_investment.provider = investment.investment_provider;
- finance_investment.amount = investment.investment_amount;
- finance_investment.premium = investment.investment_contributors;
- finance_investment.commission = investment.investment_commission;
- finance_investment.details = null;
- finance_investment.updated = System.DateTime.Now;
- finance_investment.datelive = Helper.GetDate(investment.investment_datelive);
- finance_investment.dateexpire = Helper.GetDate(investment.investment_expires);
- finance_investment.fundvalue = investment.investment_fundvalue;
- //Added Client Fee 27-10-2014
- finance_investment.ClientFee = investment.investment_Clientfee;
- //********************************
- finance_investment.isPolicyForOtherApplicant = investment.investment_isPolicyForOtherApplicant;
- }
- }
- }
- else
- {
- if (investment.investment_status != 0)
- {
- //insert
- tblfinance_investments newfinanceinvestment = new tblfinance_investments();
- ctx.tblfinance_investments.Add(newfinanceinvestment);
- //finance
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Investments;
- newfinance.status = investment.investment_status;
- newfinance.subtype = investment.investment_riskprofiles;
- newfinance.policyreference = investment.investment_policyref;
- newfinance.followup = Helper.GetFollowUp(investment.investment_date, investment.investment_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : investment.investment_time);
- newfinance.provider = investment.investment_provider;
- newfinance.amount = investment.investment_amount;
- newfinance.premium = investment.investment_contributors;
- newfinance.commission = investment.investment_commission;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.created = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(investment.investment_datelive);
- newfinance.dateexpire = Helper.GetDate(investment.investment_expires);
- newfinance.fundvalue = investment.investment_fundvalue;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = investment.investment_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = investment.investment_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- }
- }
- }
- else
- {
- if (investment.investment_status != 0)
- {
- //insert
- tblfinance_investments newfinanceinvestment = new tblfinance_investments();
- ctx.tblfinance_investments.Add(newfinanceinvestment);
- //finance
- tblfinance newfinance = new tblfinance();
- newfinance.contact = _address.contactid;
- newfinance.type = (int)FinanceTypes.Investments;
- newfinance.status = investment.investment_status;
- newfinance.subtype = investment.investment_riskprofiles;
- newfinance.policyreference = investment.investment_policyref;
- newfinance.followup = Helper.GetFollowUp(investment.investment_date, investment.investment_time == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : investment.investment_time);
- newfinance.provider = investment.investment_provider;
- newfinance.amount = investment.investment_amount;
- newfinance.premium = investment.investment_contributors;
- newfinance.commission = investment.investment_commission;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.created = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(investment.investment_datelive);
- newfinance.dateexpire = Helper.GetDate(investment.investment_expires);
- newfinance.fundvalue = investment.investment_fundvalue;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = investment.investment_Clientfee;
- //********************************
- newfinance.isPolicyForOtherApplicant = investment.investment_isPolicyForOtherApplicant;
- ctx.tblfinances.Add(newfinance);
- }
- }
- if (investment.investment_status != 0)
- {
- financeId = investment.investment_financeid;
- status = investment.investment_status;
- if (investment.investment_notes != null)
- {
- tblnote investmentnote = new tblnote();
- investmentnote.financeid = investment.investment_financeid;
- investmentnote.contact = _address.contactid;
- investmentnote.note = investment.investment_notes.Length > 8000 ? investment.investment_notes.Substring(0, 7999) : investment.investment_notes;
- investmentnote.created = System.DateTime.Now;
- investmentnote.UserId = userid;
- investmentnote.allowInReport=mortage_notes_allow;
- ctx.tblnotes.Add(investmentnote);
- }
- else
- {
- if (_chkInvestUpdate)
- {
- tblnote investmentnoteforstatus = new tblnote();
- investmentnoteforstatus.financeid = investment.investment_financeid;
- investmentnoteforstatus.contact = _address.contactid;
- if (oldStatusId != 0)
- {
- investmentnoteforstatus.note = string.Format("Status changes from {0} to {1} on {2} at {3} by {4}", ctx.tblfinancestatus.Where(x => x.statusid == oldStatusId).Select(x => x.name).FirstOrDefault(), ctx.tblfinancestatus.Where(x => x.statusid == investment.investment_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- else
- {
- investmentnoteforstatus.note = string.Format("Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == investment.investment_status).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userid).Select(x => x.brokername).FirstOrDefault());
- }
- investmentnoteforstatus.created = System.DateTime.Now;
- investmentnoteforstatus.UserId = userid;
- ctx.tblnotes.Add(investmentnoteforstatus);
- }
- }
- }
- ctx.SaveChanges();
- }
- #endregion
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "UpdateApplicationform", ex.Message);
- throw;
- }
- }
- #endregion [Update Application Form 2015-03-31]
- #region [Get application form details 2015-03-31]
- /// <summary>
- /// Get application form details
- /// </summary>
- /// <param name="appid"></param>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public ApplicationForm GetApplicationForm(int appid, int contactid, int financeid)
- {
- int count = 1;
- ApplicationForm formdata = new ApplicationForm();
- int mortage_statusid = GetFinanceType(FinanceType.Mortgages);
- int life_statusid = GetFinanceType(FinanceType.Life);
- int buildingcontent_statusid = GetFinanceType(FinanceType.BuildingsOrContents);
- int pension_statusid = GetFinanceType(FinanceType.Pensions);
- int investment_statusid = GetFinanceType(FinanceType.Investments);
- AddProducts addproducts = new AddProducts();
- #region contact
- //Contact
- tblcontact contact = ctx.tblcontacts.Where(x => x.contactid == contactid).FirstOrDefault();
- if (contact != null)
- {
- formdata.FirstName = contact.firstname;
- formdata.LastName = contact.lastname;
- formdata.Email = contact.email;
- formdata.Telephone = contact.telephone;
- formdata.Email = contact.email;
- formdata.Method = contact.method;
- formdata.Broker = contact.broker ?? 0;
- formdata.ContactUserName = contact.ContactUserName ?? "";
- formdata.ContactPassword = contact.ContactPassword ?? "";
- formdata.Companyname = contact.tblaccount.companyname;
- if (contact.offerqualified.HasValue && contact.offerqualified != null)
- {
- formdata.IsOfferQualified = contact.offerqualified.Value;
- }
- if (contact.slamet != null)
- {
- if (contact.slamet.Value == true)
- formdata.ContactIn2Hrs = 1;
- else
- formdata.ContactIn2Hrs = 2;
- }
- else
- formdata.ContactIn2Hrs = 0;
- formdata.clientname = contact.firstname + " " + contact.lastname;
- formdata.negotiator = GetNegotiatorNameById(contact.NegrefId);//contact.negref;
- //added on 2015-03-03
- formdata.branch = GetBranchNameById(contact.BranchId);//contact.branch;
- formdata.account = Convert.ToInt32(contact.account);
- formdata.parentContactId = (contact.parentContactId ?? 0).ToString();
- var parentContact = ctx.tblcontacts.Where(x => x.contactid == contact.parentContactId).Select(x =>
- new
- {
- x.firstname,
- x.lastname,
- x.email,
- x.telephone
- }).FirstOrDefault();
- if (parentContact != null)
- formdata.parentContactName = (parentContact.firstname ?? "") + " " + (parentContact.lastname ?? "") + ", " + parentContact.email.GetStringForReferral() + ", " + parentContact.telephone.GetStringForReferral();
- }
- #endregion
- #region Mortage/Finance
- var mortageids = ctx.tblfinancestatus.Where(x => x.type == mortage_statusid && x.statusid != 34).ToList().Select(s => s.statusid);
- var mortagequery = ctx.tblfinances.Where(x => mortageids.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- var FirstFinanceId = 0;
- if (mortagequery.Count() > 0)
- FirstFinanceId = (int)mortagequery[0];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- int indexOfCurrentF = mortagequery.IndexOf(financeid);
- if (indexOfCurrentF > -1)
- FirstFinanceId = mortagequery[indexOfCurrentF];
- //End:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance financedata = ctx.tblfinances.Where(x => x.financeid == FirstFinanceId).FirstOrDefault();
- //Bind Mortgage tab from finance table
- if (financedata != null)
- {
- Mortgage mortgage = new Mortgage();
- mortgage.mortage_financeid = financedata.financeid;
- formdata.contactid = financedata.contact ?? 0;
- formdata.AppicationType = financedata.type ?? 0;
- mortgage.mortage_mortgagesubtype = financedata.status ?? 0;
- mortgage.mortage_mortageaccountno = financedata.policyreference;
- mortgage.mortage_lender = financedata.provider;
- mortgage.mortage_amount = financedata.amount.HasValue ? (decimal?)Math.Round(financedata.amount.Value, 2) : null;
- mortgage.mortage_premium = financedata.premium.HasValue ? (decimal?)Math.Round(financedata.premium.Value, 2) : null;
- mortgage.mortage_commission = financedata.commission.HasValue ? (decimal?)Math.Round(financedata.commission.Value, 2) : null;
- mortgage.mortage_type = financedata.subtype ?? 0;
- mortgage.mortage_datelive = Helper.GetDateString(financedata.datelive);
- mortgage.mortage_expires = Helper.GetDateString(financedata.dateexpire);
- mortgage.mortage_date = Helper.GetDateString(financedata.followup);
- mortgage.mortage_time = financedata.followup.HasValue ? financedata.followup.Value.ToString("HH:mm") : string.Empty;
- mortgage.mortage_contactid = financedata.contact ?? 0;
- mortgage.mortage_AppicationType = financedata.type ?? 0;
- mortgage.mortgage_address1 = financedata.Address1;
- mortgage.mortgage_address2 = financedata.Address2;
- mortgage.mortgage_town = financedata.Town;
- mortgage.mortgage_county = financedata.County;
- mortgage.mortgage_postcode = financedata.Postcode;
- mortgage.mortgage_Clientfee = financedata.ClientFee ?? 0;
- mortgage.mortgage_SubFinanceStatus = financedata.subFinanceStatus ?? 0;
- //from mortage table
- tblfinance_mortgage financemortage = ctx.tblfinance_mortgage.Where(x => x.financeid == FirstFinanceId).FirstOrDefault();
- if (financemortage != null)
- {
- mortgage.mortage_reason = financemortage.mortgagesubtype ?? 0;
- mortgage.mortage_financetype = financedata.status ?? 0;
- mortgage.mortage_solicitor = financemortage.solicitor;
- mortgage.mortage_deposit = financemortage.deposit.HasValue ? (decimal?)Math.Round(financemortage.deposit.Value, 2) : null;
- mortgage.mortage_income = financemortage.income.HasValue ? (decimal?)Math.Round(financemortage.income.Value, 2) : null;
- mortgage.mortage_rterm = financemortage.rterm ?? 0;
- mortgage.mortage_completed = Helper.GetDateString(financemortage.completed);
- mortgage.mortage_exchanged = financemortage.exchanged.HasValue ? Helper.GetDateString(financemortage.exchanged.Value) : string.Empty;
- mortgage.mortage_remortgagedate = financemortage.remortgagedate.HasValue ? Helper.GetDateString(financemortage.remortgagedate.Value) : string.Empty;
- //Added on 2014-11-24
- mortgage.mortgage_remortgagecontact = financemortage.remortgagecontact.HasValue ? Helper.GetDateString(financemortage.remortgagecontact.Value) : string.Empty;
- mortgage.mortage_propertyvalue = financemortage.purchase.HasValue ? (decimal?)Math.Round(financemortage.purchase.Value, 2) : null;
- mortgage.mortage_financetype = GetFinanceType(FinanceType.Mortgages);
- mortgage.mortage_rate = financemortage.Rate;
- mortgage.RateType = financemortage.RateType ?? 0;
- int index = mortagequery.IndexOf(financedata.financeid) + 1;
- mortgage.Mortage_Name = string.Format("{0}{1}", index, index == 1 ? "st Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : index == 2 ? "nd Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : index == 3 ? "rd Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : "th Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid));
- }
- else
- {
- mortgage.mortage_financetype = GetFinanceType(FinanceType.Mortgages);
- }
- formdata.Mortgage = mortgage;
- }
- List<financeID> mids = new List<financeID>();
- if (mortagequery.Count > 0)
- {
- count = 1;
- foreach (int id in mortagequery)
- {
- financeID _financeid = new financeID();
- _financeid.financeid = id;
- if (count == 1)
- {
- _financeid.name = count + "st Mortgage" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 2)
- {
- _financeid.name = count + "nd Mortgage" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 3)
- {
- _financeid.name = count + "rd Mortgage" + DisplayAddressAndLender(_financeid.financeid);
- }
- else
- {
- _financeid.name = count + "th Mortgage" + DisplayAddressAndLender(_financeid.financeid);
- }
- mids.Add(_financeid);
- addproducts.MortgageProduct = mids;
- count = count + 1;
- }
- }
- else
- {
- financeID _financeid = new financeID();
- _financeid.financeid = 0;
- _financeid.name = "1st Mortgage";
- mids.Add(_financeid);
- addproducts.MortgageProduct = mids;
- }
- #endregion
- #region Life
- //Life
- appid = 2;
- var ids = ctx.tblfinancestatus.Where(x => x.type == life_statusid && x.statusid != 35).ToList().Select(s => s.statusid);
- var lifegequery = ctx.tblfinances.Where(x => ids.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- int fid = 0;
- if (lifegequery.Count > 0)
- {
- fid = (int)lifegequery[0];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- int indexOfCurrentFForLife = lifegequery.IndexOf(financeid);
- if (indexOfCurrentFForLife > -1)
- fid = lifegequery[indexOfCurrentFForLife];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_insurance finance_insurance = ctx.tblfinance_insurance.Where(x => x.financeid == fid).FirstOrDefault();
- if (finance_insurance == null)
- {
- //insert
- tblfinance_insurance newfinance_insurance = new tblfinance_insurance();
- newfinance_insurance.financeid = fid;
- newfinance_insurance.smoker = null;
- newfinance_insurance.height = null;
- newfinance_insurance.weight = null;
- newfinance_insurance.doctor = null;
- ctx.tblfinance_insurance.Add(newfinance_insurance);
- ctx.SaveChanges();
- }
- }
- var query = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances.Where(s => ids.Contains(s.status.Value)) on c.contactid equals ft.contact
- join fi in ctx.tblfinance_insurance on ft.financeid equals fi.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == fid
- select new { ft, fi, c }).FirstOrDefault();
- if (query != null)
- {
- Life life = new Life();
- life.life_financeid = query.ft.financeid;
- life.life_status = query.ft.status ?? 0;
- life.life_provider = query.ft.provider;
- life.life_policyref = query.ft.policyreference;
- life.life_amount = query.ft.amount.HasValue ? (decimal?)Math.Round(query.ft.amount.Value, 2) : null;
- life.life_commission = query.ft.commission.HasValue ? (decimal?)Math.Round(query.ft.commission.Value, 2) : null;
- life.life_policytype = query.ft.subtype ?? 0;
- life.life_premium = query.ft.premium.HasValue ? (decimal?)Math.Round(query.ft.premium.Value, 2) : null;
- life.life_height = query.fi.height;
- life.life_weight = query.fi.weight;
- life.life_issmoker = query.fi.smoker.HasValue ? query.fi.smoker.Value : false;
- life.life_doctor = query.fi.doctor;
- life.life_medical = query.ft.details;
- life.life_datelive = Helper.GetDateString(query.ft.datelive);
- life.life_expires = Helper.GetDateString(query.ft.dateexpire);
- life.life_date = query.ft.followup.HasValue ? Helper.GetDateString(query.ft.followup) : string.Empty;
- life.life_time = query.ft.followup.HasValue ? query.ft.followup.Value.ToString("HH:mm") : string.Empty;
- life.life_financetype = GetFinanceType(FinanceType.Life);
- life.life_contactid = financedata.contact ?? 0;
- life.life_AppicationType = financedata.type ?? 0;
- int index = lifegequery.IndexOf(query.ft.financeid) + 1;
- life.life_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(life.life_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(life.life_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(life.life_financeid) : "th Policy" + DisplayAddressAndLender(life.life_financeid));
- //Added New Client Fee 27-10-2014
- life.life_Clientfee = query.ft.ClientFee ?? 0;
- //******************************
- //Added on 03-04-2015
- life.life_isPolicyForOtherApplicant = query.ft.isPolicyForOtherApplicant.HasValue ? query.ft.isPolicyForOtherApplicant.Value : false;
- formdata.Life = life;
- }
- else
- {
- Life life = new Life();
- life.life_financetype = GetFinanceType(FinanceType.Life);
- formdata.Life = life;
- }
- List<financeID> _lifes = new List<financeID>();
- if (lifegequery.Count > 0)
- {
- count = 1;
- foreach (int id in lifegequery)
- {
- financeID _financeid = new financeID();
- _financeid.financeid = id;
- if (count == 1)
- {
- _financeid.name = count + "st Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 2)
- {
- _financeid.name = count + "nd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 3)
- {
- _financeid.name = count + "rd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else
- {
- _financeid.name = count + "th Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- _lifes.Add(_financeid);
- addproducts.LifeProduct = _lifes;
- count = count + 1;
- }
- }
- else
- {
- financeID _financeid = new financeID();
- _financeid.financeid = 0;
- _financeid.name = "1st Policy";
- _lifes.Add(_financeid);
- addproducts.LifeProduct = _lifes;
- }
- #endregion
- #region Building/Content
- //Building Contents
- appid = 3;
- var idBuildings = ctx.tblfinancestatus.Where(x => x.type == buildingcontent_statusid && x.statusid != 36).ToList().Select(s => s.statusid);
- var builingquery = ctx.tblfinances.Where(x => idBuildings.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- int fidB = 0;
- if (builingquery.Count > 0)
- {
- fidB = (int)builingquery[0];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- int indexOfCurrentFForbuilding = builingquery.IndexOf(financeid);
- if (indexOfCurrentFForbuilding > -1)
- fidB = builingquery[indexOfCurrentFForbuilding];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_buildings buildingcontent = ctx.tblfinance_buildings.Where(x => x.financeid == fidB).FirstOrDefault();
- if (buildingcontent == null)
- {
- //insert
- tblfinance_buildings newfinance_building = new tblfinance_buildings();
- newfinance_building.rebuild = null;
- newfinance_building.alarm = null;
- newfinance_building.financeid = fidB;
- ctx.tblfinance_buildings.Add(newfinance_building);
- ctx.SaveChanges();
- }
- }
- var queryBuilding = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances.Where(s => idBuildings.Contains(s.status.Value)) on c.contactid equals ft.contact
- join fb in ctx.tblfinance_buildings on ft.financeid equals fb.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == fidB
- select new { ft, fb, c }).FirstOrDefault();
- if (queryBuilding != null)
- {
- BuildingContent buildingcontent = new BuildingContent();
- buildingcontent.buildingcontent_financeid = queryBuilding.ft.financeid;
- buildingcontent.buildingcontent_status = queryBuilding.ft.status ?? 0;
- buildingcontent.buildingcontent_provider = queryBuilding.ft.provider;
- buildingcontent.buildingcontent_policyref = queryBuilding.ft.policyreference;
- buildingcontent.buildingcontent_amount = queryBuilding.ft.amount.HasValue ? (decimal?)Math.Round(queryBuilding.ft.amount.Value, 2) : null;
- buildingcontent.buildingcontent_commission = queryBuilding.ft.commission.HasValue ? (decimal?)Math.Round(queryBuilding.ft.commission.Value, 2) : null;
- buildingcontent.buildingcontent_type = queryBuilding.ft.subtype ?? 0;
- buildingcontent.buildingcontent_premium = queryBuilding.ft.premium.HasValue ? (decimal?)Math.Round(queryBuilding.ft.premium.Value, 2) : null;
- buildingcontent.buildingcontent_rebuildvalue = queryBuilding.fb.rebuild.HasValue ? (decimal?)Math.Round(queryBuilding.fb.rebuild.Value, 2) : null;
- buildingcontent.buildingcontent_isalarmed = queryBuilding.fb.alarm.HasValue ? queryBuilding.fb.alarm.Value : false;
- buildingcontent.buildingcontent_addcover = queryBuilding.ft.details;
- buildingcontent.buildingcontent_datelive = Helper.GetDateString(queryBuilding.ft.datelive); ;
- buildingcontent.buildingcontent_expires = Helper.GetDateString(queryBuilding.ft.dateexpire);
- buildingcontent.buildingcontent_date = Helper.GetDateString(queryBuilding.ft.followup);
- buildingcontent.buildingcontent_time = queryBuilding.ft.followup.HasValue ? queryBuilding.ft.followup.Value.ToString("HH:mm") : string.Empty;
- buildingcontent.buildingcontent_financetype = GetFinanceType(FinanceType.BuildingsOrContents);
- buildingcontent.buildingContent_contactid = financedata.contact ?? 0;
- buildingcontent.buildingContent_AppicationType = financedata.type ?? 0;
- int index = builingquery.IndexOf(queryBuilding.ft.financeid) + 1;
- buildingcontent.buildingcontent_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid) : "th Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid));
- //Added New Client Fee 27-10-2014
- buildingcontent.building_Clientfee = queryBuilding.ft.ClientFee ?? 0;
- //******************************
- buildingcontent.buildingcontent_isPolicyForOtherApplicant = queryBuilding.ft.isPolicyForOtherApplicant.HasValue ? queryBuilding.ft.isPolicyForOtherApplicant.Value : false;
- formdata.BuildingContent = buildingcontent;
- }
- else
- {
- BuildingContent buildingcontent = new BuildingContent();
- buildingcontent.buildingcontent_financetype = GetFinanceType(FinanceType.BuildingsOrContents);
- formdata.BuildingContent = buildingcontent;
- }
- List<financeID> _buildings = new List<financeID>();
- if (builingquery.Count > 0)
- {
- count = 1;
- foreach (int id in builingquery)
- {
- financeID _financeid = new financeID();
- _financeid.financeid = id;
- if (count == 1)
- {
- _financeid.name = count + "st Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 2)
- {
- _financeid.name = count + "nd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 3)
- {
- _financeid.name = count + "rd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else
- {
- _financeid.name = count + "th Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- _buildings.Add(_financeid);
- addproducts.BuildingContentProduct = _buildings;
- count = count + 1;
- }
- }
- else
- {
- financeID _financeid = new financeID();
- _financeid.financeid = 0;
- _financeid.name = "1st Policy";
- _buildings.Add(_financeid);
- addproducts.BuildingContentProduct = _buildings;
- }
- #endregion
- #region Pension
- //Pension
- appid = 4;
- var idPensions = ctx.tblfinancestatus.Where(x => x.type == pension_statusid && x.statusid != 37).ToList().Select(s => s.statusid);
- var pensiongquery = ctx.tblfinances.Where(x => idPensions.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- int fidP = 0;
- if (pensiongquery.Count > 0)
- {
- fidP = (int)pensiongquery[0];
- int indexOfCurrentFForPension = pensiongquery.IndexOf(financeid);
- if (indexOfCurrentFForPension > -1)
- fidP = pensiongquery[indexOfCurrentFForPension];
- tblfinance_pension buildingcontent = ctx.tblfinance_pension.Where(x => x.financeid == fidP).FirstOrDefault();
- if (buildingcontent == null)
- {
- //insert
- tblfinance_pension newfinance_pension = new tblfinance_pension();
- newfinance_pension.incomereq = null;
- newfinance_pension.financeid = fidP;
- ctx.tblfinance_pension.Add(newfinance_pension);
- ctx.SaveChanges();
- }
- }
- var queryPension = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances.Where(s => idPensions.Contains(s.status.Value)) on c.contactid equals ft.contact
- join fp in ctx.tblfinance_pension on ft.financeid equals fp.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == fidP
- select new { ft, fp, c }).FirstOrDefault();
- if (queryPension != null)
- {
- Pensions pension = new Pensions();
- pension.pension_financeid = queryPension.ft.financeid;
- pension.pension_amount = queryPension.ft.amount.HasValue ? (decimal?)Math.Round(queryPension.ft.amount.Value, 2) : null;
- pension.pension_commission = queryPension.ft.commission.HasValue ? (decimal?)Math.Round(queryPension.ft.commission.Value, 2) : null;
- pension.pension_contributors = queryPension.ft.premium.HasValue ? (decimal?)Math.Round(queryPension.ft.premium.Value, 2) : null;
- pension.pension_datelive = Helper.GetDateString(queryPension.ft.datelive);
- pension.pension_expires = Helper.GetDateString(queryPension.ft.dateexpire);
- pension.pension_fundvalue = queryPension.ft.fundvalue.HasValue ? (decimal?)Math.Round(queryPension.ft.fundvalue.Value, 2) : null;
- pension.pension_incomereq = queryPension.fp.incomereq.HasValue ? (decimal?)Math.Round(queryPension.fp.incomereq.Value, 2) : null;
- pension.pension_policyref = queryPension.ft.policyreference;
- pension.pension_provider = queryPension.ft.provider;
- pension.pension_riskprofile = queryPension.ft.subtype ?? 0;
- pension.pension_status = queryPension.ft.status ?? 0;
- pension.pension_date = Helper.GetDateString(queryPension.ft.followup);
- pension.pension_time = queryPension.ft.followup.HasValue ? queryPension.ft.followup.Value.ToString("HH:mm") : string.Empty;
- pension.pension_financetype = GetFinanceType(FinanceType.Pensions);
- pension.pension_contactid = financedata.contact ?? 0;
- pension.pension_AppicationType = financedata.type ?? 0;
- int index = pensiongquery.IndexOf(queryPension.ft.financeid) + 1;
- pension.pension_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(pension.pension_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(pension.pension_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(pension.pension_financeid) : "th Policy" + DisplayAddressAndLender(pension.pension_financeid));
- //Added New Client Fee 27-10-2014
- pension.pension_Clientfee = queryPension.ft.ClientFee ?? 0;
- //******************************
- pension.pension_isPolicyForOtherApplicant = queryPension.ft.isPolicyForOtherApplicant.HasValue ? queryPension.ft.isPolicyForOtherApplicant.Value : false;
- formdata.Pension = pension;
- }
- else
- {
- Pensions pension = new Pensions();
- pension.pension_financetype = GetFinanceType(FinanceType.Pensions);
- formdata.Pension = pension;
- }
- List<financeID> _pensions = new List<financeID>();
- if (pensiongquery.Count > 0)
- {
- count = 1;
- foreach (int id in pensiongquery)
- {
- financeID _financeid = new financeID();
- _financeid.financeid = id;
- if (count == 1)
- {
- _financeid.name = count + "st Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 2)
- {
- _financeid.name = count + "nd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 3)
- {
- _financeid.name = count + "rd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else
- {
- _financeid.name = count + "th Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- _pensions.Add(_financeid);
- addproducts.PensionProduct = _pensions;
- count = count + 1;
- }
- }
- else
- {
- financeID _financeid = new financeID();
- _financeid.financeid = 0;
- _financeid.name = "1st Policy";
- _pensions.Add(_financeid);
- addproducts.PensionProduct = _pensions;
- }
- #endregion
- #region Investment
- //Investment
- appid = 5;
- var idInvestments = ctx.tblfinancestatus.Where(x => x.type == investment_statusid && x.statusid != 38).ToList().Select(s => s.statusid);
- var investmentquery = ctx.tblfinances.Where(x => idInvestments.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- int fidI = 0;
- if (investmentquery.Count > 0)
- {
- fidI = (int)investmentquery[0];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- int indexOfCurrentFForInvestment = investmentquery.IndexOf(financeid);
- if (indexOfCurrentFForInvestment > -1)
- fidI = investmentquery[indexOfCurrentFForInvestment];
- //Start:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_investments pinvets = ctx.tblfinance_investments.Where(x => x.financeid == fidI).FirstOrDefault();
- if (pinvets == null)
- {
- //insert
- tblfinance_investments newfinanceinvestment = new tblfinance_investments();
- newfinanceinvestment.financeid = fidI;
- ctx.tblfinance_investments.Add(newfinanceinvestment);
- ctx.SaveChanges();
- }
- }
- var queryInvestment = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances.Where(s => idInvestments.Contains(s.status.Value)) on c.contactid equals ft.contact
- join finv in ctx.tblfinance_investments on ft.financeid equals finv.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == fidI
- select new { ft, finv, c }).FirstOrDefault();
- if (queryInvestment != null)
- {
- Investment investment = new Investment();
- investment.investment_financeid = queryInvestment.ft.financeid;
- investment.investment_amount = queryInvestment.ft.amount.HasValue ? (decimal?)Math.Round(queryInvestment.ft.amount.Value, 2) : null;
- investment.investment_commission = queryInvestment.ft.commission.HasValue ? (decimal?)Math.Round(queryInvestment.ft.commission.Value, 2) : null;
- investment.investment_contributors = queryInvestment.ft.premium.HasValue ? (decimal?)Math.Round(queryInvestment.ft.premium.Value, 2) : null;
- investment.investment_date = queryInvestment.ft.followup.HasValue ? Helper.GetDateString(queryInvestment.ft.followup.Value) : string.Empty;
- investment.investment_datelive = queryInvestment.ft.datelive.HasValue ? Helper.GetDateString(queryInvestment.ft.datelive.Value) : string.Empty;
- investment.investment_expires = queryInvestment.ft.dateexpire.HasValue ? Helper.GetDateString(queryInvestment.ft.dateexpire.Value) : string.Empty;
- investment.investment_financetype = GetFinanceType(FinanceType.Investments);
- investment.investment_fundvalue = queryInvestment.ft.fundvalue.HasValue ? (decimal?)Math.Round(queryInvestment.ft.fundvalue.Value, 2) : null;
- investment.investment_policyref = queryInvestment.ft.policyreference != null ? queryInvestment.ft.policyreference : string.Empty;
- investment.investment_provider = queryInvestment.ft.provider != null ? queryInvestment.ft.provider : string.Empty; ;
- investment.investment_riskprofiles = queryInvestment.ft.subtype ?? 0;
- investment.investment_status = queryInvestment.ft.status ?? 0;
- investment.investment_contactid = financedata.contact ?? 0;
- investment.investment_AppicationType = financedata.type ?? 0;
- investment.investment_time = queryInvestment.ft.followup.HasValue ? queryInvestment.ft.followup.Value.ToString("HH:mm") : string.Empty;
- int index = investmentquery.IndexOf(queryInvestment.ft.financeid) + 1;
- investment.Investment_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(investment.investment_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(investment.investment_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(investment.investment_financeid) : "th Policy" + DisplayAddressAndLender(investment.investment_financeid));
- //Added New Client Fee 27-10-2014
- investment.investment_Clientfee = queryInvestment.ft.ClientFee ?? 0;
- //******************************
- investment.investment_isPolicyForOtherApplicant = queryInvestment.ft.isPolicyForOtherApplicant.HasValue ? queryInvestment.ft.isPolicyForOtherApplicant.Value : false;
- formdata.Investment = investment;
- }
- else
- {
- Investment investment = new Investment();
- investment.investment_financetype = GetFinanceType(FinanceType.Investments);
- formdata.Investment = investment;
- }
- List<financeID> _investments = new List<financeID>();
- if (investmentquery.Count > 0)
- {
- count = 1;
- foreach (int id in investmentquery)
- {
- financeID _financeid = new financeID();
- _financeid.financeid = id;
- if (count == 1)
- {
- _financeid.name = count + "st Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 2)
- {
- _financeid.name = count + "nd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else if (count == 3)
- {
- _financeid.name = count + "rd Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- else
- {
- _financeid.name = count + "th Policy" + DisplayAddressAndLender(_financeid.financeid);
- }
- _investments.Add(_financeid);
- addproducts.InvestmentProduct = _investments;
- count = count + 1;
- }
- }
- else
- {
- financeID _financeid = new financeID();
- _financeid.financeid = 0;
- _financeid.name = "1st Policy";
- _investments.Add(_financeid);
- addproducts.InvestmentProduct = _investments;
- }
- #endregion
- #region Address
- //Address
- int addressid = ctx.tblcontacts.Where(x => x.contactid == contactid).Select(x => x.address.Value).FirstOrDefault();
- var address = ctx.tbladdresses.Where(x => x.addressid == addressid).FirstOrDefault();
- if (address != null)
- {
- Address addr = new Address();
- addr.address_line1 = address.address1;
- addr.address_line2 = address.address2;
- addr.address_city = address.town;
- addr.address_postcode = address.postcode;
- if (contact != null)
- {
- addr.ninnumber = contact.ninumber;
- addr.dob = contact.dob.HasValue ? Helper.GetDateString(contact.dob.Value) : string.Empty;
- addr.jobtitle = contact.jobtitle;
- addr.employer = contact.employer;
- addr.accountant = contact.accountdetails;
- addr.weddinganniversary = contact.married.HasValue ? Helper.GetDateString(contact.married.Value) : string.Empty;
- addr.dependents = contact.dependants;
- }
- formdata.Address = addr;
- }
- #endregion
- #region notes
- #endregion
- formdata.addproducts = addproducts;
- return formdata;
- }
- #region [Get branch and negotiator names by Id]
- /// <summary>
- /// Get negotiator name by id
- /// </summary>
- /// <param name="negotiatorId"></param>
- /// <returns></returns>
- public string GetNegotiatorNameById(int? negotiatorId)
- {
- var negotiatorName = string.Empty;
- try
- {
- negotiatorName = ctx.tblNegotiators.Where(negt => negt.Id == negotiatorId).Select(negt => negt.Negotiator).FirstOrDefault();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "GetNegotiatorNameByIds", "Q_Application", ex.Message);
- }
- return negotiatorName;
- }
- /// <summary>
- /// Get branch name by id
- /// </summary>
- /// <param name="branchId"></param>
- /// <returns></returns>
- public string GetBranchNameById(int? branchId)
- {
- var branchName = string.Empty;
- try
- {
- branchName = ctx.tblBranches.Where(brn => brn.Id == branchId).Select(brn => brn.Branch).FirstOrDefault();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "GetBranchNameById", "Q_Application", ex.Message);
- }
- return branchName;
- }
- #endregion [Get branch and negotiator names by Id]
- /// <summary>
- /// Get user name
- /// </summary>
- /// <param name="userId"></param>
- /// <param name="contactId"></param>
- /// <returns></returns>
- public string GetUserName(int userId, int contactId)
- {
- string _uName = "";
- try
- {
- if (userId > 0)
- _uName = ctx.tblusers.Where(c => c.userid == userId).FirstOrDefault().brokername;
- else
- _uName = (from c in ctx.tblcontacts
- join u in ctx.tblusers on c.broker ?? 0 equals u.userid
- where c.contactid == contactId
- select new { u }).FirstOrDefault().u.brokername;
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetUserName", ex.Message, ex.Source, ex.StackTrace, ex.HelpLink);
- }
- return _uName;
- }
- /// <summary>
- /// Get finance status details
- /// </summary>
- /// <param name="applicationid"></param>
- /// <returns></returns>
- public List<tblfinancestatu> GetFinancestatus(int applicationid)
- {
- return ctx.tblfinancestatus.Where(x => x.type == applicationid).ToList();
- }
- /// <summary>
- /// Get finance sub status details
- /// </summary>
- /// <param name="applicationid"></param>
- /// <returns></returns>
- public List<tblfinancesubstatus> GetFinanceSubstatus(int applicationid)
- {
- return ctx.tblfinancesubstatus.ToList();
- }
- /// <summary>
- /// Get all finance status details
- /// </summary>
- /// <returns></returns>
- public List<tblfinancestatu> GetAllFinancestatus()
- {
- return ctx.tblfinancestatus.ToList();
- }
- /// <summary>
- /// Get finance type details
- /// </summary>
- /// <param name="financetype"></param>
- /// <returns></returns>
- public int GetFinanceType(string financetype)
- {
- return ctx.tblfinancetypes.Where(x => x.type.ToLower() == financetype.ToLower()).Select(x => x.financetypeid).FirstOrDefault();
- }
- /// <summary>
- /// Get other applicant details
- /// </summary>
- /// <param name="ContactId"></param>
- /// <returns></returns>
- public OtherApplicant GetOtherApplicant(int ContactId)
- {
- var oData = new OtherApplicant();
- try
- {
- var d = ctx.tblOtherApplicants.Where(x => x.MainContactId == ContactId & x.IsActive == true).FirstOrDefault();
- if (d != null)
- {
- oData.AddDate = d.AddDate;
- oData.Email = d.Email;
- oData.EntryBy = d.EntryBy;
- oData.FirstName = d.FirstName;
- oData.IsActive = d.IsActive;
- oData.IsDelete = d.IsDelete;
- oData.MainContactId = d.MainContactId;
- oData.MobileNumber = d.MobileNumber;
- oData.OtherApplicantId = d.OtherApplicantId;
- oData.SurName = d.SurName;
- oData.UpdateBy = d.UpdateBy;
- oData.UpdateDate = d.UpdateDate;
- oData.address_line1 = d.address1;
- oData.address_line2 = d.address2;
- oData.address_city = d.town;
- oData.address_postcode = d.postcode;
- oData.dependents = d.dependants;
- oData.employer = d.employer;
- oData.jobtitle = d.jobtitle;
- oData.ninnumber = d.ninumber;
- oData.weddinganniversary = d.married.HasValue ? Helper.GetDateString(d.married.Value) : string.Empty;
- oData.dob = d.dob.HasValue ? Helper.GetDateString(d.dob.Value) : string.Empty;
- oData.accountant = d.accountdetails;
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetOtherApplicant", ex.Message);
- }
- return oData ?? new OtherApplicant();
- }
- /// <summary>
- /// Get address details
- /// </summary>
- /// <param name="contactid"></param>
- /// <returns></returns>
- public Address GetAddress(int contactid)
- {
- //Address
- var address = ctx.tbladdresses.Where(x => x.addressid == contactid).FirstOrDefault();
- Address addr = new Address();
- address = null;
- if (address != null)
- {
- addr.address_line1 = address.address1;
- addr.address_line2 = address.address2;
- addr.address_city = address.town;
- addr.address_postcode = address.postcode;
- }
- return addr;
- }
- /// <summary>
- /// Get notes details
- /// </summary>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public List<Notes> GetNotes(int contactid, int financeid)
- {
- List<Notes> _NoteList = new List<Notes>();
- //Added on 2015-03-17
- if (financeid > 0)
- {
- contactid = Convert.ToInt32(ctx.tblfinances.Where(res => res.financeid == financeid).Select(res => res.contact).FirstOrDefault());
- }
- if (financeid != 0)
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@ContactId", contactid);
- Param[1] = new SqlParameter("@FinanceId", financeid);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetNotes", Param);
- _NoteList = (from DataRow row in dt.Rows
- select new Notes
- {
- contact = Convert.ToInt32(((row["contact"] == DBNull.Value || row["contact"] == null) ? "0" : row["contact"]).ToString()),
- created = (row["created"] == DBNull.Value || row["created"] == null) ? string.Empty : Convert.ToDateTime(row["created"]).ToString("dd/MM/yyyy HH:mm"),
- noteid = Convert.ToInt32(((row["noteid"] == DBNull.Value || row["noteid"] == null) ? "0" : row["noteid"]).ToString()),
- userid = Convert.ToInt32(((row["userid"] == DBNull.Value || row["userid"] == null) ? "0" : row["userid"]).ToString()),
- notes = ((row["notes"] == DBNull.Value || row["notes"] == null) ? " " : row["notes"]).ToString(),
- UserName = ((row["UserName"] == DBNull.Value || row["UserName"] == null) ? " " : row["UserName"]).ToString()
- }).ToList();
- }
- else
- {
- _NoteList = new List<Notes>();
- }
- return _NoteList;
- }
- #endregion [Get application form details 2015-03-31]
- #region [Get various product details 2015-03-31]
- /// <summary>
- /// Get mortgage product details
- /// </summary>
- /// <param name="appid"></param>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public Mortgage GetMortgage(int appid, int contactid, int financeid)
- {
- int mortage_statusid = GetFinanceType(FinanceType.Mortgages);
- var mortageids = ctx.tblfinancestatus.Where(x => x.type == mortage_statusid && x.statusid != 34).ToList().Select(s => s.statusid);
- //Added on 2015-03-17
- if (financeid > 0)
- {
- contactid = Convert.ToInt32(ctx.tblfinances.Where(res => res.financeid == financeid).Select(res => res.contact).FirstOrDefault());
- }
- var mortagequery = ctx.tblfinances.Where(x => mortageids.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- Mortgage mortgage = new Mortgage();
- int indexOfCurrentF = mortagequery.IndexOf(financeid);
- if (indexOfCurrentF > -1)
- financeid = mortagequery[indexOfCurrentF];
- else
- {
- if (mortagequery.Count() > 0)
- if (financeid > 0)
- financeid = (int)mortagequery[0];
- }
- //End:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance financedata = ctx.tblfinances.Where(x => x.financeid == financeid).FirstOrDefault();
- if (financedata != null)
- {
- mortgage.mortage_financeid = financedata.financeid;
- mortgage.mortage_mortgagesubtype = financedata.status ?? 0;
- mortgage.mortage_mortageaccountno = financedata.policyreference;
- mortgage.mortage_lender = financedata.provider;
- mortgage.mortage_amount = financedata.amount.HasValue ? (decimal?)Math.Round(financedata.amount.Value, 2) : null;
- mortgage.mortage_premium = financedata.premium.HasValue ? (decimal?)Math.Round(financedata.premium.Value, 2) : null;
- mortgage.mortage_commission = financedata.commission.HasValue ? (decimal?)Math.Round(financedata.commission.Value, 2) : null;
- mortgage.mortage_type = financedata.subtype ?? 0;
- mortgage.mortage_datelive = Helper.GetDateString(financedata.datelive);
- mortgage.mortage_expires = Helper.GetDateString(financedata.dateexpire);
- mortgage.mortage_date = Helper.GetDateString(financedata.followup);
- mortgage.mortage_time = financedata.followup.HasValue ? financedata.followup.Value.ToString("HH:mm") : string.Empty;
- mortgage.mortage_contactid = contactid;
- mortgage.mortage_AppicationType = appid;
- mortgage.mortgage_address1 = financedata.Address1;
- mortgage.mortgage_address2 = financedata.Address2;
- mortgage.mortgage_town = financedata.Town;
- mortgage.mortgage_county = financedata.County;
- mortgage.mortgage_postcode = financedata.Postcode;
- //Added Client Fee 27-10-2014
- mortgage.mortgage_Clientfee = financedata.ClientFee;
- mortgage.mortgage_SubFinanceStatus = financedata.subFinanceStatus ?? 0;
- //********************************
- //from mortage table
- tblfinance_mortgage financemortage = ctx.tblfinance_mortgage.Where(x => x.financeid == financeid).FirstOrDefault();
- if (financemortage != null)
- {
- mortgage.mortage_reason = financemortage.mortgagesubtype ?? 0;
- mortgage.mortage_financetype = financedata.status ?? 0;
- mortgage.mortage_solicitor = financemortage.solicitor;
- mortgage.mortage_deposit = financemortage.deposit.HasValue ? (decimal?)Math.Round(financemortage.deposit.Value, 2) : null;
- mortgage.mortage_income = financemortage.income.HasValue ? (decimal?)Math.Round(financemortage.income.Value, 2) : null;
- mortgage.mortage_rterm = financemortage.rterm ?? 0;
- mortgage.mortage_completiondate = Helper.GetDateString(financemortage.completed);
- mortgage.mortage_exchangedate = financemortage.exchanged.HasValue ? Helper.GetDateString(financemortage.exchanged.Value) : string.Empty;
- mortgage.mortage_remortagedate = financemortage.remortgagedate.HasValue ? Helper.GetDateString(financemortage.remortgagedate.Value) : string.Empty;
- //Added on 2014-11-24
- mortgage.mortgage_remortgagecontact = financemortage.remortgagecontact.HasValue ? Helper.GetDateString(financemortage.remortgagecontact.Value) : string.Empty;
- mortgage.mortage_propertyvalue = financemortage.purchase.HasValue ? (decimal?)Math.Round(financemortage.purchase.Value, 2) : null;
- mortgage.mortage_financetype = GetFinanceType(FinanceType.Mortgages);
- int index = mortagequery.IndexOf(financedata.financeid) + 1;
- mortgage.Mortage_Name = string.Format("{0}{1}", index, index == 1 ? "st Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : index == 2 ? "nd Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : index == 3 ? "rd Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : "th Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid));
- //Added new remortgage contact 24-11-2014
- mortgage.mortgage_remortgagecontact = financemortage.remortgagecontact.HasValue ? Helper.GetDateString(financemortage.remortgagecontact.Value) : string.Empty;
- mortgage.mortage_rate = financemortage.Rate;
- mortgage.RateType = financemortage.RateType ?? 0;
- }
- else
- {
- mortgage.mortage_financetype = GetFinanceType(FinanceType.Mortgages);
- int index = mortagequery.IndexOf(financedata.financeid) + 1;
- mortgage.Mortage_Name = string.Format("{0}{1}", index, index == 1 ? "st Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : index == 2 ? "nd Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : index == 3 ? "rd Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid) : "th Mortgage" + DisplayAddressAndLender(mortgage.mortage_financeid));
- }
- }
- return mortgage;
- }
- /// <summary>
- /// Get life product details
- /// </summary>
- /// <param name="appid"></param>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public Life GetLife(int appid, int contactid, int financeid)
- {
- int life_statusid = GetFinanceType(FinanceType.Life);
- var ids = ctx.tblfinancestatus.Where(x => x.type == life_statusid && x.statusid != 35).ToList().Select(s => s.statusid);
- //Added on 2015-03-17
- if (financeid > 0)
- {
- contactid = Convert.ToInt32(ctx.tblfinances.Where(res => res.financeid == financeid).Select(res => res.contact).FirstOrDefault());
- }
- var lifegequery = ctx.tblfinances.Where(x => ids.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- if (lifegequery.Count > 0)
- {
- int fid = (int)lifegequery[0];
- //Start:- Updated On 3-4-2014 regarding tab and product selection
- int indexOfCurrentF = lifegequery.IndexOf(financeid);
- if (indexOfCurrentF > -1)
- {
- financeid = lifegequery[indexOfCurrentF];
- fid = lifegequery[indexOfCurrentF];
- }
- else
- {
- if (financeid > 0)
- financeid = fid;
- }
- //End:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_insurance finance_insurance = ctx.tblfinance_insurance.Where(x => x.financeid == fid).FirstOrDefault();
- if (finance_insurance == null)
- {
- //insert
- tblfinance_insurance newfinance_insurance = new tblfinance_insurance();
- newfinance_insurance.financeid = fid;
- newfinance_insurance.smoker = null;
- newfinance_insurance.height = null;
- newfinance_insurance.weight = null;
- newfinance_insurance.doctor = null;
- ctx.tblfinance_insurance.Add(newfinance_insurance);
- ctx.SaveChanges();
- }
- }
- var query = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances.Where(s => ids.Contains(s.status.Value)) on c.contactid equals ft.contact
- join fi in ctx.tblfinance_insurance on ft.financeid equals fi.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == financeid
- select new { ft, fi, c }).FirstOrDefault();
- Life life = new Life();
- if (query != null)
- {
- life.life_financeid = query.ft.financeid;
- life.life_status = query.ft.status ?? 0;
- life.life_provider = query.ft.provider;
- life.life_policyref = query.ft.policyreference;
- life.life_amount = query.ft.amount.HasValue ? (decimal?)Math.Round(query.ft.amount.Value, 2) : null;
- life.life_commission = query.ft.commission.HasValue ? (decimal?)Math.Round(query.ft.commission.Value, 2) : null;
- life.life_policytype = query.ft.subtype ?? 0;
- life.life_premium = query.ft.premium.HasValue ? (decimal?)Math.Round(query.ft.premium.Value, 2) : null;
- life.life_height = query.fi.height;
- life.life_weight = query.fi.weight;
- life.life_issmoker = query.fi.smoker.HasValue ? query.fi.smoker.Value : false;
- life.life_doctor = query.fi.doctor;
- life.life_medical = query.ft.details;
- life.life_datelive = Helper.GetDateString(query.ft.datelive);
- life.life_expires = Helper.GetDateString(query.ft.dateexpire);
- life.life_date = query.ft.followup.HasValue ? Helper.GetDateString(query.ft.followup) : string.Empty;
- life.life_time = query.ft.followup.HasValue ? query.ft.followup.Value.ToString("HH:mm") : string.Empty;
- life.life_financetype = GetFinanceType(FinanceType.Life);
- int index = lifegequery.IndexOf(query.ft.financeid) + 1;
- life.life_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(life.life_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(life.life_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(life.life_financeid) : "th Policy" + DisplayAddressAndLender(life.life_financeid));
- life.life_contactid = contactid;
- life.life_AppicationType = appid;
- //Added Client Fee 27-10-2014
- life.life_Clientfee = query.ft.ClientFee;
- //********************************
- //Added on 03-04-2015
- life.life_isPolicyForOtherApplicant = query.ft.isPolicyForOtherApplicant.HasValue ? query.ft.isPolicyForOtherApplicant.Value : false;
- }
- else
- {
- life.life_financetype = GetFinanceType(FinanceType.Life);
- }
- return life;
- }
- /// <summary>
- /// Get building / content product details
- /// </summary>
- /// <param name="appid"></param>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public BuildingContent GetBuildingContent(int appid, int contactid, int financeid)
- {
- int buildingcontent_statusid = GetFinanceType(FinanceType.BuildingsOrContents);
- //Building Contents
- var idBuildings = ctx.tblfinancestatus.Where(x => x.type == buildingcontent_statusid && x.statusid != 36).ToList().Select(s => s.statusid);
- //Added on 2015-03-17
- if (financeid > 0)
- {
- contactid = Convert.ToInt32(ctx.tblfinances.Where(res => res.financeid == financeid).Select(res => res.contact).FirstOrDefault());
- }
- var builingquery = ctx.tblfinances.Where(x => idBuildings.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- if (builingquery.Count > 0)
- {
- int fid = (int)builingquery[0];
- //Start:- Updated On 3-4-2014 regarding tab and product selection
- int indexOfCurrentF = builingquery.IndexOf(financeid);
- if (indexOfCurrentF > -1)
- {
- financeid = builingquery[indexOfCurrentF];
- fid = builingquery[indexOfCurrentF];
- }
- else
- {
- if (financeid > 0)
- financeid = fid;
- }
- //End:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_buildings buildings = ctx.tblfinance_buildings.Where(x => x.financeid == fid).FirstOrDefault();
- if (buildings == null)
- {
- //insert
- tblfinance_buildings newfinance_building = new tblfinance_buildings();
- newfinance_building.rebuild = null;
- newfinance_building.alarm = null;
- newfinance_building.financeid = fid;
- ctx.tblfinance_buildings.Add(newfinance_building);
- ctx.SaveChanges();
- }
- }
- var queryBuilding = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join fb in ctx.tblfinance_buildings on ft.financeid equals fb.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == financeid
- select new { ft, fb, c }).FirstOrDefault();
- BuildingContent buildingcontent = new BuildingContent();
- if (queryBuilding != null)
- {
- buildingcontent.buildingcontent_financeid = queryBuilding.ft.financeid;
- buildingcontent.buildingcontent_status = queryBuilding.ft.status ?? 0;
- buildingcontent.buildingcontent_provider = queryBuilding.ft.provider;
- buildingcontent.buildingcontent_policyref = queryBuilding.ft.policyreference;
- buildingcontent.buildingcontent_amount = queryBuilding.ft.amount.HasValue ? (decimal?)Math.Round(queryBuilding.ft.amount.Value, 2) : null;
- buildingcontent.buildingcontent_commission = queryBuilding.ft.commission.HasValue ? (decimal?)Math.Round(queryBuilding.ft.commission.Value, 2) : null;
- buildingcontent.buildingcontent_type = queryBuilding.ft.subtype ?? 0;
- buildingcontent.buildingcontent_premium = queryBuilding.ft.premium.HasValue ? (decimal?)Math.Round(queryBuilding.ft.premium.Value, 2) : null;
- buildingcontent.buildingcontent_rebuildvalue = queryBuilding.fb.rebuild.HasValue ? (decimal?)Math.Round(queryBuilding.fb.rebuild.Value, 2) : null;
- buildingcontent.buildingcontent_isalarmed = queryBuilding.fb.alarm.HasValue ? queryBuilding.fb.alarm.Value : false;
- buildingcontent.buildingcontent_addcover = queryBuilding.ft.details;
- buildingcontent.buildingcontent_datelive = Helper.GetDateString(queryBuilding.ft.datelive); ;
- buildingcontent.buildingcontent_expires = Helper.GetDateString(queryBuilding.ft.dateexpire);
- buildingcontent.buildingcontent_date = Helper.GetDateString(queryBuilding.ft.followup);
- buildingcontent.buildingcontent_time = queryBuilding.ft.followup.HasValue ? queryBuilding.ft.followup.Value.ToString("HH:mm") : string.Empty;
- buildingcontent.buildingcontent_financetype = GetFinanceType(FinanceType.BuildingsOrContents);
- buildingcontent.buildingContent_contactid = contactid;
- buildingcontent.buildingContent_AppicationType = appid;
- // Update on 23-6-2014 due to performance issue as the GetNOte method get called Explicitly
- int index = builingquery.IndexOf(queryBuilding.ft.financeid) + 1;
- buildingcontent.buildingcontent_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid) : "th Policy" + DisplayAddressAndLender(buildingcontent.buildingcontent_financeid));
- //Added Client Fee 27-10-2014
- buildingcontent.building_Clientfee = queryBuilding.ft.ClientFee;
- //********************************
- buildingcontent.buildingcontent_isPolicyForOtherApplicant = queryBuilding.ft.isPolicyForOtherApplicant.HasValue ? queryBuilding.ft.isPolicyForOtherApplicant.Value : false;
- }
- else
- {
- buildingcontent.buildingcontent_financetype = GetFinanceType(FinanceType.BuildingsOrContents);
- }
- return buildingcontent;
- }
- /// <summary>
- /// Get pension product details
- /// </summary>
- /// <param name="appid"></param>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public Pensions GetPension(int appid, int contactid, int financeid)
- {
- Pensions pension = new Pensions();
- int pension_statusid = GetFinanceType(FinanceType.Pensions);
- var idPensions = ctx.tblfinancestatus.Where(x => x.type == pension_statusid && x.statusid != 37).ToList().Select(s => s.statusid);
- //Added on 2015-03-17
- if (financeid > 0)
- {
- contactid = Convert.ToInt32(ctx.tblfinances.Where(res => res.financeid == financeid).Select(res => res.contact).FirstOrDefault());
- }
- var pensiongquery = ctx.tblfinances.Where(x => idPensions.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- if (pensiongquery.Count > 0)
- {
- int fid = (int)pensiongquery[0];
- //Start:- Updated On 3-4-2014 regarding tab and product selection
- int indexOfCurrentF = pensiongquery.IndexOf(financeid);
- if (indexOfCurrentF > -1)
- {
- financeid = pensiongquery[indexOfCurrentF];
- fid = pensiongquery[indexOfCurrentF];
- }
- else
- {
- if (financeid > 0)
- financeid = fid;
- }
- //End:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_pension _obj = ctx.tblfinance_pension.Where(x => x.financeid == fid).FirstOrDefault();
- if (_obj == null)
- {
- //insert
- tblfinance_pension newfinance_pension = new tblfinance_pension();
- newfinance_pension.incomereq = null;
- newfinance_pension.financeid = fid;
- ctx.tblfinance_pension.Add(newfinance_pension);
- ctx.SaveChanges();
- }
- }
- var queryPension = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join fp in ctx.tblfinance_pension on ft.financeid equals fp.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == financeid
- select new { ft, fp, c }).FirstOrDefault();
- if (queryPension != null)
- {
- pension.pension_financeid = queryPension.ft.financeid;
- pension.pension_amount = queryPension.ft.amount.HasValue ? (decimal?)Math.Round(queryPension.ft.amount.Value, 2) : null;
- pension.pension_commission = queryPension.ft.commission.HasValue ? (decimal?)Math.Round(queryPension.ft.commission.Value, 2) : null;
- pension.pension_contributors = queryPension.ft.premium.HasValue ? (decimal?)Math.Round(queryPension.ft.premium.Value, 2) : null;
- pension.pension_datelive = Helper.GetDateString(queryPension.ft.datelive);
- pension.pension_expires = Helper.GetDateString(queryPension.ft.dateexpire);
- pension.pension_fundvalue = queryPension.ft.fundvalue.HasValue ? (decimal?)Math.Round(queryPension.ft.fundvalue.Value, 2) : null;
- pension.pension_incomereq = queryPension.fp.incomereq.HasValue ? (decimal?)Math.Round(queryPension.fp.incomereq.Value, 2) : null;
- pension.pension_policyref = queryPension.ft.policyreference;
- pension.pension_provider = queryPension.ft.provider;
- pension.pension_riskprofile = queryPension.ft.subtype ?? 0;
- pension.pension_status = queryPension.ft.status ?? 0;
- pension.pension_date = Helper.GetDateString(queryPension.ft.followup);
- pension.pension_time = queryPension.ft.followup.HasValue ? queryPension.ft.followup.Value.ToString("HH:mm") : string.Empty;
- pension.pension_financetype = GetFinanceType(FinanceType.Pensions);
- // Update on 23-6-2014 due to performance issue as the GetNOte method get called Explicitly
- pension.pension_contactid = contactid;
- pension.pension_AppicationType = appid;
- int index = pensiongquery.IndexOf(queryPension.ft.financeid) + 1;
- pension.pension_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(pension.pension_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(pension.pension_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(pension.pension_financeid) : "th Policy" + DisplayAddressAndLender(pension.pension_financeid));
- //Added Client Fee 27-10-2014
- pension.pension_Clientfee = queryPension.ft.ClientFee;
- //********************************
- pension.pension_isPolicyForOtherApplicant = queryPension.ft.isPolicyForOtherApplicant.HasValue ? queryPension.ft.isPolicyForOtherApplicant.Value : false;
- }
- else
- {
- pension.pension_financetype = GetFinanceType(FinanceType.Pensions);
- }
- return pension;
- }
- /// <summary>
- /// Get investment product details
- /// </summary>
- /// <param name="appid"></param>
- /// <param name="contactid"></param>
- /// <param name="financeid"></param>
- /// <returns></returns>
- public Investment GetInvestment(int appid, int contactid, int financeid)
- {
- int investment_statusid = GetFinanceType(FinanceType.Investments);
- var idInvestments = ctx.tblfinancestatus.Where(x => x.type == investment_statusid && x.statusid != 38).ToList().Select(s => s.statusid);
- //Added on 2015-03-17
- if (financeid > 0)
- {
- contactid = Convert.ToInt32(ctx.tblfinances.Where(res => res.financeid == financeid).Select(res => res.contact).FirstOrDefault());
- }
- var investmentquery = ctx.tblfinances.Where(x => idInvestments.Contains(x.status.Value) && x.contact == contactid && x.type == appid).OrderBy(c => c.financeid).Select(x => x.financeid).ToList();
- if (investmentquery.Count > 0)
- {
- int fid = (int)investmentquery[0];
- //Start:- Updated On 3-4-2014 regarding tab and product selection
- int indexOfCurrentF = investmentquery.IndexOf(financeid);
- if (indexOfCurrentF > -1)
- {
- financeid = investmentquery[indexOfCurrentF];
- fid = investmentquery[indexOfCurrentF];
- }
- else
- {
- if (financeid > 0)
- financeid = fid;
- }
- //End:- Updated On 2-4-2014 regarding tab and product selection
- tblfinance_investments _obj = ctx.tblfinance_investments.Where(x => x.financeid == fid).FirstOrDefault();
- if (_obj == null)
- {
- //insert
- tblfinance_investments newfinanceinvestment = new tblfinance_investments();
- newfinanceinvestment.financeid = fid;
- ctx.tblfinance_investments.Add(newfinanceinvestment);
- ctx.SaveChanges();
- }
- }
- var queryInvestment = (from c in ctx.tblcontacts
- join ft in ctx.tblfinances on c.contactid equals ft.contact
- join finv in ctx.tblfinance_investments on ft.financeid equals finv.financeid
- where ft.contact == contactid && ft.type == appid && ft.financeid == financeid
- select new { ft, finv, c }).FirstOrDefault();
- Investment investment = new Investment();
- if (queryInvestment != null)
- {
- investment.investment_financeid = queryInvestment.ft.financeid;
- investment.investment_amount = queryInvestment.ft.amount.HasValue ? (decimal?)Math.Round(queryInvestment.ft.amount.Value, 2) : null;
- investment.investment_commission = queryInvestment.ft.commission.HasValue ? (decimal?)Math.Round(queryInvestment.ft.commission.Value, 2) : null;
- investment.investment_contributors = queryInvestment.ft.premium.HasValue ? (decimal?)Math.Round(queryInvestment.ft.premium.Value, 2) : null;
- investment.investment_date = queryInvestment.ft.followup.HasValue ? Helper.GetDateString(queryInvestment.ft.followup.Value) : string.Empty;
- investment.investment_datelive = queryInvestment.ft.datelive.HasValue ? Helper.GetDateString(queryInvestment.ft.datelive.Value) : string.Empty;
- investment.investment_expires = queryInvestment.ft.dateexpire.HasValue ? Helper.GetDateString(queryInvestment.ft.dateexpire.Value) : string.Empty;
- investment.investment_financetype = GetFinanceType(FinanceType.Investments);
- investment.investment_fundvalue = queryInvestment.ft.fundvalue.HasValue ? (decimal?)Math.Round(queryInvestment.ft.fundvalue.Value, 2) : null;
- investment.investment_policyref = queryInvestment.ft.policyreference != null ? queryInvestment.ft.policyreference : string.Empty;
- investment.investment_provider = queryInvestment.ft.provider != null ? queryInvestment.ft.provider : string.Empty; ;
- investment.investment_riskprofiles = queryInvestment.ft.subtype ?? 0;
- investment.investment_status = queryInvestment.ft.status ?? 0;
- investment.investment_time = queryInvestment.ft.followup.HasValue ? queryInvestment.ft.followup.Value.ToString("HH:mm") : string.Empty;
- // Update on 23-6-2014 due to performance issue as the GetNOte method get called Explicitly
- // investment.InvestmentNotes = GetNotes(contactid, financeid);
- investment.investment_contactid = contactid;
- investment.investment_AppicationType = appid;
- int index = investmentquery.IndexOf(queryInvestment.ft.financeid) + 1;
- investment.Investment_Name = string.Format("{0}{1}", index, index == 1 ? "st Policy" + DisplayAddressAndLender(investment.investment_financeid) : index == 2 ? "nd Policy" + DisplayAddressAndLender(investment.investment_financeid) : index == 3 ? "rd Policy" + DisplayAddressAndLender(investment.investment_financeid) : "th Policy" + DisplayAddressAndLender(investment.investment_financeid));
- //Added Client Fee 27-10-2014
- investment.investment_Clientfee = queryInvestment.ft.ClientFee;
- //********************************
- investment.investment_isPolicyForOtherApplicant = queryInvestment.ft.isPolicyForOtherApplicant.HasValue ? queryInvestment.ft.isPolicyForOtherApplicant.Value : false;
- }
- else
- {
- investment.investment_financetype = GetFinanceType(FinanceType.Investments);
- }
- return investment;
- }
- #endregion [Get various product details 2015-03-31]
- #region Reports
- /// <summary>
- /// Method for Brroker Lead Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Broker List</returns>
- public List<BrokerLeadTable> GetBrokerLeadReport(string Conditions, int accountid, string Conditions1 = "", string dateFilter = "")
- {
- List<BrokerLeadTable> BrokerLeadTableList = new List<BrokerLeadTable>();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- Param[2] = new SqlParameter("@DateFilter", dateFilter);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllBrokerReport", Param);
- BrokerLeadTableList = (from DataRow row in dt.Rows
- select new BrokerLeadTable
- {
- Brokerid = Convert.ToInt32(row["brokerid"]),
- BrokerName = Convert.ToString(row["broker"]),
- LeadPercent = "0",
- NoOfLeads = Convert.ToInt32(row["TotalCount"].ToString()),
- OfferQualification = Convert.ToInt32(((row["offerqualified"] == DBNull.Value || row["offerqualified"] == null) ? " " : row["offerqualified"]).ToString())
- }).ToList();
- return BrokerLeadTableList.OrderByDescending(x => x.NoOfLeads).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplication", "GetBrokerLeadReport", ex.Message);
- return BrokerLeadTableList.ToList();
- }
- }
- /// <summary>
- /// Method for Agent Lead Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="isNeg">Negotiator</param>
- /// <param name="Condition1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Agent List</returns>
- public List<AgentLeadTable> GetAfflicateLeadReport(string Conditions, int accountid, bool isNeg, string Condition1 = "", string dateFilter = "")
- {
- List<AgentLeadTable> AgentLeadList = new List<AgentLeadTable>();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@conditions", Conditions);
- if (!string.IsNullOrEmpty(Condition1))
- Param[1] = new SqlParameter("@conditions1", Condition1);
- Param[2] = new SqlParameter("@DateFilter", dateFilter);
- string _procName = "GetAllAfflicateReport";
- //Check For Is Negotiation When the negotiator selected the below procedure will be selected elase the old
- if (isNeg)
- _procName = "GetAllAfflicateReport_Neg_Update";
- //****************************************
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- AgentLeadList = (from DataRow row in dt.Rows
- select new AgentLeadTable
- {
- AgentId = Convert.ToInt32(((row["account"] == DBNull.Value || row["account"] == null) ? " " : row["account"]).ToString()),
- AgentName = ((row["agentname"] == DBNull.Value || row["agentname"] == null) ? " " : row["agentname"]).ToString(),
- LeadPercent = "0",
- NoOfLeads = Convert.ToInt32(((row["TotalCount"] == DBNull.Value || row["TotalCount"] == null) ? " " : row["TotalCount"]).ToString()),
- NegName = (isNeg == true ? ((row["negref"] == DBNull.Value || row["negref"] == null) ? " " : row["negref"]).ToString() : ""),
- OfferQualification = Convert.ToInt32(((row["offerqualified"] == DBNull.Value || row["offerqualified"] == null) ? " " : row["offerqualified"]).ToString()),
- }).ToList();
- return AgentLeadList.OrderByDescending(x => x.NoOfLeads).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplication", "GetAfflicateLeadReport", ex.Message);
- return AgentLeadList.ToList();
- }
- }
- //added 13-01-2015
- /// <summary>
- /// Method for Agent Lead Report with Branch
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="isBranch">Branch</param>
- /// <param name="Condition1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns></returns>
- public List<AgentLeadTableBranch> GetAfflicateLeadReport_Branch(string Conditions, int accountid, bool isBranch, string Condition1 = "", string dateFilter = "")
- {
- List<AgentLeadTableBranch> AgentLeadBranchList = new List<AgentLeadTableBranch>();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Condition1);
- Param[2] = new SqlParameter("@DateFilter", dateFilter);
- string _procName = "GetAllAfflicateReport_NullBranch";
- //Check For Is Negotiation When the negotiator selected the below procedure will be selected elase the old
- if (isBranch)
- _procName = "GetAllAfflicateReport_Branch_Update";
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- AgentLeadBranchList = (from DataRow row in dt.Rows
- select new AgentLeadTableBranch
- {
- AgentId = Convert.ToInt32(((row["account"] == DBNull.Value || row["account"] == null) ? " " : row["account"]).ToString()),
- AgentName = ((row["agentname"] == DBNull.Value || row["agentname"] == null) ? " " : row["agentname"]).ToString(), //GetAgentName(Convert.ToInt32(row["account"])),
- LeadPercent = "0",
- NoOfLeads = Convert.ToInt32(((row["TotalCount"] == DBNull.Value || row["TotalCount"] == null) ? " " : row["TotalCount"]).ToString()),
- Branch = (isBranch == true ? ((row["branch"] == DBNull.Value || row["branch"] == null) ? " " : row["branch"]).ToString() : ""),
- OfferQualification = Convert.ToInt32(((row["offerqualified"] == DBNull.Value || row["offerqualified"] == null) ? " " : row["offerqualified"]).ToString()),
- }).ToList();
- return AgentLeadBranchList.OrderByDescending(x => x.NoOfLeads).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Qapplication", "GetafflicateLeadReportBanch", ex.Message);
- return AgentLeadBranchList;
- }
- }
- /// <summary>
- /// Method for product Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for product report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="fromdate">From Date</param>
- /// <param name="todate">To Date</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Roduct List</returns>
- public List<ProductReport> GetProductReport(string Conditions, int accountid, DateTime? fromdate, DateTime? todate, string Conditions1 = "")
- {
- List<ProductReport> ProductReportList = new List<ProductReport>();
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetProductReport", Param);
- ProductReportList = (from DataRow row in dt.Rows
- select new ProductReport
- {
- Product = GetFinanceTableData(row["type"].ToString()).type,
- NoOfLeads = Convert.ToInt32(row["TotalLeads"]),
- InProgress = GetFinanceTableData(row["type"].ToString(), (int)MortgageStatus.NewLead, fromdate, todate),
- Complete = GetFinanceTableData(row["type"].ToString(), (int)MortgageStatus.Completed, fromdate, todate),
- TotalCommission = row["TotalCommission"].ToString() != "" ? Math.Round(Convert.ToDecimal(row["TotalCommission"].ToString()), 2).ToString() : "0",
- AvgCommission = row["AvgCommission"].ToString() != "" ? Math.Round(Convert.ToDecimal(row["AvgCommission"].ToString()), 2).ToString() : "0",
- }).ToList();
- return ProductReportList.OrderByDescending(x => x.AvgCommission).ToList();
- }
- private tblfinancetype GetFinanceTableData(string type)
- {
- int _type = Convert.ToInt32(type);
- var d = ctx.tblfinancetypes.Where(x => x.financetypeid == _type).FirstOrDefault();
- if (d == null)
- d = new tblfinancetype(); ;
- return d;
- }
- private int GetFinanceTableData(string type, int status, DateTime? fromdate, DateTime? todate)
- {
- int _type = Convert.ToInt32(type);
- var d = ctx.tblfinances.Where(x => x.type == _type && x.status == status && (x.created.Value >= fromdate.Value && x.created.Value <= todate.Value));
- return d.Count();
- }
- /// <summary>
- /// Method for status Report in the Main Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for product report</param>
- /// <param name="accountid">Accout Id</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Status report List</returns>
- public List<statusReport> GetStatusReport(string Conditions, int accountid, string Conditions1 = "")
- {
- List<statusReport> StatusReportList = new List<statusReport>();
- try
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetStatusReport", Param);
- StatusReportList = (from DataRow row in dt.Rows
- select new statusReport
- {
- status = row["StatusName"].ToString(),
- NoOfLeads = Convert.ToInt32(row["TotalLeads"]),
- }).ToList();
- return StatusReportList;
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplication", "GetStatusRepot", ex.Message);
- return StatusReportList;
- }
- }
- /// <summary>
- /// Method for date for main report chart
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Accoutnt Id</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <returns>MAin Report Chart Data</returns>
- public List<ReportDataPoint> GetLeadReport(string Conditions, int accountid, string Conditions1 = "")
- {
- List<ReportDataPoint> ReportdataList = new List<ReportDataPoint>();
- try
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "LeadReport", Param);
- ReportdataList = (from DataRow row in dt.Rows
- select new ReportDataPoint
- {
- Dated = row.IsNull("created") ? DateTime.MinValue : DateTime.Parse(row["created"].ToString()),
- Value = Convert.ToInt32(row["TotalCount"]),
- }).ToList();
- return ReportdataList;
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplicaition", "GetLeadreport", ex.Message);
- return ReportdataList;
- }
- }
- public List<string> GetProviderOrSoliciter(int accountId, int datatype = 0, int financetype = 0, string inputtext = "")
- {
- List<string> namelist = new List<string>();
- try
- {
- SqlParameter[] Param = new SqlParameter[4];
- Param[0] = new SqlParameter("@inputtext", inputtext);
- Param[1] = new SqlParameter("@datatype", datatype);
- Param[2] = new SqlParameter("@Type", financetype);
- Param[3] = new SqlParameter("@parentuserid", accountId);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetProviderOrSoliciter", Param);
- if (dt != null)
- namelist = dt.AsEnumerable().Select(dr => dr.Field<string>("Name")).ToList();
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetProviderOrSoliciter", ex.Message);
- }
- return namelist;
- }
- public List<string> GetProviderOrSoliciter(int accountId, int pageno, out int Total, int datatype = 0, int financetype = 0, string inputtext = "")
- {
- Total = 20;
- List<string> namelist = new List<string>();
- try
- {
- SqlParameter[] Param = new SqlParameter[5];
- Param[0] = new SqlParameter("@inputtext", inputtext);
- Param[1] = new SqlParameter("@datatype", datatype);
- Param[2] = new SqlParameter("@Type", financetype);
- Param[3] = new SqlParameter("@parentuserid", accountId);
- Param[4] = new SqlParameter("@pageno", pageno);
- var ds = SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "GetProviderOrSoliciterDemo", Param);
- if (ds.Tables[0] != null)
- {
- namelist = ds.Tables[0].AsEnumerable().Select(dr => dr.Field<string>("Name")).ToList();
- Total = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
- }
- }
- catch
- {
- }
- return namelist;
- }
- /// <summary>
- /// Getting broker name
- /// </summary>
- /// <param name="Brokerid"></param>
- /// <returns></returns>
- public string GetBrokerName(int Brokerid)
- {
- return ctx.tblusers.Where(x => x.userid == Brokerid).Select(x => x.brokername).FirstOrDefault();
- }
- public string GetAgentName(int Agentid)
- {
- return ctx.tblaccounts.Where(x => x.accountid == Agentid).Select(x => x.companyname).FirstOrDefault();
- }
- /// <summary>
- /// Checking for broker
- /// </summary>
- /// <param name="UserId"></param>
- /// <returns></returns>
- public bool IsBroker(int UserId)
- {
- return ctx.tblusers.Any(x => x.userid == UserId && x.active == true && x.broker == true);
- }
- /// <summary>
- /// Checking for insurance broker
- /// </summary>
- /// <param name="UserId"></param>
- /// <returns></returns>
- public bool IsInsuranceBroker(int UserId)
- {
- return ctx.tblusers.Any(x => x.userid == UserId && x.active == true && x.broker == true && x.account == 880);
- }
- /// <summary>
- /// Checking for Mortgage Broker
- /// </summary>
- /// <param name="UserId"></param>
- /// <returns></returns>
- public bool IsMortgageBroker(int UserId)
- {
- return ctx.tblusers.Any(x => x.userid == UserId && x.active == true && x.broker == true && x.account == 6569);
- }
- /// <summary>
- /// Checking for admin
- /// </summary>
- /// <param name="UserId"></param>
- /// <returns></returns>
- public bool IsAdmin(int UserId)
- {
- return ctx.tblusers.Any(x => x.userid == UserId && x.active == true && (x.administrator.HasValue == true && x.administrator.Value == true) && (x.broker.HasValue == false || x.broker.Value == false));
- }
- /// <summary>
- /// Checking for User
- /// </summary>
- /// <param name="UserId"></param>
- /// <returns></returns>
- public bool IsUser(int UserId)
- {
- return 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));
- }
- /// <summary>
- /// Checking for super admin
- /// </summary>
- /// <param name="UserId"></param>
- /// <returns></returns>
- public bool IsSuperAdmin(int UserId)
- {
- return ctx.tblusers.Any(x => x.userid == UserId && x.active == true && (x.administrator.HasValue == true && x.administrator.Value == true) && (x.broker.HasValue == false || x.broker.Value == false) && (!x.AdminId.HasValue || x.AdminId.Value == 0));
- }
- /// <summary>
- /// Checking for Manager
- /// </summary>
- /// <param name="UserId"></param>
- /// <param name="teamId"></param>
- /// <param name="brokers"></param>
- /// <returns></returns>
- 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(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "IsManager", ex.Message);
- }
- return _chk;
- }
- /// <summary>
- /// Checking for administrator
- /// </summary>
- /// <param name="UserId"></param>
- /// <param name="brokers"></param>
- /// <returns></returns>
- 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(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "IsAdministrator", ex.Message);
- }
- return _chk;
- }
- /// <summary>
- /// Is creating admin user
- /// </summary>
- /// <param name="accountId"></param>
- /// <param name="UserId"></param>
- /// <param name="adminaccId"></param>
- /// <param name="brokers"></param>
- /// <returns></returns>
- public bool IsCreatedAdminUser(int accountId, int UserId, out int adminaccId, out string brokers)
- {
- bool _chk = false;
- brokers = "";
- adminaccId = 0;
- try
- {
- if (ctx.tblusers.Any(u => u.userid == UserId && u.AdminId.HasValue && u.AdminId.Value > 0 && u.active == true && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == false || u.broker.Value == false)))
- {
- _chk = true;
- adminaccId = ctx.tblusers.Where(c => c.userid == UserId).FirstOrDefault().AdminId.Value;
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@AdminId", accountId);
- var dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAdminTeamMembersIds", Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- brokers = Convert.ToString(dt.Rows[0]["Brokers"]).Trim().TrimEnd(',');
- }
- }
- }
- catch
- {
- }
- return _chk;
- }
- /// <summary>
- /// Method for checking User type
- /// </summary>
- /// <param name="UserId">User Id</param>
- /// <param name="teamId">Team Id</param>
- /// <param name="accountId">Account Id</param>
- /// <param name="brokers">Brokersg</param>
- /// <returns>User Type </returns>
- 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 = "";
- var _objU = ctx.tblusers.Where(x => x.userid == UserId).FirstOrDefault();
- if (_objU != null)
- {
- if (IsAdministrator(UserId, out brokers))
- {
- _uType = (int)UserType.Admin;
- accountId = _objU.account;
- }
- else if (IsManager(UserId, out teamId, out brokers))
- {
- _uType = (int)UserType.Manager;
- accountId = _objU.account;
- }
- else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && _objU.broker.HasValue && _objU.broker.Value)
- {
- _uType = (int)UserType.Broker;
- accountId = _objU.account;
- }
- else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && (!_objU.broker.HasValue || !_objU.broker.Value))
- {
- _uType = (int)UserType.GeneralUser;
- accountId = _objU.account;
- }
- }
- return _uType;
- }
- /// <summary>
- /// Method for checking User type
- /// </summary>
- /// <param name="UserId">User Id</param>
- /// <param name="teamId">Team Id</param>
- /// <param name="accountId">Account Id</param>
- /// <param name="brokers">Brokersg</param>
- /// <returns>User Type </returns>
- public int CheckUserType1(int UserId, out int Id)
- {
- int _uType = 0; // 1- Admin, 2- Manager, 3- Broker, 4- general User
- int teamId = 0;
- int accountId = 0;
- string brokers = "";
- Id = 0;
- var _objU = ctx.tblusers.Where(x => x.userid == UserId).FirstOrDefault();
- if (_objU != null)
- {
- if (IsAdministrator(UserId, out brokers))
- {
- _uType = (int)UserType.Admin;
- accountId = _objU.account;
- Id = _objU.account;
- }
- else if (IsManager(UserId, out teamId, out brokers))
- {
- _uType = (int)UserType.Manager;
- accountId = _objU.account;
- Id = teamId;
- }
- else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && _objU.broker.HasValue && _objU.broker.Value)
- {
- _uType = (int)UserType.Broker;
- accountId = _objU.account;
- Id = UserId;
- }
- else if ((!_objU.administrator.HasValue || !_objU.administrator.Value) && (!_objU.broker.HasValue || !_objU.broker.Value))
- {
- _uType = (int)UserType.GeneralUser;
- //accountId = _objU.account;
- int account = ctx.tblaccounts.Where(u => u.accountid == UserId).Select(u => u.parent.HasValue ? u.parent.Value : 0).FirstOrDefault();
- Id = account;
- }
- }
- return _uType;
- }
- #endregion
- #region Yearly Holiday Settings
- /// <summary>
- /// Saving Yearly Holiday setting
- /// </summary>
- /// <param name="model"></param>
- /// <param name="AccountId"></param>
- /// <returns></returns>
- public int YearlyHolidaySave(YearlyHolidaySettingsModel model, int AccountId)
- {
- int _chk = 0;
- try
- {
- using (SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"])))
- {
- con.Open();
- SqlDataAdapter com = new SqlDataAdapter("USPYearlyHolidaySettingsAddUpdate", con);
- com.SelectCommand.CommandType = CommandType.StoredProcedure;
- com.SelectCommand.Parameters.AddWithValue("@Id", model.ID.HasValue ? model.ID.Value : 0);
- com.SelectCommand.Parameters.AddWithValue("@Year", model.Year.HasValue ? model.Year.Value : 0);
- com.SelectCommand.Parameters.AddWithValue("@Date", model.Date.GetDate());
- com.SelectCommand.Parameters.AddWithValue("@HolidayTitle", model.Title);
- com.SelectCommand.Parameters.AddWithValue("@HolidayDescription", model.Description);
- com.SelectCommand.Parameters.AddWithValue("@EntryBy", model.EntryBy);
- com.SelectCommand.Parameters.AddWithValue("@UpdatedBy", model.UpdateBy);
- com.SelectCommand.Parameters.AddWithValue("@IsActive", true);
- com.SelectCommand.Parameters.AddWithValue("@IsDeleted", false);
- com.SelectCommand.Parameters.AddWithValue("@AddDate", DateTime.Now);
- com.SelectCommand.Parameters.AddWithValue("@UpdateDate", DateTime.Now);
- com.SelectCommand.Parameters.AddWithValue("@ActionType", 1);
- com.SelectCommand.Parameters.AddWithValue("@AccountId", AccountId);
- //@ReturnMessage
- SqlParameter outParam1 = com.SelectCommand.Parameters.Add("@Chk", SqlDbType.Int);
- outParam1.Direction = ParameterDirection.Output;
- com.SelectCommand.ExecuteNonQuery();
- _chk = Convert.ToInt32((outParam1.SqlValue != DBNull.Value || outParam1.SqlValue != null) ? outParam1.SqlValue.ToString() : "0");
- }
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "YearlyHolidaysave", ex.Message);
- _chk = 0;
- }
- return _chk;
- }
- /// <summary>
- /// Deleting yearly holiday setting
- /// </summary>
- /// <param name="model"></param>
- /// <param name="AccountId"></param>
- /// <returns></returns>
- public int YearlyHolidayDelete(YearlyHolidaySettingsModel model, int AccountId)
- {
- int _chk = 0;
- try
- {
- using (SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"])))
- {
- con.Open();
- SqlDataAdapter com = new SqlDataAdapter("USPYearlyHolidaySettingsAddUpdate", con);
- com.SelectCommand.CommandType = CommandType.StoredProcedure;
- com.SelectCommand.Parameters.AddWithValue("@Id", model.ID.Value);
- com.SelectCommand.Parameters.AddWithValue("@Year", model.Year.HasValue ? model.Year.Value : 0);
- com.SelectCommand.Parameters.AddWithValue("@Date", DateTime.Now);
- com.SelectCommand.Parameters.AddWithValue("@HolidayTitle", model.Title);
- com.SelectCommand.Parameters.AddWithValue("@HolidayDescription", model.Description);
- com.SelectCommand.Parameters.AddWithValue("@EntryBy", model.EntryBy);
- com.SelectCommand.Parameters.AddWithValue("@UpdatedBy", model.UpdateBy);
- com.SelectCommand.Parameters.AddWithValue("@IsActive", true);
- com.SelectCommand.Parameters.AddWithValue("@IsDeleted", false);
- com.SelectCommand.Parameters.AddWithValue("@AddDate", DateTime.Now);
- com.SelectCommand.Parameters.AddWithValue("@UpdateDate", DateTime.Now);
- com.SelectCommand.Parameters.AddWithValue("@ActionType", 2);
- com.SelectCommand.Parameters.AddWithValue("@AccountId", AccountId);
- SqlParameter outParam1 = com.SelectCommand.Parameters.Add("@Chk", SqlDbType.Int);
- outParam1.Direction = ParameterDirection.Output;
- com.SelectCommand.ExecuteNonQuery();
- _chk = Convert.ToInt32((outParam1.SqlValue != DBNull.Value || outParam1.SqlValue != null) ? outParam1.SqlValue.ToString() : "0");
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "YearlyHolidayDelete", ex.Message);
- _chk = 0;
- }
- return _chk;
- }
- /// <summary>
- /// Getting Yearly Holidays
- /// </summary>
- /// <param name="model"></param>
- /// <param name="AccountId"></param>
- /// <returns></returns>
- public List<YearlyHolidaySettingsModel> GetYearlyHolidays(YearlyHolidayModel model, int AccountId)
- {
- List<YearlyHolidaySettingsModel> _yearlyholidays = new List<YearlyHolidaySettingsModel>();
- string date = System.DateTime.Now.ToString("MM/dd/yyyy");
- if (!string.IsNullOrWhiteSpace(model.Date))
- date = model.Date.GetDate().HasValue ? model.Date.GetDate().Value.ToString("MM/dd/yyyy") : null;
- else
- date = null;
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@Year", model.Year.HasValue ? model.Year.Value : 0);
- Param[1] = new SqlParameter("@Date", date);
- Param[2] = new SqlParameter("@AccountId", AccountId);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "USPGetYearlyHolidays", Param);
- _yearlyholidays = (from DataRow row in dt.Rows
- select new YearlyHolidaySettingsModel
- {
- ID = Convert.ToInt32(((row["Id"] == DBNull.Value || row["Id"] == null) ? 0 : row["Id"]).ToString()),
- Year = Convert.ToInt32(((row["Year"] == DBNull.Value || row["Year"] == null) ? "" : row["Year"]).ToString()),
- Date = Convert.ToString(((row["Date"] == DBNull.Value || row["Date"] == null) ? "" : row["Date"]).ToString()),
- Title = Convert.ToString(((row["Title"] == DBNull.Value || row["Title"] == null) ? "" : row["Title"]).ToString()),
- Description = Convert.ToString(((row["Description"] == DBNull.Value || row["Description"] == null) ? "" : row["Description"]).ToString())
- }).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetYearlyHolidays", ex.Message);
- }
- return _yearlyholidays;
- }
- /// <summary>
- /// Get Yearly Holidays
- /// </summary>
- /// <param name="SearchText"></param>
- /// <returns></returns>
- public List<string> GetYearsForHolidays(string SearchText)
- {
- List<string> _years = new List<string>();
- try
- {
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@SearchText", SearchText);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetYearsForHolidays", Param);
- _years = (from DataRow row in dt.Rows
- select Convert.ToString(((row["Year"] == DBNull.Value || row["Year"] == null) ? "" : row["Year"]).ToString())
- ).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetYersForHolidays", ex.Message);
- }
- return _years;
- }
- #endregion
- #region Over All Broker Summary
- /// <summary>
- /// Getting All broker summary details
- /// </summary>
- /// <param name="BrokerId"></param>
- /// <param name="FromDate"></param>
- /// <param name="ToDate"></param>
- /// <returns></returns>
- public OverAllBrokerSummary GetOverAllBrokerSummary(int BrokerId, string FromDate = null, string ToDate = null)
- {
- OverAllBrokerSummary _OverAllBrokerSummary = new OverAllBrokerSummary();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@BrokerId", BrokerId);
- if (!string.IsNullOrWhiteSpace(FromDate))
- {
- Param[1] = new SqlParameter("@FromDate", FromDate.GetDate().HasValue ? FromDate.GetDate().Value.ToString("MM/dd/yyyy") : null);
- }
- if (!string.IsNullOrWhiteSpace(ToDate))
- {
- Param[2] = new SqlParameter("@ToDate", ToDate.GetDate().HasValue ? ToDate.GetDate().Value.ToString("MM/dd/yyyy") : null);
- }
- string _procName = "GetOverAllBrokerSummary";
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- string subPath = System.Configuration.ConfigurationManager.AppSettings["BrokerImages"] ?? "~/Content/BrokerImages/";
- _OverAllBrokerSummary = (from DataRow row in dt.Rows
- select new OverAllBrokerSummary
- {
- BrokerId = Convert.ToInt32(((row["BrokerId"] == DBNull.Value || row["BrokerId"] == null) ? "0" : row["BrokerId"]).ToString()),
- BrokerName = ((row["BrokerName"] == DBNull.Value || row["BrokerName"] == null) ? " " : row["BrokerName"]).ToString(),
- DetailInfo = ((row["DetailInfo"] == DBNull.Value || row["DetailInfo"] == null) ? " " : row["DetailInfo"]).ToString(),
- BrokerImage = subPath + ((row["BrokerImage"] == DBNull.Value || row["BrokerImage"] == null) ? "noimage.jpg" : row["BrokerImage"]).ToString(),
- TotalDays = Convert.ToInt32(((row["TotalDays"] == DBNull.Value || row["TotalDays"] == null) ? "0" : row["TotalDays"]).ToString()),
- NewLead = Convert.ToInt32(((row["NewLead"] == DBNull.Value || row["NewLead"] == null) ? "0" : row["NewLead"]).ToString()),
- Remortgage = Convert.ToInt32(((row["Remortgage"] == DBNull.Value || row["Remortgage"] == null) ? "0" : row["Remortgage"]).ToString()),
- CallBack = Convert.ToInt32(((row["CallBack"] == DBNull.Value || row["CallBack"] == null) ? "0" : row["CallBack"]).ToString()),
- Meeting = Convert.ToInt32(((row["Meeting"] == DBNull.Value || row["Meeting"] == null) ? "0" : row["Meeting"]).ToString()),
- DIP = Convert.ToInt32(((row["DIP"] == DBNull.Value || row["DIP"] == null) ? "0" : row["DIP"]).ToString()),
- PreOfferProcessing = Convert.ToInt32(((row["PreOfferProcessing"] == DBNull.Value || row["PreOfferProcessing"] == null) ? "0" : row["PreOfferProcessing"]).ToString()),
- PostOfferProcessing = Convert.ToInt32(((row["PostOfferProcessing"] == DBNull.Value || row["PostOfferProcessing"] == null) ? "0" : row["PostOfferProcessing"]).ToString()),
- Completed = Convert.ToInt32(((row["Completed"] == DBNull.Value || row["Completed"] == null) ? "0" : row["Completed"]).ToString()),
- Prospect = Convert.ToInt32(((row["Prospect"] == DBNull.Value || row["Prospect"] == null) ? "0" : row["Prospect"]).ToString()),
- Deleted = Convert.ToInt32(((row["Deleted"] == DBNull.Value || row["Deleted"] == null) ? "0" : row["Deleted"]).ToString()),
- Total = Convert.ToInt32(((row["Total"] == DBNull.Value || row["Deleted"] == null) ? "0" : row["Total"]).ToString()),
- TotalLife = Convert.ToInt32(((row["TotalLife"] == DBNull.Value || row["TotalLife"] == null) ? "0" : row["TotalLife"]).ToString()),
- CompletedLife = Convert.ToInt32(((row["CompletedLife"] == DBNull.Value || row["CompletedLife"] == null) ? "0" : row["CompletedLife"]).ToString()),
- DaysPerMortgaeDefault = Convert.ToDecimal(((row["DaysPerMortgaeDefault"] == DBNull.Value || row["DaysPerMortgaeDefault"] == null) ? "0" : row["DaysPerMortgaeDefault"]).ToString()),
- LeadToMeetingDefault = Convert.ToDecimal(((row["LeadToMeetingDefault"] == DBNull.Value || row["LeadToMeetingDefault"] == null) ? "0" : row["LeadToMeetingDefault"]).ToString()),
- MeetingToDIPDefault = Convert.ToDecimal(((row["MeetingToDIPDefault"] == DBNull.Value || row["MeetingToDIPDefault"] == null) ? "0" : row["MeetingToDIPDefault"]).ToString()),
- DIPToAppDefault = Convert.ToDecimal(((row["DIPToAppDefault"] == DBNull.Value || row["DIPToAppDefault"] == null) ? "0" : row["DIPToAppDefault"]).ToString()),
- SubmittedToCompletedDefault = Convert.ToDecimal(((row["SubmittedToCompletedDefault"] == DBNull.Value || row["SubmittedToCompletedDefault"] == null) ? "0" : row["SubmittedToCompletedDefault"]).ToString()),
- MortgaeToProtectionDefault = Convert.ToDecimal(((row["MortgaeToProtectionDefault"] == DBNull.Value || row["MortgaeToProtectionDefault"] == null) ? "0" : row["MortgaeToProtectionDefault"]).ToString()),
- }).ToList()[0];
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException,"Q_Application","GetOverallBrokerSummary",ex.Message);
- }
- return _OverAllBrokerSummary ?? new OverAllBrokerSummary();
- }
- /// <summary>
- /// Getting broker default setting
- /// </summary>
- /// <param name="AccountId"></param>
- /// <returns></returns>
- public BrokerDefaultReportSetting GetBrokerDefaultReportSetting(int AccountId)
- {
- BrokerDefaultReportSetting _BrokerDefaultReportSetting = new BrokerDefaultReportSetting();
- try
- {
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@AccountId", AccountId);
- string _procName = "GetBrokerDefaultReportSetting";
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- _BrokerDefaultReportSetting = (from DataRow row in dt.Rows
- select new BrokerDefaultReportSetting
- {
- DefaultId = Convert.ToInt32(((row["DefaultId"] == DBNull.Value || row["DefaultId"] == null) ? "0" : row["DefaultId"]).ToString()),
- AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
- DaysPerMortgae = Convert.ToDecimal(((row["DaysPerMortgae"] == DBNull.Value || row["DaysPerMortgae"] == null) ? "0" : row["DaysPerMortgae"]).ToString()),
- LeadToMeeting = Convert.ToDecimal(((row["LeadToMeeting"] == DBNull.Value || row["LeadToMeeting"] == null) ? "0" : row["LeadToMeeting"]).ToString()),
- MeetingToDIP = Convert.ToDecimal(((row["MeetingToDIP"] == DBNull.Value || row["MeetingToDIP"] == null) ? "0" : row["MeetingToDIP"]).ToString()),
- DIPToApp = Convert.ToDecimal(((row["DIPToApp"] == DBNull.Value || row["DIPToApp"] == null) ? "0" : row["DIPToApp"]).ToString()),
- SubmittedToCompleted = Convert.ToDecimal(((row["SubmittedToCompleted"] == DBNull.Value || row["SubmittedToCompleted"] == null) ? "0" : row["SubmittedToCompleted"]).ToString()),
- MortgaeToProtection = Convert.ToDecimal(((row["MortgaeToProtection"] == DBNull.Value || row["MortgaeToProtection"] == null) ? "0" : row["MortgaeToProtection"]).ToString()),
- }).ToList()[0];
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetBrokerDefaultReportSetting", ex.Message);
- }
- return _BrokerDefaultReportSetting ?? new BrokerDefaultReportSetting();
- }
- /// <summary>
- /// Broker Default Report setting Adding update
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public int BrokerDefaultReportSettingAddUpdate(BrokerDefaultReportSetting model)
- {
- int _chk = 0;
- try
- {
- using (SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"])))
- {
- con.Open();
- SqlDataAdapter com = new SqlDataAdapter("BrokerDefaultReportSettingAddUpdate", con);
- com.SelectCommand.CommandType = CommandType.StoredProcedure;
- com.SelectCommand.Parameters.AddWithValue("@AccountId", model.AccountId);
- com.SelectCommand.Parameters.AddWithValue("@DaysPerMortgae", model.DaysPerMortgae);
- com.SelectCommand.Parameters.AddWithValue("@LeadToMeeting", model.LeadToMeeting);
- com.SelectCommand.Parameters.AddWithValue("@MeetingToDIP", model.MeetingToDIP);
- com.SelectCommand.Parameters.AddWithValue("@DIPToApp", model.DIPToApp);
- com.SelectCommand.Parameters.AddWithValue("@SubmittedToCompleted", model.SubmittedToCompleted);
- com.SelectCommand.Parameters.AddWithValue("@MortgaeToProtection", model.MortgaeToProtection);
- com.SelectCommand.Parameters.AddWithValue("@EntryBy", model.EntryBy);
- com.SelectCommand.Parameters.AddWithValue("@UpdateBy", model.UpdateBy);
- _chk = com.SelectCommand.ExecuteNonQuery();
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "BrokerDefaultReportSettingAddUpdate", ex.Message);
- _chk = 0;
- }
- return _chk;
- }
- #endregion
- #region Default Holiday Settings
- /// <summary>
- /// Getting Broker Default Holiday Setting
- /// </summary>
- /// <param name="AccountId"></param>
- /// <returns></returns>
- public BrokerDefaultHolidaySetting GetBrokerDefaultHolidaySetting(int AccountId)
- {
- BrokerDefaultHolidaySetting _BrokerDefaultHolidaySetting = new BrokerDefaultHolidaySetting();
- try
- {
- SqlParameter[] Param = new SqlParameter[1];
- Param[0] = new SqlParameter("@AccountId", AccountId);
- string _procName = "GetBrokerDefaultHolidaySetting";
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- if (dt != null && dt.Rows.Count > 0)
- {
- _BrokerDefaultHolidaySetting = (from DataRow row in dt.Rows
- select new BrokerDefaultHolidaySetting
- {
- DefaultId = Convert.ToInt32(((row["DefaultId"] == DBNull.Value || row["DefaultId"] == null) ? "0" : row["DefaultId"]).ToString()),
- AccountId = Convert.ToInt32(((row["AccountId"] == DBNull.Value || row["AccountId"] == null) ? "0" : row["AccountId"]).ToString()),
- DaysOff = Convert.ToDecimal(((row["DaysOff"] == DBNull.Value || row["DaysOff"] == null) ? "0" : row["DaysOff"]).ToString()),
- HoursOff = Convert.ToDecimal(((row["HoursOff"] == DBNull.Value || row["HoursOff"] == null) ? "0" : row["HoursOff"]).ToString()),
- }).ToList()[0];
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetBrokerDefualtHolidaysetting", ex.Message);
- }
- return _BrokerDefaultHolidaySetting ?? new BrokerDefaultHolidaySetting();
- }
- /// <summary>
- /// getting broker default holiday setting add update
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public int BrokerDefaultHolidaySettingAddUpdate(BrokerDefaultHolidaySetting model)
- {
- int _chk = 0;
- try
- {
- using (SqlConnection con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"])))
- {
- con.Open();
- SqlDataAdapter com = new SqlDataAdapter("BrokerDefaultHolidaySettingAddUpdate", con);
- com.SelectCommand.CommandType = CommandType.StoredProcedure;
- com.SelectCommand.Parameters.AddWithValue("@AccountId", model.AccountId);
- com.SelectCommand.Parameters.AddWithValue("@DaysOff", model.DaysOff);
- com.SelectCommand.Parameters.AddWithValue("@HoursOff", model.HoursOff);
- com.SelectCommand.Parameters.AddWithValue("@EntryBy", model.EntryBy);
- com.SelectCommand.Parameters.AddWithValue("@UpdateBy", model.UpdateBy);
- _chk = com.SelectCommand.ExecuteNonQuery();
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "BrokerDefaultHolidaySettingAddUpdate", ex.Message);
- _chk = 0;
- }
- return _chk;
- }
- #endregion
- #region [Various Checks 2015-03-31]
- /// <summary>
- /// Check if credential email has already sent to the contact.
- /// </summary>
- /// <param name="contactId"></param>
- /// <param name="email"></param>
- /// <returns></returns>
- public bool IsCredentialMailAlreadySend(int contactId)
- {
- return ctx.tblClientRegistrations.Any(res => res.ContactId == contactId && res.Password != null);
- }
- /// <summary>
- /// Check if super admin
- /// </summary>
- /// <param name="userId"></param>
- /// <returns></returns>
- public int CheckIsSuperAdmin(int userId)
- {
- int _userTYpe = 0; // 1 - Super Admin, 2- Created Admin, 3 - Manager, 4 - Broker, 5 - General User
- try
- {
- if (ctx.tblusers.Any(u => u.userid == userId && u.active == true && (u.AdminId.HasValue == false || u.AdminId.Value == 0) && (u.administrator.HasValue == true && u.administrator.Value == true) && (u.broker.HasValue == false || u.broker.Value == false)))
- {
- _userTYpe = 1;
- }
- }
- catch(Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "CheckIsSuperAdmin", ex.Message);
- }
- return _userTYpe;
- }
- #endregion [Various Checks 2015-03-31]
- #region [Lead Product Data Duplicity Check]
- /// <summary>
- /// Added on 2015-03-14 to check lead data duplicity and lead product data transfer
- /// </summary>
- /// <param name="mortgageList"></param>
- /// <param name="lifeList"></param>
- /// <param name="buildingContentList"></param>
- /// <param name="pensionList"></param>
- /// <param name="investmentList"></param>
- /// <param name="address"></param>
- /// <returns></returns>
- public bool CheckLeadDataDuplication(List<Mortgage> mortgageList, List<Life> lifeList, List<BuildingContent> buildingContentList, List<Pensions> pensionList, List<Investment> investmentList, Address address,int? userId=0)
- {
- string msg = "";
- var dbOccfinance5572Entities = new db_occfinance_5572Entities();
- var result = false;
- var contactId = address.contactid;
- try
- {
- foreach (var contact in (from mort in mortgageList where mort.mortage_financeid > 0 select dbOccfinance5572Entities.tblfinances.Where(res => res.financeid == mort.mortage_financeid).Select(res => res.contact).FirstOrDefault()).Where(contact => contact != contactId))
- {
- ErrorLog(Convert.ToString("Data Swapping Error. Actual Contact Id : " + contactId + " New Contact Id: " + CheckDynamicVariableForNull(contact)),userId??0);
- result = true;
- break;
- }
- if (result == false)
- {
- foreach (var contact in lifeList.Where(life => life.life_financeid > 0).Select(life => dbOccfinance5572Entities.tblfinances.Where(res => res.financeid == life.life_financeid).Select(res => res.contact).FirstOrDefault()).Where(contact => contact != contactId))
- {
- ErrorLog(Convert.ToString("Data Swapping Error. Actual Contact Id : " + contactId + " New Contact Id: " + CheckDynamicVariableForNull(contact)), userId ?? 0);
- result = true;
- break;
- }
- if (result == false)
- {
- foreach (var contact in buildingContentList.Where(build => build.buildingcontent_financeid > 0).Select(build => dbOccfinance5572Entities.tblfinances.Where(res => res.financeid == build.buildingcontent_financeid).Select(res => res.contact).FirstOrDefault()).Where(contact => contact != contactId))
- {
- ErrorLog(Convert.ToString("Data Swapping Error. Actual Contact Id : " + contactId + " New Contact Id: " + CheckDynamicVariableForNull(contact)), userId ?? 0);
- result = true;
- break;
- }
- if (result == false)
- {
- foreach (var contact in pensionList.Where(pen => pen.pension_financeid > 0).Select(pen => dbOccfinance5572Entities.tblfinances.Where(res => res.financeid == pen.pension_financeid).Select(res => res.contact).FirstOrDefault()).Where(contact => contact != contactId))
- {
- ErrorLog(Convert.ToString("Data Swapping Error. Actual Contact Id : " + contactId + " New Contact Id: " + CheckDynamicVariableForNull(contact)), userId ?? 0);
- result = true;
- break;
- }
- if (result == false)
- {
- foreach (var contact in investmentList.Where(invst => invst.investment_financeid > 0).Select(invst => dbOccfinance5572Entities.tblfinances.Where(res => res.financeid == invst.investment_financeid).Select(res => res.contact).FirstOrDefault()).Where(contact => contact != contactId))
- {
- ErrorLog(Convert.ToString("Data Swapping Error. Actual Contact Id : " + contactId + " New Contact Id: " + CheckDynamicVariableForNull(contact)), userId ?? 0);
- result = true;
- break;
- }
- }
- }
- }
- }
- }
- catch(Exception ex)
- {
- ErrorLog("Exception occurred while testing duplicity of lead product data. Actual Exception : " + ex.Message);
- }
- return result;
- }
- #region [Lead Product Data Duplication Check 20150720]
- /// <summary>
- /// Check Lead Data duplication
- /// </summary>
- /// <param name="mortgageList"></param>
- /// <param name="lifeList"></param>
- /// <param name="buildingContentList"></param>
- /// <param name="pensionList"></param>
- /// <param name="investmentList"></param>
- /// <param name="address"></param>
- /// <returns></returns>
- public bool CheckLeadProductDataDuplication(List<Mortgage> mortgageList, List<Life> lifeList, List<BuildingContent> buildingContentList, List<Pensions> pensionList, List<Investment> investmentList, Address address)
- {
- var result = false;
- try
- {
- if (IsMortgageProductDataDuplicated(mortgageList))
- result = true;
- if (result == false)
- {
- if (IsLifeProductDataDuplicated(lifeList))
- result = true;
- if (result == false)
- {
- if (IsBuildingContentProductDataDuplicated(buildingContentList))
- result = true;
- if (result == false)
- {
- if (IsPensionProductDataDuplicated(pensionList))
- result = true;
- if (result == false)
- {
- if (IsInvestmentProductDataDuplicated(investmentList))
- result = true;
- }
- }
- }
- }
- }
- catch
- {
- ErrorLog("Exception occurred while testing duplicity of lead product data.");
- }
- if (result)
- ErrorLog(Convert.ToString("Data swapping error occurs between products of contact id" + address.contactid + "."));
- return result;
- }
- public bool IsMortgageProductDataDuplicated(IReadOnlyList<Mortgage> mList)
- {
- if (mList == null || mList.Count == 0) return false;
- for (var i = 0; i < mList.Count - 1; i++)
- {
- if ((mList[i].mortgage_address1 == mList[i + 1].mortgage_address1)
- && (mList[i].mortgage_address2 == mList[i + 1].mortgage_address2)
- && (mList[i].mortgage_county == mList[i + 1].mortgage_county)
- && (mList[i].mortgage_town == mList[i + 1].mortgage_town)
- && (mList[i].mortgage_postcode == mList[i + 1].mortgage_postcode)
- && (mList[i].mortage_date == mList[i + 1].mortage_date)
- && (mList[i].mortage_solicitor == mList[i + 1].mortage_solicitor)
- && (mList[i].mortage_lender == mList[i + 1].mortage_lender)
- && (mList[i].mortage_amount == mList[i + 1].mortage_amount)
- && (mList[i].mortage_commission == mList[i + 1].mortage_commission)
- && (mList[i].mortage_rate == mList[i + 1].mortage_rate)
- && (mList[i].mortgage_Clientfee == mList[i + 1].mortgage_Clientfee)
- && (mList[i].mortage_premium == mList[i + 1].mortage_premium)
- && (mList[i].mortage_deposit == mList[i + 1].mortage_deposit)
- && (mList[i].mortage_income == mList[i + 1].mortage_income)
- && (mList[i].mortage_propertyvalue == mList[i + 1].mortage_propertyvalue)
- && (mList[i].mortage_reason == mList[i + 1].mortage_reason)
- && (mList[i].mortage_rterm == mList[i + 1].mortage_rterm)
- && (mList[i].mortage_remortagedate == mList[i + 1].mortage_remortagedate)
- && (mList[i].RateType == mList[i + 1].RateType)
- && (mList[i].mortage_mortgagesubtype == mList[i + 1].mortage_mortgagesubtype))
- {
- if (!CheckIfMortgageProductsAreEmpty(mList[i], mList[i + 1]))
- {
- return true;
- }
- }
- }
- return false;
- }
- private bool CheckIfMortgageProductsAreEmpty(Mortgage mortgage1, Mortgage mortgage2)
- {
- if ((string.IsNullOrEmpty(mortgage1.mortgage_address1))
- && (string.IsNullOrEmpty(mortgage2.mortgage_address1))
- && (string.IsNullOrEmpty(mortgage1.mortgage_address2))
- && (string.IsNullOrEmpty(mortgage2.mortgage_address2))
- && (string.IsNullOrEmpty(mortgage1.mortgage_postcode))
- && (string.IsNullOrEmpty(mortgage2.mortgage_postcode))
- && (string.IsNullOrEmpty(mortgage1.mortgage_county))
- && (string.IsNullOrEmpty(mortgage2.mortgage_county))
- && (string.IsNullOrEmpty(mortgage1.mortgage_town))
- && (string.IsNullOrEmpty(mortgage2.mortgage_town))
- && (mortgage1.mortage_amount == null || mortgage1.mortage_amount == 0)
- && (mortgage2.mortage_amount == null || mortgage2.mortage_amount == 0)
- && (mortgage1.mortage_commission == null || mortgage1.mortage_commission == 0)
- && (mortgage2.mortage_commission == null || mortgage2.mortage_commission == 0)
- && (mortgage1.mortgage_Clientfee == null || mortgage1.mortgage_Clientfee == 0)
- && (mortgage2.mortgage_Clientfee == null || mortgage2.mortgage_Clientfee == 0)
- && (mortgage1.mortage_premium == null || mortgage1.mortage_premium == 0)
- && (mortgage2.mortage_premium == null || mortgage2.mortage_premium == 0)
- && (mortgage1.mortage_deposit == null || mortgage1.mortage_deposit == 0)
- && (mortgage2.mortage_deposit == null || mortgage2.mortage_deposit == 0)
- && (mortgage1.mortage_income == null || mortgage1.mortage_income == 0)
- && (mortgage2.mortage_income == null || mortgage2.mortage_income == 0))
- {
- return true;
- }
- return false;
- }
- private static bool IsLifeProductDataDuplicated(IReadOnlyList<Life> lList)
- {
- if (lList == null || lList.Count == 0) return false;
- for (var i = 0; i < lList.Count - 1; i++)
- {
- if ((lList[i].life_AppicationType == lList[i + 1].life_AppicationType)
- && (lList[i].life_financetype == lList[i + 1].life_financetype)
- && (lList[i].life_isPolicyForOtherApplicant == lList[i + 1].life_isPolicyForOtherApplicant)
- && (lList[i].life_status == lList[i + 1].life_status)
- && (lList[i].life_provider == lList[i + 1].life_provider)
- && (lList[i].life_policyref == lList[i + 1].life_policyref)
- && (lList[i].life_policytype == lList[i + 1].life_policytype)
- && (lList[i].life_amount == lList[i + 1].life_amount)
- && (lList[i].life_commission == lList[i + 1].life_commission)
- && (lList[i].life_contactid == lList[i + 1].life_contactid)
- && (lList[i].life_date == lList[i + 1].life_date)
- && (lList[i].life_datelive == lList[i + 1].life_datelive)
- && (lList[i].life_expires == lList[i + 1].life_expires)
- && (lList[i].life_Clientfee == lList[i + 1].life_Clientfee)
- && (lList[i].life_financetype == lList[i + 1].life_financetype)
- && (lList[i].life_height == lList[i + 1].life_height)
- && (lList[i].life_weight == lList[i + 1].life_weight)
- && (lList[i].life_issmoker == lList[i + 1].life_issmoker)
- && (lList[i].life_doctor == lList[i + 1].life_doctor)
- && (lList[i].life_notes == lList[i + 1].life_notes)
- && (lList[i].life_medical == lList[i + 1].life_medical))
- {
- if (!CheckIfLifeProductsAreEmpty(lList[i], lList[i + 1]))
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// Check If life Products are emply
- /// </summary>
- /// <param name="life1"></param>
- /// <param name="life2"></param>
- /// <returns></returns>
- private static bool CheckIfLifeProductsAreEmpty(Life life1, Life life2)
- {
- if ((life1.life_amount == null || life1.life_amount == 0)
- && (life2.life_amount == null || life2.life_amount == 0)
- && (life1.life_commission == null || life1.life_commission == 0)
- && (life2.life_commission == null || life2.life_commission == 0)
- && (life1.life_Clientfee == null || life1.life_Clientfee == 0)
- && (life2.life_Clientfee == null || life2.life_Clientfee == 0)
- )
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// Check If the building products are duplicated
- /// </summary>
- /// <param name="bcList"></param>
- /// <returns></returns>
- private static bool IsBuildingContentProductDataDuplicated(IReadOnlyList<BuildingContent> bcList)
- {
- if (bcList == null || bcList.Count == 0) return false;
- for (var i = 0; i < bcList.Count - 1; i++)
- {
- if ((bcList[i].buildingcontent_status == bcList[i + 1].buildingcontent_status)
- && (bcList[i].buildingcontent_financetype == bcList[i + 1].buildingcontent_financetype)
- && (bcList[i].buildingcontent_isPolicyForOtherApplicant == bcList[i + 1].buildingcontent_isPolicyForOtherApplicant)
- && (bcList[i].buildingcontent_provider == bcList[i + 1].buildingcontent_provider)
- && (bcList[i].buildingcontent_policyref == bcList[i + 1].buildingcontent_policyref)
- && (bcList[i].buildingcontent_amount == bcList[i + 1].buildingcontent_amount)
- && (bcList[i].buildingcontent_commission == bcList[i + 1].buildingcontent_commission)
- && (bcList[i].buildingcontent_type == bcList[i + 1].buildingcontent_type)
- && (bcList[i].buildingcontent_premium == bcList[i + 1].buildingcontent_premium)
- && (bcList[i].buildingcontent_rebuildvalue == bcList[i + 1].buildingcontent_rebuildvalue)
- && (bcList[i].buildingcontent_isalarmed == bcList[i + 1].buildingcontent_isalarmed)
- && (bcList[i].buildingcontent_addcover == bcList[i + 1].buildingcontent_addcover)
- && (bcList[i].buildingcontent_datelive == bcList[i + 1].buildingcontent_datelive)
- && (bcList[i].buildingcontent_expires == bcList[i + 1].buildingcontent_expires)
- && (bcList[i].buildingcontent_followup == bcList[i + 1].buildingcontent_followup)
- && (bcList[i].buildingcontent_date == bcList[i + 1].buildingcontent_date)
- && (bcList[i].buildingcontent_time == bcList[i + 1].buildingcontent_time)
- && (bcList[i].buildingcontent_notes == bcList[i + 1].buildingcontent_notes)
- && (bcList[i].buildingContent_contactid == bcList[i + 1].buildingContent_contactid)
- && (bcList[i].buildingContent_AppicationType == bcList[i + 1].buildingContent_AppicationType)
- && (bcList[i].building_Clientfee == bcList[i + 1].building_Clientfee))
- {
- if (!CheckIfBuildingsProductsAreEmpty(bcList[i], bcList[i + 1]))
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// Checking if the building products are empty
- /// </summary>
- /// <param name="buildingContent1"></param>
- /// <param name="buildingContent2"></param>
- /// <returns></returns>
- private static bool CheckIfBuildingsProductsAreEmpty(BuildingContent buildingContent1, BuildingContent buildingContent2)
- {
- if ((buildingContent1.buildingcontent_amount == null || buildingContent1.buildingcontent_amount == 0)
- && (buildingContent2.buildingcontent_amount == null || buildingContent2.buildingcontent_amount == 0)
- && (buildingContent1.building_Clientfee == null || buildingContent1.building_Clientfee == 0)
- && (buildingContent2.building_Clientfee == null || buildingContent2.building_Clientfee == 0)
- && (buildingContent1.buildingcontent_commission == null || buildingContent1.buildingcontent_commission == 0)
- && (buildingContent2.buildingcontent_commission == null || buildingContent2.buildingcontent_commission == 0)
- && (buildingContent1.buildingcontent_premium == null || buildingContent1.buildingcontent_premium == 0)
- && (buildingContent2.buildingcontent_premium == null || buildingContent2.buildingcontent_premium == 0)
- )
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// Checking if the pension product data are dupllicated
- /// </summary>
- /// <param name="pList"></param>
- /// <returns></returns>
- private static bool IsPensionProductDataDuplicated(IReadOnlyList<Pensions> pList)
- {
- if (pList == null || pList.Count == 0) return false;
- for (var i = 0; i < pList.Count - 1; i++)
- {
- if ((pList[i].pension_status == pList[i + 1].pension_status)
- && (pList[i].pension_financetype == pList[i + 1].pension_financetype)
- && (pList[i].pension_isPolicyForOtherApplicant == pList[i + 1].pension_isPolicyForOtherApplicant)
- && (pList[i].pension_provider == pList[i + 1].pension_provider)
- && (pList[i].pension_policyref == pList[i + 1].pension_policyref)
- && (pList[i].pension_amount == pList[i + 1].pension_amount)
- && (pList[i].pension_commission == pList[i + 1].pension_commission)
- && (pList[i].pension_riskprofile == pList[i + 1].pension_riskprofile)
- && (pList[i].pension_riskprofile == pList[i + 1].pension_riskprofile)
- && (pList[i].pension_contributors == pList[i + 1].pension_contributors)
- && (pList[i].pension_fundvalue == pList[i + 1].pension_fundvalue)
- && (pList[i].pension_incomereq == pList[i + 1].pension_incomereq)
- && (pList[i].pension_datelive == pList[i + 1].pension_datelive)
- && (pList[i].pension_expires == pList[i + 1].pension_expires)
- && (pList[i].pension_followup == pList[i + 1].pension_followup)
- && (pList[i].pension_date == pList[i + 1].pension_date)
- && (pList[i].pension_time == pList[i + 1].pension_time)
- && (pList[i].pension_notes == pList[i + 1].pension_notes)
- // && (pList[i].pension_Name == pList[i + 1].pension_Name)
- && (pList[i].pension_contactid == pList[i + 1].pension_contactid)
- && (pList[i].pension_AppicationType == pList[i + 1].pension_AppicationType)
- && (pList[i].pension_Clientfee == pList[i + 1].pension_Clientfee))
- {
- if (!CheckIfPensionProductsAreEmpty(pList[i], pList[i + 1]))
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// Checking if the pension product are empty
- /// </summary>
- /// <param name="pensions1"></param>
- /// <param name="pensions2"></param>
- /// <returns></returns>
- private static bool CheckIfPensionProductsAreEmpty(Pensions pensions1, Pensions pensions2)
- {
- if (
- (pensions1.pension_amount == null || pensions1.pension_amount == 0)
- && (pensions2.pension_amount == null || pensions2.pension_amount == 0)
- && (pensions1.pension_Clientfee == null || pensions1.pension_Clientfee == 0)
- && (pensions2.pension_Clientfee == null || pensions2.pension_Clientfee == 0)
- && (pensions1.pension_commission == null || pensions1.pension_commission == 0)
- && (pensions2.pension_commission == null || pensions2.pension_commission == 0)
- && (pensions1.pension_fundvalue == null || pensions1.pension_fundvalue == 0)
- && (pensions2.pension_fundvalue == null || pensions2.pension_fundvalue == 0)
- )
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// Checking is the Investment Prodct are dupliated
- /// </summary>
- /// <param name="iList"></param>
- /// <returns></returns>
- private static bool IsInvestmentProductDataDuplicated(IReadOnlyList<Investment> iList)
- {
- if (iList == null || iList.Count == 0) return false;
- for (var i = 0; i < iList.Count - 1; i++)
- {
- if ((iList[i].investment_isPolicyForOtherApplicant == iList[i + 1].investment_isPolicyForOtherApplicant)
- && (iList[i].investment_financetype == iList[i + 1].investment_financetype)
- && (iList[i].investment_status == iList[i + 1].investment_status)
- && (iList[i].investment_provider == iList[i + 1].investment_provider)
- && (iList[i].investment_policyref == iList[i + 1].investment_policyref)
- && (iList[i].investment_amount == iList[i + 1].investment_amount)
- && (iList[i].investment_commission == iList[i + 1].investment_commission)
- && (iList[i].investment_riskprofiles == iList[i + 1].investment_riskprofiles)
- && (iList[i].investment_contributors == iList[i + 1].investment_contributors)
- && (iList[i].investment_fundvalue == iList[i + 1].investment_fundvalue)
- && (iList[i].investment_datelive == iList[i + 1].investment_datelive)
- && (iList[i].investment_expires == iList[i + 1].investment_expires)
- && (iList[i].investment_followup == iList[i + 1].investment_followup)
- && (iList[i].investment_date == iList[i + 1].investment_date)
- && (iList[i].investment_time == iList[i + 1].investment_time)
- && (iList[i].investment_notes == iList[i + 1].investment_notes)
- // && (iList[i].Investment_Name == iList[i + 1].Investment_Name)
- && (iList[i].investment_contactid == iList[i + 1].investment_contactid)
- && (iList[i].investment_AppicationType == iList[i + 1].investment_AppicationType)
- && (iList[i].investment_Clientfee == iList[i + 1].investment_Clientfee))
- {
- if (!CheckIfInvestmentProductsAreEmpty(iList[i], iList[i + 1]))
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// Check if the Investment Products are emply
- /// </summary>
- /// <param name="investment1"></param>
- /// <param name="investment2"></param>
- /// <returns></returns>
- private static bool CheckIfInvestmentProductsAreEmpty(Investment investment1, Investment investment2)
- {
- if ((investment1.investment_amount == null || investment1.investment_amount == 0)
- && (investment2.investment_amount == null || investment2.investment_amount == 0)
- && (investment1.investment_commission == null || investment1.investment_commission == 0)
- && (investment2.investment_commission == null || investment2.investment_commission == 0)
- && (investment1.investment_fundvalue == null || investment1.investment_fundvalue == 0)
- && (investment2.investment_fundvalue == null || investment2.investment_fundvalue == 0)
- && (investment1.investment_Clientfee == null || investment1.investment_Clientfee == 0)
- && (investment2.investment_Clientfee == null || investment2.investment_Clientfee == 0)
- )
- {
- return true;
- }
- return false;
- }
- #endregion [Lead Product Data Duplication Check 20150720]
- public static int CheckDynamicVariableForNull(dynamic value)
- {
- if (value != null)
- return value;
- else
- return 0;
- }
- /// <summary>
- /// Enter errors in error log table.
- /// </summary>
- /// <param name="inEx"></param>
- public void ErrorLog(string inEx,int? userId=0)
- {
- var dbOccfinance5572Entities = new db_occfinance_5572Entities();
- string _Name = "", _EmailId = "";
- int _AddBy =0;
- if (HttpContext.Current.Session != null)
- {
- _Name = Convert.ToString(HttpContext.Current.Session["ContactName"] ?? "");
- _AddBy = Convert.ToInt32(HttpContext.Current.Session["LoggedInUserId"] ?? "0");
- _EmailId = Convert.ToString(HttpContext.Current.Session["ContactEmail"] ?? "");
- }
- else
- {
- _AddBy =userId??0;
- }
- var errlg = new tblErrorLog
- {
- Action = "CheckLeadDataDuplication",
- AddBy = _AddBy,
- AddDate = DateTime.Now,
- Controller = "AppTrack Controller",
- EmailId = _EmailId,
- ErrorDate = DateTime.Now,
- HelpLink = "Data Duplicity Error on Application page",
- InnerMsg = inEx,
- IsActive = true,
- IsDeleted = false,
- IsResolved = false,
- Message = inEx,
- Name = _Name,
- Source = inEx,
- Trace = inEx,
- URL = "Data Duplicity Error on Application Page"
- };
- dbOccfinance5572Entities.tblErrorLog.Add(errlg);
- dbOccfinance5572Entities.SaveChanges();
- }
- #endregion [Lead Data Duplicity Check]
- #region [Delete Leads 2015-03-19]
- /// <summary>
- /// Delete lead records
- /// </summary>
- /// <param name="financeId"></param>
- /// <returns></returns>
- public bool DeleteLeads(int financeId)
- {
- bool result = false;
- var lead = ctx.tblfinances.Where(res => res.financeid == financeId).FirstOrDefault();
- if (lead != null)
- {
- if (lead.type == 1)
- {
- lead.status = 34;
- result = true;
- }
- if (lead.type == 2)
- {
- lead.status = 35;
- result = true;
- }
- if (lead.type == 3)
- {
- lead.status = 36;
- result = true;
- }
- if (lead.type == 4)
- {
- lead.status = 37;
- result = true;
- }
- if (lead.status == 5)
- {
- lead.status = 38;
- result = true;
- }
- ctx.SaveChanges();
- }
- return result;
- }
- #endregion [Delete Leads 2015-03-19]
- #region [Display Address and Lender Details 2015-03-20]
- public enum ProductType
- {
- Mortgage = 1,
- Life = 2,
- Building = 3,
- Pension = 4,
- Investment = 5
- }
- public enum LifePolicyType
- {
- LifeInsurance = 1,
- CriticalIllness = 2,
- IncomeProtection = 3
- }
- public enum BuildingPolicyType
- {
- House = 1,
- Flat = 2
- }
- public enum PensionPolicyType
- {
- High = 1,
- Medium = 2,
- Low = 3
- }
- public enum InvestmentPolicyType
- {
- High = 1,
- Medium = 2,
- Low = 3
- }
- /// <summary>
- /// Display address and lender details
- /// </summary>
- /// <param name="financeId"></param>
- /// <returns></returns>
- public string DisplayAddressAndLender(int financeId)
- {
- try
- {
- string firstSection = string.Empty;
- string secondSection = string.Empty;
- var product = (from con in ctx.tblcontacts
- join fin in ctx.tblfinances on con.contactid equals fin.contact
- where fin.financeid == financeId
- select new
- {
- fin.type,
- fin.Address1,
- fin.provider,
- fin.Address2,
- fin.subtype
- }).FirstOrDefault();
- //Set second section
- if (product.provider != null && product.provider != "")
- {
- secondSection = product.provider.StringToLength(15);
- }
- else
- {
- secondSection = "N/A";
- }
- //Set first section
- if (product.type == (int)ProductType.Mortgage)
- {
- if ((product.Address1 != null && product.Address1 != ""))
- {
- firstSection = product.Address1.StringToLength(22);
- }
- else
- {
- firstSection = "N/A";
- }
- }
- else if (product.type == (int)ProductType.Life)
- {
- if (product.subtype == (int)LifePolicyType.CriticalIllness)
- {
- firstSection = LifePolicyType.CriticalIllness.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)LifePolicyType.IncomeProtection)
- {
- firstSection = LifePolicyType.IncomeProtection.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)LifePolicyType.LifeInsurance)
- {
- firstSection = LifePolicyType.LifeInsurance.ToString().StringToLength(14);
- }
- else
- {
- firstSection = "N/A";
- }
- }
- else if (product.type == (int)ProductType.Building)
- {
- if (product.subtype == (int)BuildingPolicyType.Flat)
- {
- firstSection = BuildingPolicyType.Flat.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)BuildingPolicyType.House)
- {
- firstSection = BuildingPolicyType.House.ToString().StringToLength(14);
- }
- else
- {
- firstSection = "N/A";
- }
- }
- else if (product.type == (int)ProductType.Pension)
- {
- if (product.subtype == (int)PensionPolicyType.High)
- {
- firstSection = PensionPolicyType.High.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)PensionPolicyType.Low)
- {
- firstSection = PensionPolicyType.Low.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)PensionPolicyType.Medium)
- {
- firstSection = PensionPolicyType.Medium.ToString().StringToLength(14);
- }
- else
- {
- firstSection = "N/A";
- }
- }
- else if (product.type == (int)ProductType.Investment)
- {
- if (product.subtype == (int)InvestmentPolicyType.High)
- {
- firstSection = InvestmentPolicyType.High.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)InvestmentPolicyType.Low)
- {
- firstSection = InvestmentPolicyType.Low.ToString().StringToLength(14);
- }
- else if (product.subtype == (int)InvestmentPolicyType.Medium)
- {
- firstSection = InvestmentPolicyType.Medium.ToString().StringToLength(14);
- }
- else
- {
- firstSection = "N/A";
- }
- }
- return (", " + firstSection + ", " + secondSection);
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetUserName", ex.Message, ex.Source, ex.StackTrace, ex.HelpLink);
- return string.Empty;
- }
- }
- #endregion [Display Address and Lender Details 2015-03-20]
- #region [Delete All Product of Lead 2015-04-10]
- public int DeleteLeadProducts(int contactId)
- {
- int result = 0;
- try
- {
- var lead = ctx.tblcontacts.Where(x => x.contactid == contactId).FirstOrDefault();
- var leadMortgage = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 1).ToList();
- var leadLife = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 2).ToList();
- var leadBuilding = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 3).ToList();
- var leadPension = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 4).ToList();
- var leadInvestment = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 5).ToList();
- if (lead != null)
- {
- lead.IsDeleted = true;
- lead.modified = System.DateTime.Now;
- }
- foreach (var productMortgage in leadMortgage)
- {
- productMortgage.status = 34;
- productMortgage.updated = System.DateTime.Now;
- }
- foreach (var productLife in leadLife)
- {
- productLife.status = 35;
- productLife.updated = System.DateTime.Now;
- }
- foreach (var productbuildng in leadBuilding)
- {
- productbuildng.status = 36;
- productbuildng.updated = System.DateTime.Now;
- }
- foreach (var productPolicy in leadPension)
- {
- productPolicy.status = 37;
- productPolicy.updated = System.DateTime.Now;
- }
- foreach (var productInvstmnt in leadInvestment)
- {
- productInvstmnt.status = 38;
- productInvstmnt.updated = System.DateTime.Now;
- }
- result = ctx.SaveChanges();
- }
- catch
- {
- }
- return result;
- }
- #endregion [Delete All Product of Lead 2015-04-10]
- #region [Get All Contacts for Referring Client 2015]
- public List<Clients> GetAllContact()
- {
- List<Clients> list = new List<Clients>();
- list = ctx.tblcontacts.Where(x => (x.IsDeleted ?? false) == false && (x.firstname != null || x.lastname != null)).OrderBy(x => x.firstname).ThenBy(x => x.lastname).Select(x => new Clients { contactId = x.contactid, contactname = (x.firstname ?? "") + " " + (x.lastname ?? ""), email = x.email, telephone = x.telephone }).ToList();
- return list;
- }
- #endregion[Get All Contacts for Referring Client 2015]
- #region [Get All Contacts for Referring Client in report 2015]
- public List<Clients> GetAllContactForReport()
- {
- //1583028 is the account id of client Referral Account
- var ReferrerList = ctx.tblcontacts.Where(x => x.parentContactId != null && x.parentContactId != 0 && x.account != 1582971 && x.account == 1583028 && (x.IsDeleted ?? false) == false).Select(x => x.parentContactId).Distinct().ToList();
- var ReferrerList1 = ctx.tblcontacts.Where(x => x.parentNegId != null && x.parentNegId != 0 && x.account != 1582971 && x.account == 1583028 && (x.IsDeleted ?? false) == false).Select(x => x.parentNegId).Distinct().ToList();
- List<Clients> list = new List<Clients>();
- List<Clients> list1 = new List<Clients>();
- list = ctx.tblcontacts.Where(x => (ReferrerList.Contains(x.contactid)) && x.account != 1582971).OrderBy(x => x.firstname).ThenBy(x => x.lastname).ToList().Select(x => new Clients { affiliateid = x.contactid.ToString(), contactname = (x.firstname ?? "") + " " + (x.lastname ?? ""), email = x.email, telephone = x.telephone }).ToList();
- list1 = ctx.tblClientReferralNeg.Where(x => (ReferrerList1.Contains(x.NegId))).ToList().Select(x => new Clients { affiliateid = (x.NegId.ToString() + "_neg"), contactname = x.NegName }).ToList();
- var list2 = list.Concat(list1).ToList();
- return list2;
- }
- #endregion[Get All Contacts for Referring Client in report 2015]
- public bool NewLifeProduct(int contactId, int userId)
- {
- var result = false;
- try
- {
- bool IsLifeProductExist = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 2 && x.status != 35).Any();
- if (!IsLifeProductExist)
- {
- var _chkLifeupdate = true;
- tblfinance newfinance = new tblfinance();
- newfinance.contact = contactId;
- newfinance.type = (int)FinanceTypes.Life;
- newfinance.status = 10;
- newfinance.subtype = 0;
- newfinance.policyreference = null;
- newfinance.followup = Helper.GetFollowUp(null, null == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : null);
- newfinance.provider = null;
- newfinance.amount = null;
- newfinance.premium = null;
- newfinance.commission = null;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(null);
- newfinance.dateexpire = Helper.GetDate(null);
- newfinance.created = System.DateTime.Now;
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = null;
- //********************************
- newfinance.isPolicyForOtherApplicant = false;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_insurance newfinance_insurance = new tblfinance_insurance();
- newfinance_insurance.smoker = false;
- newfinance_insurance.height = null;
- newfinance_insurance.weight = null;
- newfinance_insurance.doctor = null;
- ctx.tblfinance_insurance.Add(newfinance_insurance);
- if (_chkLifeupdate)
- {
- tblnote lifenoteforstatus = new tblnote();
- lifenoteforstatus.financeid = newfinance.financeid;
- lifenoteforstatus.contact = contactId;
- lifenoteforstatus.note = string.Format("Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == 10).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userId).Select(x => x.brokername).FirstOrDefault());
- lifenoteforstatus.created = System.DateTime.Now;
- lifenoteforstatus.UserId = userId;
- ctx.tblnotes.Add(lifenoteforstatus);
- }
- ctx.SaveChanges();
- result = true;
- }
- else
- {
- result = true;
- }
- }
- catch
- {
- }
- return result;
- }
- public bool NewBuildingProduct(int contactId, int userId)
- {
- var result = false;
- try
- {
- bool IsBuildingProductExist = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 3).Any();
- bool IsPensionProductExist = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 4).Any();
- bool IsInvestmentProductExist = ctx.tblfinances.Where(x => x.contact == contactId && x.type == 5).Any();
- if (!IsBuildingProductExist)
- {
- tblfinance newfinance = new tblfinance();
- newfinance.contact = contactId;
- newfinance.type = (int)FinanceTypes.BuildingsOrContents;
- newfinance.status = 16;
- newfinance.subtype = 0;
- newfinance.policyreference = null;
- newfinance.followup = Helper.GetFollowUp(null, null == null ? (DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second).ToString() : null);
- newfinance.provider = null;
- newfinance.amount = null;
- newfinance.premium = null;
- newfinance.commission = null;
- newfinance.details = null;
- newfinance.updated = System.DateTime.Now;
- newfinance.created = System.DateTime.Now;
- newfinance.datelive = Helper.GetDate(null);
- newfinance.dateexpire = Helper.GetDate(null);
- //Added Client Fee 27-10-2014
- newfinance.ClientFee = null;
- //********************************
- newfinance.isPolicyForOtherApplicant = false;
- ctx.tblfinances.Add(newfinance);
- //insert
- tblfinance_buildings newfinance_building = new tblfinance_buildings();
- newfinance_building.rebuild = null;
- newfinance_building.alarm = false;
- ctx.tblfinance_buildings.Add(newfinance_building);
- //insert note
- tblnote buildingcontentnoteforstatus = new tblnote();
- //buildingcontentnoteforstatus.noteid = _noteid;
- buildingcontentnoteforstatus.financeid = newfinance.financeid;
- buildingcontentnoteforstatus.contact = contactId;
- buildingcontentnoteforstatus.note = string.Format("Initial status is set as {0} on {1} at {2} by {3}", ctx.tblfinancestatus.Where(x => x.statusid == 16).Select(x => x.name).FirstOrDefault(), System.DateTime.Now.ToString("dd/MM/yyyy"), System.DateTime.Now.ToString("HH:mm"), ctx.tblusers.Where(x => x.userid == userId).Select(x => x.brokername).FirstOrDefault());
- buildingcontentnoteforstatus.created = System.DateTime.Now;
- buildingcontentnoteforstatus.UserId = userId;
- ctx.tblnotes.Add(buildingcontentnoteforstatus);
- ctx.SaveChanges();
- result = true;
- }
- else
- {
- result = true;
- }
- }
- catch
- {
- }
- return result;
- }
- #region [Adding Negotiator in Client Referral Negotiator table]
- public int AddNeg(string Neg)
- {
- int Id = 0;
- try
- {
- var IsAlready = ctx.tblClientReferralNeg.Where(x => x.NegName.Trim().ToUpper() == Neg.Trim().ToUpper()).FirstOrDefault();
- if (IsAlready == null)
- {
- tblClientReferralNeg obj = new tblClientReferralNeg();
- obj.NegName = Neg.Trim();
- obj.CreatedDate = DateTime.Now;
- ctx.tblClientReferralNeg.Add(obj);
- ctx.SaveChanges();
- Id = obj.NegId;
- }
- else
- {
- Id = IsAlready.NegId;
- }
- return Id;
- }
- catch
- {
- return Id;
- }
- }
- #endregion
- public int SaveBasicIntellicalcDetails(string com, string con, string tel, string email)
- {
- int Id = 0;
- try
- {
- SqlParameter[] Param = new SqlParameter[5];
- Param[0] = new SqlParameter("@CompanyName", com);
- Param[1] = new SqlParameter("@ContactName", con);
- Param[2] = new SqlParameter("@Email", email);
- Param[3] = new SqlParameter("@Telephone", tel);
- SqlParameter id = new SqlParameter();
- id.SqlDbType = SqlDbType.Int;
- id.Direction = ParameterDirection.Output;
- id.ParameterName = "@new_identity";
- Param[4] = id;
- string _procedurename = "IntellicalcBasicDetailsAdd";
- SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, _procedurename, Param);
- Id = Convert.ToInt32(Param[4].Value);
- }
- catch
- {
- }
- return Id;
- }
- #region [Main Lead Report Updated Procedures 2015-11-06]
- /// <summary>
- /// Method for Brroker Lead Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Broker List</returns>
- public List<BrokerLeadTable> GetBrokerLeadReportByIds(string Conditions, int accountid, string Conditions1 = "", string dateFilter = "")
- {
- List<BrokerLeadTable> BrokerLeadTableList = new List<BrokerLeadTable>();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- Param[2] = new SqlParameter("@DateFilter", dateFilter);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetAllBrokerReport_Update", Param);
- BrokerLeadTableList = (from DataRow row in dt.Rows
- select new BrokerLeadTable
- {
- Brokerid = Convert.ToInt32(row["brokerid"]),
- BrokerName = Convert.ToString(row["broker"]),
- LeadPercent = "0",
- NoOfLeads = Convert.ToInt32(row["TotalCount"].ToString()),
- OfferQualification = Convert.ToInt32(((row["offerqualified"] == DBNull.Value || row["offerqualified"] == null) ? " " : row["offerqualified"]).ToString())
- }).ToList();
- return BrokerLeadTableList.OrderByDescending(x => x.NoOfLeads).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplication", "GetBrokerLeadReport", ex.Message);
- return BrokerLeadTableList.ToList();
- }
- }
- /// <summary>
- /// Method for Agent Lead Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="isNeg">Negotiator</param>
- /// <param name="Condition1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Agent List</returns>
- public List<AgentLeadTable> GetAfflicateLeadReportByIds(string Conditions, int accountid, bool isNeg, string Condition1 = "", string dateFilter = "")
- {
- List<AgentLeadTable> AgentLeadList = new List<AgentLeadTable>();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@conditions", Conditions);
- if (!string.IsNullOrEmpty(Condition1))
- Param[1] = new SqlParameter("@conditions1", Condition1);
- Param[2] = new SqlParameter("@DateFilter", dateFilter);
- string _procName = "GetAllAfflicateReport_Update";
- //Check For Is Negotiation When the negotiator selected the below procedure will be selected elase the old
- if (isNeg)
- _procName = "GetAllAfflicateReport_Neg_Update";
- //****************************************
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- AgentLeadList = (from DataRow row in dt.Rows
- select new AgentLeadTable
- {
- AgentId = Convert.ToInt32(((row["account"] == DBNull.Value || row["account"] == null) ? " " : row["account"]).ToString()),
- AgentName = ((row["agentname"] == DBNull.Value || row["agentname"] == null) ? " " : row["agentname"]).ToString(),
- LeadPercent = "0",
- NoOfLeads = Convert.ToInt32(((row["TotalCount"] == DBNull.Value || row["TotalCount"] == null) ? " " : row["TotalCount"]).ToString()),
- NegName = (isNeg == true ? ((row["negref"] == DBNull.Value || row["negref"] == null) ? " " : row["negref"]).ToString() : ""),
- OfferQualification = Convert.ToInt32(((row["offerqualified"] == DBNull.Value || row["offerqualified"] == null) ? " " : row["offerqualified"]).ToString()),
- }).ToList();
- return AgentLeadList.OrderByDescending(x => x.NoOfLeads).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplication", "GetAfflicateLeadReport_Update", ex.Message);
- return AgentLeadList.ToList();
- }
- }
- /// <summary>
- /// Method for Agent Lead Report with Branch
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="isBranch">Branch</param>
- /// <param name="Condition1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns></returns>
- public List<AgentLeadTableBranch> GetAfflicateLeadReport_BranchByIds(string Conditions, int accountid, bool isBranch, string Condition1 = "", string dateFilter = "")
- {
- List<AgentLeadTableBranch> AgentLeadBranchList = new List<AgentLeadTableBranch>();
- try
- {
- SqlParameter[] Param = new SqlParameter[3];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Condition1);
- Param[2] = new SqlParameter("@DateFilter", dateFilter);
- string _procName = "GetAllAfflicateReport_NullBranch";
- //Check For Is Negotiation When the negotiator selected the below procedure will be selected elase the old
- if (isBranch)
- _procName = "GetAllAfflicateReport_Branch_Update";
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, _procName, Param);
- AgentLeadBranchList = (from DataRow row in dt.Rows
- select new AgentLeadTableBranch
- {
- AgentId = Convert.ToInt32(((row["account"] == DBNull.Value || row["account"] == null) ? " " : row["account"]).ToString()),
- AgentName = ((row["agentname"] == DBNull.Value || row["agentname"] == null) ? " " : row["agentname"]).ToString(), //GetAgentName(Convert.ToInt32(row["account"])),
- LeadPercent = "0",
- NoOfLeads = Convert.ToInt32(((row["TotalCount"] == DBNull.Value || row["TotalCount"] == null) ? " " : row["TotalCount"]).ToString()),
- Branch = (isBranch == true ? ((row["branch"] == DBNull.Value || row["branch"] == null) ? " " : row["branch"]).ToString() : ""),
- OfferQualification = Convert.ToInt32(((row["offerqualified"] == DBNull.Value || row["offerqualified"] == null) ? " " : row["offerqualified"]).ToString()),
- }).ToList();
- return AgentLeadBranchList.OrderByDescending(x => x.NoOfLeads).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Qapplication", "GetafflicateLeadReportBanch_Update", ex.Message);
- return AgentLeadBranchList;
- }
- }
- /// <summary>
- /// Method for product Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for product report</param>
- /// <param name="accountid">Account Id</param>
- /// <param name="fromdate">From Date</param>
- /// <param name="todate">To Date</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Roduct List</returns>
- public List<ProductReport> GetProductReportByIds(string Conditions, int accountid, DateTime? fromdate, DateTime? todate, string Conditions1 = "")
- {
- List<ProductReport> ProductReportList = new List<ProductReport>();
- try
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetProductReport_Update", Param);
- ProductReportList = (from DataRow row in dt.Rows
- select new ProductReport
- {
- Product = GetFinanceTableData(row["type"].ToString()).type,
- NoOfLeads = Convert.ToInt32(row["TotalLeads"]),
- InProgress = GetFinanceTableData(row["type"].ToString(), (int)MortgageStatus.NewLead, fromdate, todate),
- Complete = GetFinanceTableData(row["type"].ToString(), (int)MortgageStatus.Completed, fromdate, todate),
- TotalCommission = row["TotalCommission"].ToString() != "" ? Math.Round(Convert.ToDecimal(row["TotalCommission"].ToString()), 2).ToString() : "0",
- AvgCommission = row["AvgCommission"].ToString() != "" ? Math.Round(Convert.ToDecimal(row["AvgCommission"].ToString()), 2).ToString() : "0",
- }).ToList();
- return ProductReportList.OrderByDescending(x => x.AvgCommission).ToList();
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "Q_Application", "GetProductReport_Update", ex.Message);
- }
- return ProductReportList;
- }
- /// <summary>
- /// Method for status Report in the Main Report
- /// </summary>
- /// <param name="Conditions">Dynamic query for product report</param>
- /// <param name="accountid">Accout Id</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <param name="dateFilter">Dynamic Date filter condition</param>
- /// <returns>Status report List</returns>
- public List<statusReport> GetStatusReportByIds(string Conditions, int accountid, string Conditions1 = "")
- {
- List<statusReport> StatusReportList = new List<statusReport>();
- try
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "GetStatusReport_Update", Param);
- StatusReportList = (from DataRow row in dt.Rows
- select new statusReport
- {
- status = row["StatusName"].ToString(),
- NoOfLeads = Convert.ToInt32(row["TotalLeads"]),
- }).ToList();
- return StatusReportList;
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplication", "GetStatusRepot", ex.Message);
- return StatusReportList;
- }
- }
- /// <summary>
- /// Method for date for main report chart
- /// </summary>
- /// <param name="Conditions">Dynamic query for main report</param>
- /// <param name="accountid">Accoutnt Id</param>
- /// <param name="Conditions1">Dynamic query for main report for link mortgage to insurance functionality</param>
- /// <returns>MAin Report Chart Data</returns>
- public List<ReportDataPoint> GetLeadReportByIds(string Conditions, int accountid, string Conditions1 = "")
- {
- List<ReportDataPoint> ReportdataList = new List<ReportDataPoint>();
- try
- {
- SqlParameter[] Param = new SqlParameter[2];
- Param[0] = new SqlParameter("@conditions", Conditions);
- Param[1] = new SqlParameter("@conditions1", Conditions1);
- DataTable dt = SqlHelper.ExecuteDatatable(CommandType.StoredProcedure, "LeadReport_Update", Param);
- ReportdataList = (from DataRow row in dt.Rows
- select new ReportDataPoint
- {
- Dated = row.IsNull("created") ? DateTime.MinValue : DateTime.Parse(row["created"].ToString()),
- Value = Convert.ToInt32(row["TotalCount"]),
- }).ToList();
- return ReportdataList;
- }
- catch (Exception ex)
- {
- Helper.ErrorLog(ex.InnerException, "QApplicaition", "GetLeadreport", ex.Message);
- return ReportdataList;
- }
- }
- #endregion [Main Lead Report Updated Procedures 2015-11-06]
- }
Add Comment
Please, Sign In to add comment