/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetAgentsForAutoCompleteRequestContainer requestContainer = context.InParam as GetAgentsForAutoCompleteRequestContainer; GetAgentsForAutoCompleteReturnContainer returnContainer = new GetAgentsForAutoCompleteReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>() { { "@deleted", false } }; parameters.Add("@name", string.Format("%{0}%", requestContainer.Text)); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetAgentForAutoComplete, parameters); returnContainer.Agents = new List<UserProfile>(); if (result.Tables.Count > 0) { foreach (DataRow row in result.Tables[0].Rows) { UserProfile agent = new UserProfile(); agent.Name = row["Name"].ToString(); agent.UserId = row["UserId"].ToString(); agent.PhoneNumber = row["PhoneNumber"].ToString(); double tempDouble; double.TryParse(row["AgentRating"].ToString(), out tempDouble); agent.AgentRating = tempDouble; int tempInt; int.TryParse(row["AgentRatingCount"].ToString(), out tempInt); agent.AgentRatingCount = tempInt; returnContainer.Agents.Add(agent); } } returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BaseReturnContainer OnExecute(RequestContext context) { SaveNewCaseRequestContainer requestContainer = context.InParam as SaveNewCaseRequestContainer; SaveNewCaseReturnContainer returnContainer = new SaveNewCaseReturnContainer(); Guid caseId = Guid.NewGuid(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@caseId", caseId); parameters.Add("@userId", requestContainer.CaseInfo.UserId); parameters.Add("@userName", requestContainer.CaseInfo.UserName); parameters.Add("@title", requestContainer.CaseInfo.Title); parameters.Add("@contactPref", string.Join(Constants.QuerySeparator, requestContainer.CaseInfo.ContactPreference)); parameters.Add("@tags", string.Join(Constants.QuerySeparator, requestContainer.CaseInfo.Tags.Distinct())); parameters.Add("@requestDetails", requestContainer.CaseInfo.RequestDetails); parameters.Add("@budget", requestContainer.CaseInfo.Budget); parameters.Add("@address", requestContainer.CaseInfo.UserAddress); parameters.Add("@anotherAddress", requestContainer.CaseInfo.AnotherAddress); // Todo: Update after tags table is created parameters.Add("@isEnterpriseTag", false); parameters.Add("@deleted", false); parameters.Add("@dateTimeCreated", DateTimeOffset.UtcNow); parameters.Add("@dateTimeUpdated", DateTimeOffset.UtcNow); sqlProvider.ExecuteQuery(SqlQueries.CreateNewCase, parameters); // Todo: Make concurrent foreach (var agentId in requestContainer.AgentIds) { parameters = new Dictionary<string, object>(); parameters.Add("@caseId", caseId); parameters.Add("@agentId", agentId); parameters.Add("@blocked", false); parameters.Add("@deleted", false); parameters.Add("@dateTimeCreated", DateTimeOffset.UtcNow); parameters.Add("@dateTimeUpdated", DateTimeOffset.UtcNow); sqlProvider.ExecuteQuery(SqlQueries.AddToAgentCaseMap, parameters); } foreach (var tag in requestContainer.CaseInfo.Tags) { parameters = new Dictionary<string, object>(); parameters.Add("@caseId", caseId); parameters.Add("@tag", tag); parameters.Add("@closed", false); parameters.Add("@deleted", false); parameters.Add("@dateTimeCreated", DateTimeOffset.UtcNow); parameters.Add("@dateTimeUpdated", DateTimeOffset.UtcNow); sqlProvider.ExecuteQuery(SqlQueries.AddToTagCaseMap, parameters); } // Add to user prefered requests returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetAgentContextCaseDetailsRequestContainer requestContainer = context.InParam as GetAgentContextCaseDetailsRequestContainer; GetAgentContextCaseDetailsReturnContainer returnContainer = new GetAgentContextCaseDetailsReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@caseId", requestContainer.CaseId); parameters.Add("@agentId", requestContainer.AgentId); parameters.Add("@deleted", false); parameters.Add("@blocked", false); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetAgentContextualInfoForUserCase, parameters); if (result.Tables.Count < 1) { throw new ApplicationException("Query failed"); } if (result.Tables[0].Rows.Count == 0) { Dictionary<string, object> parametersToInsert = new Dictionary<string, object>(); parametersToInsert.Add("@dateTimeCreated", DateTimeOffset.UtcNow.ToString()); parametersToInsert.Add("@contextId", Guid.NewGuid().ToString()); parametersToInsert.Add("@caseId", requestContainer.CaseId); parametersToInsert.Add("@userId", requestContainer.UserId); parametersToInsert.Add("@agentId", requestContainer.AgentId); parametersToInsert.Add("@deleted", false); parametersToInsert.Add("@blocked", false); parametersToInsert.Add("@dateTimeUpdated", DateTimeOffset.UtcNow.ToString()); sqlProvider.ExecuteQuery(SqlQueries.InsertCaseContextDetails, parametersToInsert); result = sqlProvider.ExecuteQuery(SqlQueries.GetAgentContextualInfoForUserCase, parameters); if (result.Tables.Count < 1 && result.Tables[0].Rows.Count != 1) { throw new ApplicationException("Query failed"); } } DataRow row = result.Tables[0].Rows[0]; returnContainer.ContextualCaseDetails = new ContextualCaseDetails(); returnContainer.ContextualCaseDetails = new ContextualCaseDetails(); returnContainer.ContextualCaseDetails.ContextId = row["ContextId"].ToString(); returnContainer.ContextualCaseDetails.UserId = row["UserId"].ToString(); returnContainer.ContextualCaseDetails.AgentId = row["AgentId"].ToString(); returnContainer.ContextualCaseDetails.AgentName = row["AgentName"].ToString(); returnContainer.ContextualCaseDetails.UserNotes = row["UserNotes"].ToString(); returnContainer.ContextualCaseDetails.Quote = row["Quote"].ToString(); returnContainer.ContextualCaseDetails.Timeline = row["Timeline"].ToString(); returnContainer.ContextualCaseDetails.PaymentStatus = row["PaymentStatus"].ToString(); returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { DeviceValidationRequestContainer requestContainer = context.InParam as DeviceValidationRequestContainer; DeviceValidationReturnContainer returnContainer = new DeviceValidationReturnContainer(); DateTimeOffset timestamp = DateTimeOffset.UtcNow; ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>() { { "@userId", requestContainer.UserId }, { "@deleted", false } }; DataSet returnedData = sqlProvider.ExecuteQuery(SqlQueries.RetrieveDeviceVerificationCode, parameters); if (returnedData.Tables[0].Rows.Count == 1) { DeviceValidationContainer deviceValidationContainer = new DeviceValidationContainer(); deviceValidationContainer.VerificationCode = int.Parse(returnedData.Tables[0].Rows[0]["VerificationCode"].ToString()); deviceValidationContainer.ExpiryTime = DateTime.Parse(returnedData.Tables[0].Rows[0]["TimeStamp"].ToString()).AddMinutes(5); bool verified = (deviceValidationContainer.VerificationCode == requestContainer.ValidationCode && deviceValidationContainer.ExpiryTime > timestamp); if (verified) { // Verified and valid returnContainer.ReturnCode = ReturnCodes.C101; sqlProvider.ExecuteQuery(SqlQueries.DeleteVerificationEntry, parameters); } else { if (deviceValidationContainer.ExpiryTime < timestamp) { // User found and code has expired. Needs to close app and start again. returnContainer.ReturnCode = ReturnCodes.C103; sqlProvider.ExecuteQuery(SqlQueries.DeleteVerificationEntry, parameters); } else { // UserFound but not valid code returnContainer.ReturnCode = ReturnCodes.C102; } } } else { // No user entry found. Need to restart App. returnContainer.ReturnCode = ReturnCodes.C001; } return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetAgentCaseDetailsRequestContainer requestContainer = context.InParam as GetAgentCaseDetailsRequestContainer; GetAgentCaseDetailsReturnContainer returnContainer = new GetAgentCaseDetailsReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@deleted", false); parameters.Add("@caseId", requestContainer.CaseId); parameters.Add("@agentId", requestContainer.AgentId); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetAgentCaseDetails, parameters); if(result.Tables.Count < 1 && result.Tables[0].Rows.Count != 1) { throw new ApplicationException("Query error"); } DataRow row = result.Tables[0].Rows[0]; returnContainer.CaseInfo = new CaseDetails(); returnContainer.CaseInfo.CaseId = row["CaseId"].ToString(); returnContainer.CaseInfo.Title = row["Title"].ToString(); returnContainer.CaseInfo.RequestDetails = row["RequestDetails"].ToString(); int tempInt = 0; int.TryParse(row["Budget"].ToString(), out tempInt); returnContainer.CaseInfo.Budget = tempInt; returnContainer.CaseInfo.ContactPreference = row["ContactPref"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList(); bool tempBool = false; bool.TryParse(row["IsEnterpriseTag"].ToString(), out tempBool); returnContainer.CaseInfo.IsEnterpriseTag = tempBool; returnContainer.ContextualCaseDetails = new ContextualCaseDetails(); returnContainer.ContextualCaseDetails.ContextId = row["ContextId"].ToString(); returnContainer.ContextualCaseDetails.UserId = row["UserId"].ToString(); returnContainer.ContextualCaseDetails.AgentId = row["AgentId"].ToString(); returnContainer.ContextualCaseDetails.AgentNotes = row["AgentNotes"].ToString(); returnContainer.ContextualCaseDetails.Timeline = row["Timeline"].ToString(); returnContainer.ContextualCaseDetails.PaymentStatus = row["PaymentStatus"].ToString(); returnContainer.ContextualCaseDetails.Quote = row["Quote"].ToString(); returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetTagsRequestContainer requestContainer = context.InParam as GetTagsRequestContainer; GetTagsReturnContainer returnContainer = new GetTagsReturnContainer(); INlpProvider nlpProvider = (INlpProvider)ProviderFactory.Instance.CreateProvider<INlpProvider>(null); Dictionary<string, IEnumerable<string>> keywordsCollection = (Dictionary<string, IEnumerable<string>>)nlpProvider.GetRelevantTerms(requestContainer.CaseDetails.RequestDetails); List<string> keywords = new List<string>(); foreach (var keywordCollection in keywordsCollection) { keywords.AddRange(keywordCollection.Value); } IKeywordProcessorProvider keywordProcessorProvider = (IKeywordProcessorProvider)ProviderFactory.Instance.CreateProvider<IKeywordProcessorProvider>(null); returnContainer.Tags = keywordProcessorProvider.GetTags(keywords).Take(5).ToList<string>(); returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { UpdateProfileRequestContainer requestContainer = context.InParam as UpdateProfileRequestContainer; UpdateProfileReturnContainer returnContainer = new UpdateProfileReturnContainer(); IGeolocationProvider geolocationProvider = (IGeolocationProvider)ProviderFactory.Instance.CreateProvider<IGeolocationProvider>(null); Coordinates coordinates = geolocationProvider.GetCoordinates(requestContainer.UserProfile.Address); if(coordinates.Latitude == 0 || coordinates.Longitude == 0) { returnContainer.ReturnCode = ReturnCodes.C001; return returnContainer; } ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parametersForProfile = new Dictionary<string, object>(); parametersForProfile.Add("@UserInfoName", requestContainer.UserProfile.Name); parametersForProfile.Add("@UserInfoContactPref", string.Join(Constants.QuerySeparator, requestContainer.UserProfile.ContactPreference)); parametersForProfile.Add("@UserInfoEmailAddress", requestContainer.UserProfile.EmailAddress); parametersForProfile.Add("@UserInfoAddress", new JavaScriptSerializer().Serialize(requestContainer.UserProfile.Address)); parametersForProfile.Add("@IsAgent", requestContainer.UserProfile.IsAgent); parametersForProfile.Add("@IsManager", requestContainer.UserProfile.IsManager); parametersForProfile.Add("@LandingPage", requestContainer.UserProfile.LandingPage); parametersForProfile.Add("@Longitude", coordinates.Longitude); parametersForProfile.Add("@Latitude", coordinates.Latitude); parametersForProfile.Add("@AreaOfService", requestContainer.UserProfile.AreaOfService); parametersForProfile.Add("@AreaOfServiceTopLeftLat", null); parametersForProfile.Add("@AreaOfServiceTopLeftLng", null); parametersForProfile.Add("@AreaOfServiceBottomRightLat", null); parametersForProfile.Add("@AreaOfServiceBottomRightLng", null); parametersForProfile.Add("@Tags", null); parametersForProfile.Add("@userId", requestContainer.UserProfile.UserId); sqlProvider.ExecuteQuery(SqlQueries.UpdateUserProfile, parametersForProfile); returnContainer.IsAgent = requestContainer.UserProfile.IsAgent; returnContainer.Latitude = coordinates.Latitude; returnContainer.Longitude = coordinates.Longitude; returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetAgentsForCaseRequestContainer requestContainer = context.InParam as GetAgentsForCaseRequestContainer; GetAgentsForCaseReturnContainer returnContainer = new GetAgentsForCaseReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@caseId", requestContainer.CaseId); parameters.Add("@deleted", false); parameters.Add("@blocked", false); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetAgentsForUserCase, parameters); if (result.Tables.Count < 1) { throw new ApplicationException("Query failed"); } returnContainer.Agents = new List<UserProfile>(); foreach (DataRow row in result.Tables[0].Rows) { UserProfile userProfile = new UserProfile(); userProfile.UserId = row["AgentId"].ToString(); userProfile.Name = row["Name"].ToString(); double tempDouble = 0; double.TryParse(row["AgentRating"].ToString(), out tempDouble); userProfile.AgentRating = tempDouble; int tempInt = 0; int.TryParse(row["AgentRatingCount"].ToString(), out tempInt); userProfile.AgentRatingCount = tempInt; returnContainer.Agents.Add(userProfile); } // Todo: Locality and order returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetTagsForAutoCompleteRequestContainer requestContainer = context.InParam as GetTagsForAutoCompleteRequestContainer; GetTagsForAutoCompleteReturnContainer returnContainer = new GetTagsForAutoCompleteReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>() { { "@deleted", false } }; parameters.Add("@tag", string.Format("%{0}%", requestContainer.Text)); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetTagsForAutoComplete, parameters); returnContainer.SuggestedTags = new List<string>(); if (result.Tables.Count > 0) { foreach (DataRow row in result.Tables[0].Rows) { returnContainer.SuggestedTags.Add(row["Tag"].ToString()); } } returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [validate]. /// </summary> /// <param name="context">The context.</param> /// <returns>Whether the input params are valid or not</returns> public virtual bool OnValidate(RequestContext context) { return true; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetUserCaseDetailRequestContainer requestContainer = context.InParam as GetUserCaseDetailRequestContainer; GetUserCaseDetailReturnContainer returnContainer = new GetUserCaseDetailReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@caseId", requestContainer.CaseId); parameters.Add("@deleted", false); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetUserCaseDetailsQuery, parameters); if (result.Tables.Count < 1) { throw new ApplicationException("Query failed"); } if (result.Tables[0].Rows.Count != 1) { throw new ApplicationException("Query failed"); } DataRow row = result.Tables[0].Rows[0]; returnContainer.CaseDetails = new CaseDetails(); returnContainer.CaseDetails.CaseId = row["CaseId"].ToString(); returnContainer.CaseDetails.Title = row["Title"].ToString(); returnContainer.CaseDetails.RequestDetails = row["RequestDetails"].ToString(); int tempInt = 0; int.TryParse(row["Budget"].ToString(), out tempInt); returnContainer.CaseDetails.Budget = tempInt; returnContainer.CaseDetails.AssignedAgentId = row["AssignedAgentId"].ToString(); // Todo: We can get this in a single join if(!string.IsNullOrEmpty(returnContainer.CaseDetails.AssignedAgentId)) { parameters = new Dictionary<string, object>(); parameters.Add("@agentId", returnContainer.CaseDetails.AssignedAgentId); parameters.Add("@caseId", requestContainer.CaseId); parameters.Add("@deleted", false); result = sqlProvider.ExecuteQuery(SqlQueries.GetAgentContextualInfoForUserCase, parameters); if (result.Tables.Count < 1) { throw new ApplicationException("Query failed"); } if (result.Tables[0].Rows.Count != 1) { throw new ApplicationException("Query failed"); } row = result.Tables[0].Rows[0]; returnContainer.ContextualCaseDetails = new ContextualCaseDetails(); returnContainer.ContextualCaseDetails.ContextId = row["ContextId"].ToString(); returnContainer.ContextualCaseDetails.UserId = row["UserId"].ToString(); returnContainer.ContextualCaseDetails.AgentId = row["AgentId"].ToString(); returnContainer.ContextualCaseDetails.AgentName = row["AgentName"].ToString(); returnContainer.ContextualCaseDetails.UserNotes = row["UserNotes"].ToString(); returnContainer.ContextualCaseDetails.Quote = row["Quote"].ToString(); returnContainer.ContextualCaseDetails.Timeline = row["Timeline"].ToString(); returnContainer.ContextualCaseDetails.PaymentStatus = row["PaymentStatus"].ToString(); } returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { CreateNewUserRequestContainer requestContainer = context.InParam as CreateNewUserRequestContainer; CreateNewUserReturnContainer returnContainer = new CreateNewUserReturnContainer(); StringBuilder sb = new StringBuilder(); sb.Append("+"); for (int i = 0; i < requestContainer.PhoneNumber.Length; i++) { int temp; if (int.TryParse(requestContainer.PhoneNumber[i].ToString(), out temp)) { sb.Append(temp); } } string phoneNumber = sb.ToString(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); DataSet user = sqlProvider.ExecuteQuery(SqlQueries.CheckIfPhoneNumberRegisteredQuery, new Dictionary<string, object>() { { "@phoneNumber", phoneNumber }, { "@deleted", false } }); bool exists = false; string userId = string.Empty; if (user.Tables[0].Rows.Count == 1) { userId = user.Tables[0].Rows[0]["UserId"].ToString(); exists = true; } if (requestContainer.DeviceType == DeviceType.Phone.ToString()) { if (exists) { returnContainer.UserId = userId; // User does exist and verification text has been sent to the phone. returnContainer.ReturnCode = ReturnCodes.C102; } else { returnContainer.UserId = Guid.NewGuid().ToString(); UserProfile userProfile = new UserProfile(); userProfile.UserId = returnContainer.UserId; userProfile.PhoneNumber = requestContainer.PhoneNumber; Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@userId", returnContainer.UserId); parameters.Add("@orgId", Constants.UnassignedOrg); parameters.Add("@phoneNumber", phoneNumber); parameters.Add("@isVerified", 0); parameters.Add("@isAgent", 0); parameters.Add("@isManager", 0); parameters.Add("@deleted", 0); parameters.Add("@dateTimeCreated", DateTimeOffset.UtcNow); parameters.Add("@dateTimeUpdated", DateTimeOffset.UtcNow); sqlProvider.ExecuteQuery(SqlQueries.CreateNewProfileQuery, parameters); returnContainer.ReturnCode = ReturnCodes.C101; } // Todo: Verification text module needs to be called. Dictionary<string, object> parameters1 = new Dictionary<string, object>(); parameters1.Add("@userId", returnContainer.UserId); parameters1.Add("@VerificationCode", 1234); parameters1.Add("@TimeStamp", DateTimeOffset.UtcNow); parameters1.Add("@Deleted", 0); sqlProvider.ExecuteQuery(SqlQueries.InsertDeviceVerificationCode, parameters1); } else if (requestContainer.DeviceType == DeviceType.NonPhone.ToString()) { if (exists) { returnContainer.UserId = userId; // User does exist and push notification sent to phone with verification code returnContainer.ReturnCode = ReturnCodes.C104; // Todo: Verification text module needs to be called. Random rand = new Random((int)DateTime.UtcNow.AddDays(-1).Ticks); int code = rand.Next(0, 10000); IPhoneVerificationProvider phoneVerificationProvider = (IPhoneVerificationProvider)ProviderFactory.Instance.CreateProvider<IPhoneVerificationProvider>("PhoneVerificationDesignProvider"); phoneVerificationProvider.SendVerificationSMS(phoneNumber, code.ToString()); Dictionary<string, object> parameters1 = new Dictionary<string, object>(); parameters1.Add("@userId", returnContainer.UserId); parameters1.Add("@VerificationCode", code); parameters1.Add("@TimeStamp", DateTimeOffset.UtcNow); parameters1.Add("@Deleted", 0); sqlProvider.ExecuteQuery(SqlQueries.InsertDeviceVerificationCode, parameters1); } else { // User does not exist and needs to create user on a phone. returnContainer.ReturnCode = ReturnCodes.C103; } } else { // Todo: Log and exception } return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetRecommendedAgentsRequestContainer requestContainer = context.InParam as GetRecommendedAgentsRequestContainer; GetRecommendedAgentsReturnContainer returnContainer = new GetRecommendedAgentsReturnContainer(); const int maxTagsCount = 10; const int maxAgentCount = int.MaxValue; // Todo: Make lists from Json ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>() { { "@deleted", false } }; for (int i = 0; i < requestContainer.CaseDetails.Tags.Count && i < maxTagsCount; i++) { parameters.Add("@tag" + i, requestContainer.CaseDetails.Tags[i]); } DataSet agentIdsresult = sqlProvider.ExecuteQuery(SqlQueries.GetAgentsForTagQuery(requestContainer.CaseDetails.Tags.Take(maxTagsCount).ToList<string>()), parameters); List<string> agentIds = new List<string>(); returnContainer.RecommendedAgents = new List<UserProfile>(); if (agentIdsresult.Tables.Count > 0 && agentIdsresult.Tables[0].Rows.Count > 0) { foreach (DataRow row in agentIdsresult.Tables[0].Rows) { bool isEnterpriseTag; bool.TryParse(row["IsEnterpriseTag"].ToString(), out isEnterpriseTag); if (isEnterpriseTag) { UserProfile userProfile = new UserProfile(); userProfile.Name = Constants.TagKeywordIndicator + row["Tag"].ToString(); userProfile.UserId = string.Empty; double tempDouble; double.TryParse(row["EnterpriseTagRating"].ToString(), out tempDouble); userProfile.AgentRating = tempDouble; int tempInt; int.TryParse(row["EnterpriseTagRatingCount"].ToString(), out tempInt); userProfile.AgentRatingCount = tempInt; int.TryParse(row["EnterpriseTagPositiveRatingCount"].ToString(), out tempInt); userProfile.AgentPositiveRatingCount = tempInt; returnContainer.RecommendedAgents.Add(userProfile); continue; } // Todo: Change to json agentIds.AddRange(row["AgentIdGroup1"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>()); agentIds.AddRange(row["AgentIdGroup2"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>()); } } parameters = new Dictionary<string, object>() { { "@deleted", false } }; for (int i = 0; i < agentIds.Count && i < maxAgentCount; i++) { parameters.Add("@userId" + i, agentIds[i]); } Coordinates coordinates = new Coordinates(requestContainer.UserProfile.UserLatitude, requestContainer.UserProfile.UserLongitude); if (requestContainer.CaseDetails.AnotherAddress != null) { IGeolocationProvider geolocationProvider = (IGeolocationProvider)ProviderFactory.Instance.CreateProvider<IGeolocationProvider>(null); coordinates = geolocationProvider.GetCoordinates(requestContainer.CaseDetails.AnotherAddress); } parameters.Add("@Lat", coordinates.Latitude); parameters.Add("@Lng", coordinates.Longitude); DataSet agentInfoResult = sqlProvider.ExecuteQuery(SqlQueries.GetUsersByIdsQuery(agentIds.Take(maxAgentCount).ToList<string>(), coordinates), parameters); List<UserProfile> agentProfiles = new List<UserProfile>(); if (agentInfoResult.Tables.Count > 0 && agentInfoResult.Tables[0].Rows.Count > 0) { foreach (DataRow row in agentInfoResult.Tables[0].Rows) { // Todo: Change to json UserProfile agentProfile = new UserProfile(); agentProfile.UserId = row["UserId"].ToString(); agentProfile.Name = row["Name"].ToString(); double tempDouble; if (double.TryParse(row["AgentRating"].ToString(), out tempDouble)) { agentProfile.AgentRating = tempDouble; } else { // Todo: Log } int tempInt; if (int.TryParse(row["AgentRatingCount"].ToString(), out tempInt)) { agentProfile.AgentRatingCount = tempInt; } else { // Todo: Log } int.TryParse(row["AgentPositiveRatingCount"].ToString(), out tempInt); agentProfile.AgentPositiveRatingCount = tempInt; agentProfiles.Add(agentProfile); } } // Todo: Enterprise tags are not ranked. IRankingProvider rankingProvider = (IRankingProvider)ProviderFactory.Instance.CreateProvider<IRankingProvider>(null); rankingProvider.SortByRank(agentProfiles); returnContainer.RecommendedAgents.AddRange(agentProfiles.Take(5).ToList()); returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Runs the command. /// </summary> /// <param name="command">The command.</param> /// <param name="contents">The contents.</param> /// <returns>The result of the command</returns> private BaseReturnContainer RunCommand(BaseCommand command, BaseRequestContainer contents) { RequestContext context = new RequestContext(contents); if (command.OnValidate(context)) { BaseReturnContainer returnContainer = command.OnExecute(context); Debug.Assert(!string.IsNullOrEmpty(returnContainer.ReturnCode)); return returnContainer; } // Todo: what happens when validate fails? return null; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetUserCasesRequestContainer requestContainer = context.InParam as GetUserCasesRequestContainer; GetUserCasesReturnContainer returnContainer = new GetUserCasesReturnContainer(); ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@userId", requestContainer.UserId); parameters.Add("@deleted", false); DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetUserCasesQuery, parameters); if(result.Tables.Count < 1) { throw new ApplicationException("Query failed"); } returnContainer.Cases = new List<CaseDetails>(); foreach (DataRow row in result.Tables[0].Rows) { CaseDetails caseDetails = new CaseDetails(); caseDetails.CaseId = row["CaseId"].ToString(); caseDetails.Title = row["Title"].ToString(); bool tempBool = false; bool.TryParse(row["NewMessage"].ToString(), out tempBool); caseDetails.NewMessage = tempBool; string tempString = row["AssignedAgentId"].ToString(); if (tempString != DBNull.Value.ToString()) { caseDetails.AssignedAgentId = tempString; } else { caseDetails.AssignedAgentId = string.Empty; } tempString = row["Name"].ToString(); if (tempString != DBNull.Value.ToString()) { caseDetails.AssignedAgentName = tempString; } else { caseDetails.AssignedAgentName = string.Empty; } DateTimeOffset tempDateTimeOffset; if (DateTimeOffset.TryParse(row["DateTimeUpdated"].ToString(), out tempDateTimeOffset)) { caseDetails.LastUpdateDateTime = tempDateTimeOffset; } else { // Log an error } returnContainer.Cases.Add(caseDetails); } returnContainer.ReturnCode = ReturnCodes.C101; return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetAgentDetailsRequestContainer requestContainer = context.InParam as GetAgentDetailsRequestContainer; GetAgentDetailsReturnContainer returnContainer = new GetAgentDetailsReturnContainer(); Dictionary<string, object> parameters = new Dictionary<string, object>() { { "@deleted", false } }; List<string> usersToQuery = new List<string>(); usersToQuery.Add(requestContainer.AgentId); usersToQuery.Add(requestContainer.UserId); for (int i = 0; i < usersToQuery.Count; i++) { parameters.Add("@userId" + i, usersToQuery[i]); } ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); DataSet agentInfoResult = sqlProvider.ExecuteQuery(SqlQueries.GetUsersByIdsQuery(usersToQuery), parameters); if (agentInfoResult.Tables.Count > 0 && agentInfoResult.Tables[0].Rows.Count == 2) { foreach (DataRow row in agentInfoResult.Tables[0].Rows) { string userId = row["UserId"].ToString(); if (userId == requestContainer.AgentId) { // Todo: Change to json UserProfile agentProfile = new UserProfile(); agentProfile.UserId = row["UserId"].ToString(); agentProfile.Name = row["Name"].ToString(); double tempDouble; if (double.TryParse(row["AgentRating"].ToString(), out tempDouble)) { agentProfile.AgentRating = tempDouble; } else { // Todo: Log } int tempInt; if (int.TryParse(row["AgentRatingCount"].ToString(), out tempInt)) { agentProfile.AgentRatingCount = tempInt; } else { // Todo: Log } double.TryParse(row["AreaOfService"].ToString(), out tempDouble); agentProfile.AreaOfService = tempDouble; agentProfile.Tags = row["Tags"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); returnContainer.AgentProfile = agentProfile; } else { List<string> favoriteAgentsOfUser = row["FavoriteAgents"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); returnContainer.IsFavorite = false; if (favoriteAgentsOfUser.Contains(requestContainer.AgentId)) { returnContainer.IsFavorite = true; } } } // If the agent profile is null, it is a tag. // Name, rating, area of service, returnContainer.ReturnCode = ReturnCodes.C101; } else { // No agent found returnContainer.ReturnCode = ReturnCodes.C001; } return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { GetProfileRequestContainer requestContainer = context.InParam as GetProfileRequestContainer; GetProfileReturnContrainer returnContainer = new GetProfileReturnContrainer(); // Todo: Make lists from Json ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>() { { "@userId", requestContainer.UserId }, { "@deleted", false } }; DataSet returnedData = sqlProvider.ExecuteQuery(SqlQueries.GetUserProfileQuery, parameters); if (returnedData.Tables.Count > 0 && returnedData.Tables[0].Rows.Count == 1) { DataRow row = returnedData.Tables[0].Rows[0]; UserProfile userProfile = new UserProfile(); userProfile.Name = row["Name"].ToString(); userProfile.PhoneNumber = row["PhoneNumber"].ToString(); bool tempBool; if (bool.TryParse(row["IsVerified"].ToString(), out tempBool)) { userProfile.IsVerified = tempBool; } else { // Todo: Log } userProfile.ContactPreference = row["ContactPref"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); userProfile.EmailAddress = row["EmailAddress"].ToString(); userProfile.Address = new JavaScriptSerializer().Deserialize<AddressContainer>(row["Address"].ToString()); if (bool.TryParse(row["IsAgent"].ToString(), out tempBool)) { userProfile.IsAgent = tempBool; } else { // Todo: Log } if (bool.TryParse(row["IsManager"].ToString(), out tempBool)) { userProfile.IsManager = tempBool; } else { // Todo: Log } int tempInt; if (int.TryParse(row["LandingPage"].ToString(), out tempInt)) { userProfile.LandingPage = tempInt; } else { // Todo: log } userProfile.PushNotificationUri = row["PushNotificationsUri"].ToString(); double tempDouble; if (double.TryParse(row["AgentRating"].ToString(), out tempDouble)) { userProfile.AgentRating = tempDouble; } else { // Todo: log } if (int.TryParse(row["AgentRatingCount"].ToString(), out tempInt)) { userProfile.AgentRatingCount = tempInt; } else { // Todo: log } userProfile.Tags = row["Tags"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); double.TryParse(row["AreaOfService"].ToString(), out tempDouble); userProfile.AreaOfService = tempDouble; userProfile.FavoriteAgents = row["FavoriteAgents"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); // Found user and returning it returnContainer.ReturnCode = ReturnCodes.C101; returnContainer.UserInfo = userProfile; } else { // User does not exist returnContainer.ReturnCode = ReturnCodes.C001; } return returnContainer; }
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>Result of the OnExecute</returns> public abstract BaseReturnContainer OnExecute(RequestContext context);
/// <summary> /// Called when [execute]. /// </summary> /// <param name="context">The context.</param> /// <returns>BaseReturnContainer object</returns> public override BaseReturnContainer OnExecute(RequestContext context) { AddAgentTagsRequestContainer requestContainer = context.InParam as AddAgentTagsRequestContainer; AddAgentTagsReturnContainer returnContainer = new AddAgentTagsReturnContainer(); int maxTagsCount = 10; ISqlProvider sqlProvider = (ISqlProvider)ProviderFactory.Instance.CreateProvider<ISqlProvider>(requestContainer.ProviderName); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@deleted", false); for (int i = 0; i < requestContainer.TagCodeList.Count && i < maxTagsCount; i++) { parameters.Add("@tag" + i, requestContainer.TagCodeList[i].First); } DataSet result = sqlProvider.ExecuteQuery(SqlQueries.GetTagInfoForAddingNewTagToAgentQuery(requestContainer.TagCodeList.Select(x => x.First).Take(maxTagsCount).ToList<string>()), parameters); if (result.Tables.Count < 1) { throw new ApplicationException("Query errored out"); } returnContainer.ReturnCode = ReturnCodes.C101; Dictionary<string, string> tagsUserMap = new Dictionary<string, string>(); // Todo: Need to check if user already on the tag and not repeat. Edit 1/18/2016: I believe here we are talking about for inserting below again in the DB. returnContainer.TagsThatNeedCodes = new List<string>(); foreach (DataRow row in result.Tables[0].Rows) { string tag = row["Tag"].ToString(); bool isEnterpriseTag = false; bool.TryParse(row["IsEnterpriseTag"].ToString(), out isEnterpriseTag); List<string> userIds = row["AgentIdGroup1"].ToString().Split(new string[] { Constants.QuerySeparator }, StringSplitOptions.RemoveEmptyEntries).ToList(); if(userIds.Contains(requestContainer.AgentProfile.UserId, StringComparer.OrdinalIgnoreCase)) { tagsUserMap.Add(tag, row["AgentIdGroup1"].ToString()); continue; } if (isEnterpriseTag) { DateTimeOffset tempDateTimeOffset = new DateTimeOffset(new DateTime(1900, 1, 1)); DateTimeOffset.TryParse(row["DateTimeTagCode"].ToString(), out tempDateTimeOffset); if(tempDateTimeOffset > DateTimeOffset.UtcNow) { int tempInt = -1; int.TryParse(row["Code"].ToString(), out tempInt); if (tempInt != requestContainer.TagCodeList.FirstOrDefault(x => x.First == tag).Second) { returnContainer.TagWithIncorrectCode = tag; returnContainer.ReturnCode = ReturnCodes.C103; return returnContainer; } else { tagsUserMap.Add(tag, row["AgentIdGroup1"].ToString() + Constants.QuerySeparator + requestContainer.AgentProfile.UserId); } } else { returnContainer.TagsThatNeedCodes.Add(tag); returnContainer.ReturnCode = ReturnCodes.C102; } } else { tagsUserMap.Add(tag, row["AgentIdGroup1"].ToString() + Constants.QuerySeparator + requestContainer.AgentProfile.UserId); } } Coordinates topLeft; Coordinates bottomRight; IGeoAreaProvider geoAreaProvider = (IGeoAreaProvider)ProviderFactory.Instance.CreateProvider<IGeoAreaProvider>(null); geoAreaProvider.GetBoundary(new Coordinates(requestContainer.AgentProfile.UserLatitude, requestContainer.AgentProfile.UserLongitude), requestContainer.AgentProfile.AreaOfService, out topLeft, out bottomRight); // Make this concurrent and is not thread safe. if (returnContainer.ReturnCode == ReturnCodes.C101) { List<string> tagsToAdd = new List<string>(); for (int i = 0; i < requestContainer.TagCodeList.Count && i < maxTagsCount; i++) { Dictionary<string, object> parametersForUpdate = new Dictionary<string, object>(); parametersForUpdate.Add("@tag", requestContainer.TagCodeList[i].First); parametersForUpdate.Add("@userIds", tagsUserMap[requestContainer.TagCodeList[i].First]); sqlProvider.ExecuteQuery(SqlQueries.UpdateTagWithInfo, parametersForUpdate); tagsToAdd.Add(requestContainer.TagCodeList[i].First); } Dictionary<string, object> parametersForProfile = new Dictionary<string, object>(); parametersForProfile.Add("@UserInfoName", null); parametersForProfile.Add("@UserInfoContactPref", null); parametersForProfile.Add("@UserInfoEmailAddress", null); parametersForProfile.Add("@UserInfoAddress", null); parametersForProfile.Add("@IsAgent", null); parametersForProfile.Add("@IsManager", null); parametersForProfile.Add("@LandingPage", null); parametersForProfile.Add("@Longitude", null); parametersForProfile.Add("@Latitude", null); parametersForProfile.Add("@AreaOfService", requestContainer.AgentProfile.AreaOfService); parametersForProfile.Add("@AreaOfServiceTopLeftLat", topLeft.Latitude); parametersForProfile.Add("@AreaOfServiceTopLeftLng", topLeft.Longitude); parametersForProfile.Add("@AreaOfServiceBottomRightLat", bottomRight.Latitude); parametersForProfile.Add("@AreaOfServiceBottomRightLng", bottomRight.Longitude); parametersForProfile.Add("@Tags", string.Join(Constants.QuerySeparator, tagsToAdd)); parametersForProfile.Add("@userId", requestContainer.AgentProfile.UserId); sqlProvider.ExecuteQuery(SqlQueries.UpdateUserProfile, parametersForProfile); } return returnContainer; }