diff --git a/CRM.Visitors/Managers/VisitorManager.Async.cs b/CRM.Visitors/Managers/VisitorManager.Async.cs index 77eebc2..118fc2d 100644 --- a/CRM.Visitors/Managers/VisitorManager.Async.cs +++ b/CRM.Visitors/Managers/VisitorManager.Async.cs @@ -87,15 +87,20 @@ namespace Bizgaze.CRM.Visitors.Managers } #endregion #region Getting data By VisitorId - public async Task GetVisitordataByIdAsync(SelectRequest request, long VisitorId) + public async Task GetVisitordataByIdAsync(SelectRequest request, long VisitorId) { var exp = request.Filter(); exp = exp & Unibase.Data.Expressions.Exp.Eq(Infos.Visitor.Property.VisitorId.ToString(), VisitorId); request.Filter(exp); - //var sql = "select c.cityname, e.contactname,* from bizgazecrm_visitors v inner join bizgazecrm_contacts e on e.contactid = v.employeeid inner join bizgazecrm_cities c on c.cityid = v.cityid where visitorid=" + VisitorId; - var sql = "select d.visitorid,d.fullname,d.code,(d.checkindate|| ' & ' ||d.checkintime) as datetime,d.cityname,d.contactname,Case when d.purposeofvisit=1 then 'Interview' when d.purposeofvisit=2 then 'Official Meeting' when d.purposeofvisit=3 then 'Meeting an Employee' when d.purposeofvisit=4 then 'Package Delivery' when d.purposeofvisit=5 then 'Others' end as purposeofvisittype,d.photourl from (select v.visitorid,v.fullname,v.code,v.photourl, TO_CHAR(v.checkindate, 'DD/MM/YYYY') as checkindate, UPPER(TO_CHAR(v.checkindate, 'HH:MI:SS AM')) AS checkintime,v.purposeofvisit,c.cityname, e.contactname from bizgazecrm_visitors v inner join bizgazecrm_contacts e on e.contactid = v.employeeid inner join bizgazecrm_cities c on c.cityid = v.cityid)d where visitorid = " + VisitorId; - var dt = await _dbContext.GetTableAsync(GetConnectionAsync(request), sql, Unibase.Data.Enums.InstructionType.Query, null); - var tabledata = Unibase.Core.Helpers.JsonHelper.ToJson(dt); + var select = "select code from bizgazecrm_visitors where visitorid=" + VisitorId; + var dt = await _dbContext.GetTableAsync(GetConnectionAsync(request), select, Unibase.Data.Enums.InstructionType.Query, null); + var code = dt.Rows[0]["code"].ToString(); + var select1 = "select visitorid from bizgazecrm_visitors where code='" + code + "' order by createddate desc"; + var dt1 = await _dbContext.GetTableAsync(GetConnectionAsync(request), select1, Unibase.Data.Enums.InstructionType.Query, null); + var id = Convert.ToInt64(dt1.Rows[0]["visitorid"]); + var sql = "select d.fullname,d.code,(d.checkindate|| ' & ' ||d.checkintime) as datetime,d.cityname,d.contactname,Case when d.purposeofvisit=1 then 'Interview' when d.purposeofvisit=2 then 'Official Meeting' when d.purposeofvisit=3 then 'Meeting an Employee' when d.purposeofvisit=4 then 'Package Delivery' when d.purposeofvisit=5 then 'Others' end as purposeofvisittype,d.photourl from (select v.visitorid,v.fullname,v.code,v.photourl, TO_CHAR(v.checkindate, 'DD/MM/YYYY') as checkindate, UPPER(TO_CHAR(v.checkindate, 'HH:MI:SS AM')) AS checkintime,v.purposeofvisit,c.cityname, e.contactname from bizgazecrm_visitors v inner join bizgazecrm_contacts e on e.contactid = v.employeeid inner join bizgazecrm_cities c on c.cityid = v.cityid)d where visitorid = " + id; + var dt2 = await _dbContext.GetTableAsync(GetConnectionAsync(request), sql, Unibase.Data.Enums.InstructionType.Query, null); + var tabledata = Unibase.Core.Helpers.JsonHelper.ToJson(dt2); string json = System.Text.Json.JsonSerializer.Serialize(tabledata); return new SelectResponse() { Result = json }; } @@ -119,6 +124,13 @@ namespace Bizgaze.CRM.Visitors.Managers //var templateManager = //Unibase.Dependency.DependencyConfig.Resolve(); var _dbContext = DependencyConfig.Resolve(); Unibase.Platform.Templates.Helpers.TemplateHelper helper = new Unibase.Platform.Templates.Helpers.TemplateHelper(_dbContext); + var visitordata = GetVisitordataByIdAsync(srequest, VisitorId); + var res = visitordata.Result; + var deserializeObj = System.Text.Json.JsonSerializer.Deserialize>>(res.Result); + var city = deserializeObj[0]["cityname"].ToString(); + var contactname = deserializeObj[0]["contactname"].ToString(); + var purposeofvisit = deserializeObj[0]["purposeofvisittype"].ToString(); + var date = deserializeObj[0]["datetime"]; var VisitorInfo_ = await GetVisitorByIdAsync(srequest, VisitorId); if (VisitorInfo_.Result != null) { @@ -137,11 +149,11 @@ namespace Bizgaze.CRM.Visitors.Managers } if (template.Contains("{{cityname}}")) { - template = template.Replace("{{cityname}}", VisitorInfo_.Result.CityName); + template = template.Replace("{{cityname}}", city); } if (template.Contains("{{purposeofvisit}}")) { - template = template.Replace("{{purposeofvisit}}", VisitorInfo_.Result.PurposeOfVisitType); + template = template.Replace("{{purposeofvisit}}", purposeofvisit); } if (template.Contains("{{phonenumber}}")) { @@ -153,7 +165,7 @@ namespace Bizgaze.CRM.Visitors.Managers } if (template.Contains("{{createddate}}")) { - template = template.Replace("{{createddate}}", CreatedDate.ToString()); + template = template.Replace("{{createddate}}", date.ToString()); } if (template.Contains("{{photourl}}")) { @@ -161,7 +173,7 @@ namespace Bizgaze.CRM.Visitors.Managers } if (template.Contains("{{HostName}}")) { - template = template.Replace("{{HostName}}", VisitorInfo_.Result.HostName); + template = template.Replace("{{HostName}}", contactname); } if (template.Contains("{{imageurl}}")) {