예제 #1
0
        /// <summary>
        /// Customers the login.
        /// </summary>
        private void CustomerLogin()
        {
            Post["CustomerLogin", "api/v1/customer/login", runAsync : true] = async(o, ct) => {
                CustomerLoginCommand command;

                //Bind
                try {
                    command = this.Bind <CustomerLoginCommand>();
                } catch (ModelBindingException ex) {
                    return(CreateErrorResponse(b => b.WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, LoginValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b.WithErrorMessages(info.GetErrors())));
                }

                CustomerLoginCommandResponse response;
                //Send command
                try {
                    response = await LoginCommandSendRecieve.SendAsync(Config.ServiceAddress, command);
                } catch (TaskCanceledException ex) {
                    Log.Error("Timeout on get customer login.");
                    return(CreateErrorResponse(HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b.WithCustomerId(response.CustomerId)));
            };
        }
예제 #2
0
        /// <summary>
        /// Handles the upload.
        /// </summary>
        /// <param name="o">The context.</param>
        /// <param name="ct">The cancellation token.</param>
        /// <param name="validator">The validator.</param>
        /// <param name="isBankDocuments">Designates whether the specified document is bank document or not</param>
        /// <returns></returns>
        private async Task <Response> HandleUpload(dynamic o, CancellationToken ct, AbstractValidator <FilesUploadModel> validator, bool isBankDocuments)
        {
            string customerId = o.customerId;

            FilesUploadModel model;

            //Bind
            try {
                model       = this.Bind <FilesUploadModel>();
                model.Files = this.Request.Files;
            } catch (ModelBindingException ex) {
                Log.Warn("binding documents upload request: " + customerId, ex);
                return(CreateErrorResponse(b => b
                                           .WithCustomerId(customerId)
                                           .WithModelBindingException(ex)));
            }

            //Validate
            InfoAccumulator info = Validate(model, validator);

            if (info.HasErrors)
            {
                return(CreateErrorResponse(b => b
                                           .WithCustomerId(customerId)
                                           .WithErrorMessages(info.GetErrors())));
            }

            Dictionary <string, Task <string> > fileToTask = this.Request.Files.ToDictionary(f => f.Name, ProcessFile);

            try {
                var paths = await Task.WhenAll(fileToTask.Values);

                var command = new DocsUploadCommand {
                    CustomerId      = model.CustomerId,
                    Files           = paths,
                    IsBankDocuments = isBankDocuments
                };
                var cts      = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                var response = await UploadCommandSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                if (response.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(response.Errors)));
                }
            } catch (AggregateException ex) {
                var failedFileNames = fileToTask
                                      .Where(p => p.Value.Exception != null)
                                      .Select(f => f.Key);
                return(CreateErrorResponse(b => b
                                           .WithCustomerId(customerId)
                                           .WithErrorMessages(failedFileNames), HttpStatusCode.InternalServerError));
            }

            return(CreateOkResponse(b => b.WithCustomerId(customerId)));
        }
예제 #3
0
        /// <summary>
        /// HMRCs the vat upload.
        /// </summary>
        private void HmrcVatUpload()
        {
            Post["UploadHmrcPdf", "api/v1/marketplace/hmrc/upload/vat/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;

                FilesUploadModel model;
                //Bind
                try {
                    model       = this.Bind <FilesUploadModel>();
                    model.Files = this.Request.Files;
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on hmrc registration request: " + customerId, ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(model, PdfValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                Dictionary <string, Task <string> > fileToTask = this.Request.Files.ToDictionary(f => f.Name, ProcessFile);

                try {
                    var paths = await Task.WhenAll(fileToTask.Values);

                    var command = new HmrcProcessUploadedFilesCommand {
                        CustomerId = model.CustomerId,
                        Files      = paths
                    };
                    var cts      = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                    var response = await ProcessUploadedFilesSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (AggregateException ex) {
                    var failedFileNames = fileToTask
                                          .Where(p => p.Value.Exception != null)
                                          .Select(f => f.Key);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(failedFileNames), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b.WithCustomerId(customerId)));
            };
        }
예제 #4
0
        /// <summary>
        /// Gets the company details.
        /// </summary>
        private void GetCompanyDetails()
        {
            Get["GetCompanyDetails", "api/v1/company/details/{customerId}/{companyId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                string companyId  = o.companyId;

                //Bind
                CompanyGetDetailsCommand command;
                try {
                    command = this.Bind <CompanyGetDetailsCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on get company details");
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, GetDetailsValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                CompanyGetDetailsCommandResponse response;
                try {
                    response = await GetCompanyDetailsSendRecieve.SendAsync(Config.ServerAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithCompanyId(companyId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException) {
                    Log.ErrorFormat("Timeout on get company details. CustomerId: {0}, CompanyId {1}", customerId, companyId);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithCompanyId(companyId)
                                        .WithJObject("Details", JObject.FromObject(response))));
            };
        }
예제 #5
0
        /// <summary>
        /// Updates the company.
        /// </summary>
        private void UpdateCompany()
        {
            Post["UpdateCompany", "api/v1/company/details/update/{customerId}/{companyId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                //"{companyId}" - is the default value in case when company id is not supplied by request
                string companyId = o.CompanyId != "{companyId}" ? o.CompanyId : null;

                //Bind
                UpdateCompanyCommand updateCommand;
                try {
                    updateCommand = this.Bind <UpdateCompanyCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on update company", ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(updateCommand, CompanyUpdateValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                try {
                    var response = await UpdateCompanySendReceive.SendAsync(Config.ServerAddress, updateCommand, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithCompanyId(companyId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException) {
                    Log.Error("timeout on update company");
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithCompanyId(companyId)));
            };
        }
예제 #6
0
        /// <summary>
        /// Creates the response.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="info">The information.</param>
        /// <param name="messageId">The message identifier.</param>
        /// <returns></returns>
        private T CreateResponse <T>(InfoAccumulator info, Guid messageId) where T : CommandResponseBase, new()
        {
            var response = new T {
                MessageId = messageId,
                Errors    = info.GetErrors()
                            .Concat(info.GetExceptions()
                                    .Select(e => e.ToString()))
                            .ToArray(),
                Warnings = info.GetWarning()
                           .ToArray(),
                Infos = info.GetInfo()
                        .ToArray()
            };

            return(response);
        }
예제 #7
0
        /// <summary>
        /// Gets the addresses by postcode.
        /// </summary>
        private void GetAddressesByPostcode()
        {
            Get["GetAddressesByPostcode", "api/v1/address/{postcode}/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                SimplyPostcodeGetAddressesCommand command;
                //Bind
                try {
                    command = this.Bind <SimplyPostcodeGetAddressesCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on get addresses by postcode request: " + customerId, ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, GetAddressesByPostCodeValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                SimplyPostcodeGetAddressesCommandResponse response;
                try {
                    response = await GetAddressesByPostcodeSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on get address by post code request: " + customerId);
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithKeyValue(() => response.Addresses.Count)
                                        .WithKeyValue(() => response.Addresses)));
            };
        }
예제 #8
0
        /// <summary>
        /// Gets the fast link.
        /// </summary>
        private void GetFastLink()
        {
            Get["GetFastLink", "api/v1/marketplace/yodlee/fastlink/{customerId}/{contentServiceId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;

                YodleeAddUserAccountCommand command;
                //Bind
                try {
                    command = this.Bind <YodleeAddUserAccountCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on yodlee get fastlink request: " + customerId, ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, AddUserAccountValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                YodleeAddUserAccountCommandResponse response;
                try {
                    response = await AddUserAccountSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on yodlee add user account" + customerId);
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithKeyValue(() => response.FastlinkUrl)));
            };
        }
예제 #9
0
        /// <summary>
        /// Customers the get details.
        /// </summary>
        private void CustomerGetDetails()
        {
            Get["GetCustomerDetails", "api/v1/customer/details/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                CustomerGetDetailsCommand getDetailsCommand;
                //Bind
                try {
                    getDetailsCommand = this.Bind <CustomerGetDetailsCommand>();
                } catch (ModelBindingException ex) {
                    return(CreateErrorResponse(b => b.WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(getDetailsCommand, GetDetailsCommandValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b.WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                CustomerGetDetailsCommandResponse response;
                try {
                    response = await GetCustomerDetailsSendRecieve.SendAsync(Config.ServiceAddress, getDetailsCommand);
                } catch (TaskCanceledException ex) {
                    Log.Error("Timeout on get customer details.");
                    return(CreateErrorResponse(b => b.WithCustomerId(getDetailsCommand.CustomerId), HttpStatusCode.InternalServerError));
                }

                var responseModel = new CustomerGetDetailsResponseModel {
                    CurrentLivingAddress      = response.CurrentLivingAddress,
                    PreviousLivingAddress     = response.PreviousLivingAddress,
                    PersonalDetails           = response.PersonalDetails,
                    AdditionalOwnedProperties = response.AdditionalOwnedProperties,
                    ContactDetails            = new CustomerContactDetailsResponseModel {
                        EmailAddress = response.ContactDetails.EmailAddress,
                        MobilePhone  = response.ContactDetails.MobilePhone,
                        PhoneNumber  = response.ContactDetails.PhoneNumber
                    },
                    RequestedAmount = response.RequestedAmount
                };

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithJObject("Details", JObject.FromObject(responseModel))));
            };
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Nancy.NancyModule"/> class.
        /// </summary>
        public AmazonModule()
        {
            Post["AmazonRegisterCustomer", "api/v1/marketplace/amazon/register/{customerId}", runAsync : true] = async(o, ct) => {
                //Bind
                string customerId = o.customerId;
                AmazonRegisterCustomerCommand command;

                try {
                    command = this.Bind <AmazonRegisterCustomerCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on register amazon customer request: " + customerId, ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, RegisterCustomerValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                AmazonRegisterCustomerCommandResponse response;
                try {
                    response = await RegisterCustomerSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on register amazon customer: " + customerId);
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)));
            };
        }
예제 #11
0
        /// <summary>
        /// Gets the redirect URL.
        /// </summary>
        private void GetRedirectUrl()
        {
            Get["EbayRirectUrl", "api/v1/marketplace/ebay/redirectUrl/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                EbayGetLoginUrlCommand command;
                //Bind
                try {
                    command = this.Bind <EbayGetLoginUrlCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on ebay redirect url request: " + customerId, ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, GetRedirectUrlValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                EbayGetLoginUrlCommandResponse response;
                try {
                    response = await GetRedirectUrlSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b.WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on ebay get redirect url: " + customerId);
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithRedirectUrl(response.EbayLoginUrl)
                                        .WithSessionId(response.SessionId)));
            };
        }
예제 #12
0
        /// <summary>
        /// Targets the company.
        /// </summary>
        private void TargetCompany()
        {
            Post["TargetCompany", "api/v1/company/target/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                ExperianBusinessTargetingCommand command;
                //Bind
                try {
                    command = this.Bind <ExperianBusinessTargetingCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on target company", ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, TargetingValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                ExperianBusinessTargetingCommandResponse response;
                try {
                    response = await TargetCompanySendReceive.SendAsync(Config.ServerAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on target company");
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)
                                        .WithKeyArray("Suggestions", response.CompanyInfos)));
            };
        }
예제 #13
0
        /// <summary>
        /// Validates the verification code.
        /// </summary>
        private void ValidateVerificationCode()
        {
            Post["ValidateVerificationCode", "api/v1/customer/verification/sms/{customerId}/{verificationToken}", runAsync : true] = async(o, ct) => {
                CustomerValidateVerificationCodeCommand command;
                string customerId = o.customerId;

                //Bind
                try {
                    command = this.Bind <CustomerValidateVerificationCodeCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("model binding failed to bind");
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, VerificationCodeValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                //specifying cancellation token makes asynchronous sender to cancel a task after specified timeout
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                try {
                    var response = await ValidateVerificationCodeSendReceive.SendAsync(Config.ServerAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on verification code validation");
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b.WithCustomerId(customerId)));
            };
        }
예제 #14
0
        /// <summary>
        /// Called on account added notification.
        /// </summary>
        private void OnAccountAdded()
        {
            Post["OnAccountAdded", "api/v1/marketplace/yodlee/notifications/account/added/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                YodleeUserAddedAccountCommand command;
                //Bind
                try {
                    command = this.Bind <YodleeUserAddedAccountCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("binding error on yodlee account added notification: " + customerId, ex);
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(command, UserAddedAccountValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                YodleeUserAddedAccountCommandResponse response;
                try {
                    response = await UserAddedAccountSendReceive.SendAsync(Config.ServiceAddress, command, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("timeout on yodlee user added account notification" + customerId);
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b
                                        .WithCustomerId(customerId)));
            };
        }
예제 #15
0
        /// <summary>
        /// Updates customer.
        /// </summary>
        private void CustomerUpdate()
        {
            Post["UpdateCustomer", "api/v1/customer/details/update/{customerId}", runAsync : true] = async(o, ct) => {
                string customerId = o.customerId;
                CustomerUpdateCommand updateCommand;
                //Bind
                try {
                    updateCommand = this.Bind <CustomerUpdateCommand>();
                } catch (ModelBindingException ex) {
                    Log.Warn("model binding failed to bind");

                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(updateCommand, UpdateValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                try {
                    var response = await UpdateSendReceive.SendAsync(Config.ServiceAddress, updateCommand, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b
                                                   .WithCustomerId(customerId)
                                                   .WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("time out on update customer");
                    return(CreateErrorResponse(b => b.WithCustomerId(customerId), HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b.WithCustomerId(customerId)));
            };
        }
예제 #16
0
        /// <summary>
        /// Customers the signup.
        /// </summary>
        private void CustomerSignup()
        {
            Post["SignupCustomer", "api/v1/customer/signup", runAsync : true] = async(o, ct) => {
                CustomerSignupCommand signupCommand;
                //Bind
                try {
                    signupCommand = this.Bind <CustomerSignupCommand>();
                } catch (ModelBindingException ex) {
                    return(CreateErrorResponse(b => b.WithModelBindingException(ex)));
                }

                //Validate
                InfoAccumulator info = Validate(signupCommand, SignupValidator);
                if (info.HasErrors)
                {
                    return(CreateErrorResponse(b => b.WithErrorMessages(info.GetErrors())));
                }

                //Send Command
                var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
                CustomerSignupCommandResponse response;
                try {
                    response = await SignupSendReceive.SendAsync(Config.ServiceAddress, signupCommand, cts);

                    if (response.HasErrors)
                    {
                        return(CreateErrorResponse(b => b.WithErrorMessages(response.Errors)));
                    }
                } catch (TaskCanceledException ex) {
                    Log.Error("Timeout on signup.");
                    return(CreateErrorResponse(HttpStatusCode.InternalServerError));
                }

                return(CreateOkResponse(b => b.WithCustomerId(response.CustomerId)));
            };
        }
예제 #17
0
        /// <summary>
        /// Handles the authorities upsert.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="ct">The ct.</param>
        /// <param name="isDirector">if set to <c>true</c> [is director].</param>
        /// <returns></returns>
        private async Task <Response> HandleAuthoritiesUpsert(dynamic context, CancellationToken ct, bool isDirector)
        {
            string customerId  = context.customerId;
            string authorityId = context.authorityId;
            string companyId   = context.companyId;
            CompanyUpdateAuthorityCommand command;

            //Bind
            try {
                command = this.Bind <CompanyUpdateAuthorityCommand>();
            } catch (ModelBindingException ex) {
                Log.Warn("binding error on upsert authority");
                return(CreateErrorResponse(b => b
                                           .WithCustomerId(customerId)
                                           .WithCompanyId(companyId)
                                           .WithAuthorityId(authorityId)
                                           .WithModelBindingException(ex)));
            }

            //Validate
            InfoAccumulator info = Validate(command, UpdateAuthorityValidator);

            if (info.HasErrors)
            {
                return(CreateErrorResponse(b => b
                                           .WithCustomerId(customerId)
                                           .WithCompanyId(companyId)
                                           .WithAuthorityId(authorityId)
                                           .WithErrorMessages(info.GetErrors())));
            }


            if (isDirector)
            {
                command.Authority.IsDirector = true;
            }
            else
            {
                command.Authority.IsDirector    = false;
                command.Authority.IsShareHolder = true;
            }

            //Send Command
            var cts = new CancellationTokenSource(Config.SendReceiveTaskTimeoutMilis);
            CompanyUpdateAuthorityCommandResponse response;

            try {
                response = await UpdateAuthoritySendRecieve.SendAsync(Config.ServerAddress, command, cts);

                if (response.HasErrors)
                {
                    return(CreateErrorResponse(b => b
                                               .WithCustomerId(customerId)
                                               .WithCompanyId(companyId)
                                               .WithAuthorityId(authorityId)
                                               .WithErrorMessages(response.Errors)));
                }
            } catch (TaskCanceledException) {
                Log.ErrorFormat("timeout on update {0}", command.Authority.IsDirector ? "director" : "shareholder");
                return(CreateErrorResponse(b => b
                                           .WithCustomerId(customerId)
                                           .WithCustomerId(customerId)
                                           .WithCompanyId(companyId)
                                           .WithAuthorityId(authorityId), HttpStatusCode.InternalServerError));
            }

            return(CreateOkResponse(b => b
                                    .WithCustomerId(customerId)
                                    .WithCompanyId(companyId)
                                    .WithKeyValue(() => response.AuthorityId)));
        }
 private void LogErrors(InfoAccumulator info)
 {
     Log.Error(info.GetErrors()
               .Aggregate("", (o1, o2) => o1 + o2 + ";"));
 }