コード例 #1
0
        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);
        }
コード例 #2
0
        private HttpResponseMessage processXmlLead(HttpRequestMessage request, string encryptedClientId, int defaultUserId, string endpoint, bool checkForDuplicate = true)
        {
            this.ResponseFormatter = new XmlMediaTypeFormatter();

            var startTime = DateTime.Now;

            if (string.IsNullOrEmpty(encryptedClientId))
            {
                return(this.CreateErrorResponse(HttpStatusCode.BadRequest, "Missing encrypted client id.", endpoint));
            }

            var     clientId = NullSafe.NullSafeInteger(Encryption.DecryptString(encryptedClientId));
            AClient client   = Master.Lists.Clients.GetClientById(clientId);

            if (!client?.Active ?? true) //if null or not active reject...
            {
                return(this.CreateErrorResponse(HttpStatusCode.Unauthorized, "Client is invalid.", endpoint));
            }

            //http://stackoverflow.com/questions/1127431/xmlserializer-giving-filenotfoundexception-at-constructor
            //Error is thrown here, this is 'expected' beaviour. Just ignore...
            var serializer = new XmlSerializer(typeof(MortgageLead));
            var dataLead   = (MortgageLead)serializer.Deserialize(request.Content.ReadAsStreamAsync().Result);

            ALeadsResponse response = new ALeadsResponse();

            response.ApiEndPoint             = endpoint;
            response.ClientDefinedIdentifier = dataLead.SourceLeadId;

            Lead lead;

            bool doInsert = true;

            if (checkForDuplicate)
            {
                ActionResponse <Lead> actionResponse = this.duplicateCheck(clientId, dataLead);
                if (actionResponse.Success) //true = dupicate
                {
                    doInsert         = false;
                    response.Status  = StatusType.Complete;
                    response.Message = "Duplicate";
                    response.LoanTekDefinedIdentifier = actionResponse.DataObject.Id.ToString();
                }
            }
            if (doInsert && (lead = LegacyLead.ConvertXmlSchema(dataLead)) != null)
            {
                lead.ClientID = clientId;

                //reset UserId to 0 if the User's ClientId does not match this client
                if (lead.UserID > 0 && Users.GetUserById(lead.UserID.GetValueOrDefault())?.ClientId != clientId)
                {
                    lead.UserID = 0;
                }
                if (lead.UserID == 0)
                {
                    lead.UserID = defaultUserId;
                }

                ActionResponse <Lead> actionResponse = new Biz.Contacts.Leads.Objects.Leads(DataContextType.Database, DataConnections.DataContextBankrateWrite).PutWithResponse(lead);
                if (actionResponse.Success)
                {
                    response.Status  = StatusType.Complete;
                    response.Message = Types.Processing.StatusType.Success.ToString();
                    response.LoanTekDefinedIdentifier = actionResponse.DataObject?.Id.ToString();
                }
                else
                {
                    response.Status  = StatusType.Error;
                    response.Message = response.Message;
                }
            }

            response.ExecutionTimeInMillisec = (int)(DateTime.Now - startTime).TotalMilliseconds;
            return(Request.CreateResponse(HttpStatusCode.OK, response, this.ResponseFormatter));
        }