protected Service CreateAndSaveService(ALeadsRequest request, ALeadsResponse response, string message, Types.Api.AppType appType, ApiWebService webService) { Service obj = new Service(); obj.RequestId = response.LoanTekDefinedIdentifier; obj.StartTime = DateTime.Now.AddMilliseconds(-this.Sw.ElapsedMilliseconds); obj.EndTime = DateTime.Now; obj.ClientId = this.AuthToken?.ClientId > 0 ? this.AuthToken.ClientId : Users.GetUserById(request.LeadFile.UserId)?.ClientId ?? 0; obj.UserId = request.LeadFile.UserId; obj.ApiWebServiceId = webService.Id; obj.ServiceName = webService.WebServiceName; obj.Endpoint = this.EndPoint; obj.Route = this.Request?.RequestUri?.PathAndQuery; obj.HttpStatusCodeType = HttpStatusCode.OK; obj.Message = message; obj.CallingIpAddress = ClientInfo.GetIPAddress(this.Request); obj.CallingAppType = appType; services.Put(obj); return(obj); }
public HttpResponseMessage SalesLeadRequestAdd(string authToken, SalesLeadRequest request) { string apiEndPoint = ApiObject.ApiName + ".SalesLeadRequest/POST"; this.EndPoint = apiEndPoint; try { var startTime = DateTime.Now; this.ContentType = this.Request.Content?.Headers?.ContentType?.MediaType; HttpResponseMessage errorResponse = this.CommonChecks(request, apiEndPoint); if (errorResponse != null) { return(errorResponse); } AuthToken authTokenObject = (!string.IsNullOrEmpty(authToken)) ? new AuthToken(authToken) : null; errorResponse = this.Authorize(apiEndPoint, authTokenObject, request.LeadFile?.UserId ?? 0); if (errorResponse != null) { return(errorResponse); } //if the ClientId is not set in the 'File' then use the clientId from the posting URL authToken if (request.LeadFile.ClientId == 0) { request.LeadFile.ClientId = authTokenObject.ClientId; } //TODO - check client for license... //if(!License.Has(LoanPricerAPILicenseType, authTokenObject.ClientId)) // return this.CreateErrorResponse(HttpStatusCode.PaymentRequired, "Missing valid license:"+ LoanPricerAPILicenseType.ToString(), apiEndPoint); this.CommonProcesses(Request); CancellationTokenSource cancelToken = this.StartTimeoutTimer(CommonParams.TimeoutInMill); ProcessFileRequest process = new ProcessFileRequest(request.LeadFile, cancelToken); Debug.WriteLine("Done. -Status:" + process.Request.StatusType + " -ActionType:" + process.Request.ActionType + " -In Secs:" + (process.Request.EndTime.GetValueOrDefault() - process.Request.StartTime).TotalSeconds); SalesLeadResponse response = new SalesLeadResponse(); response.ExecutionTimeInMillisec = (DateTime.Now - startTime).TotalMilliseconds; response.LoanTekDefinedIdentifier = StringUtilities.UniqueId(); response.ApiEndPoint = apiEndPoint; //response.CachedId = processor.Request.CachedId; response.ClientDefinedIdentifier = request.LeadFile.ClientDefinedIdentifier; response.PassThroughItems = request.PassThroughItems; if (process.Request == null) { response.Status = StatusType.Error; response.Message = "ProcessFile.Request is missing."; } else { switch (process.Request.StatusType) { case StatusType.Complete: response.Status = StatusType.Complete; break; case StatusType.Cancelled: response.Status = StatusType.Cancelled; break; default: response.Status = StatusType.Error; break; } response.Message = process.Request.ActionType + "|" + process.Request.Misc.Replace("||", "|"); } Types.Api.AppType appType = (request.LeadFile?.Source?.Name?.ToLower().Contains("widget") ?? false) || (request.LeadFile?.Source?.SubName?.ToLower().Contains("widget") ?? false) ? Types.Api.AppType.Widget : Types.Api.AppType.Api_Clients; Task.Run(() => this.CreateAndSaveService(request, response, response.Message, appType, new ApiWebService { WebServiceName = "SalesLeadRequest", EndPoint = this.EndPoint })).ConfigureAwait(false); return(AApiResponse.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { Global.OutPrint(ex.Message, new SimpleLogger.LocationObject(this, apiEndPoint), SimpleLogger.LogLevelType.CRITICAL); return(this.CreateErrorResponse(HttpStatusCode.InternalServerError, "Exception:" + ex.Message, apiEndPoint)); } }