예제 #1
0
        public async Task <Result> AddCompanyAsync(AddCustomerParams data)
        {
            try
            {
                var newCompany = data.GetCompany();

                var validator  = new AddCompanyValidator(_dataService);
                var valResults = validator.Validate(newCompany);

                var validationSucceeded = valResults.IsValid;
                if (!validationSucceeded)
                {
                    var failures = valResults.Errors;
                    var message  = failures.Aggregate(string.Empty, (current, failure) => current + (failure.ErrorMessage + "<br />"));
                    return(new Result {
                        IsCompleted = false, Success = false, Message = message
                    });
                }

                return(await _dataService.CompanyService.AddCompany(newCompany));
            }
            catch (Exception ex)
            {
                await _dataService.LogDataService.InsertLogoRecordAsync(nameof(AddCompanyAsync), nameof(Enums.LogLevel.Error), ex.Message, data.TransactionId, JsonConvert.SerializeObject(data));

                return(new Result(false, ex.Message));
            }
        }
예제 #2
0
        internal Result AddCompany(AddCustomerParams data)
        {
            var loggerManager = new LoggerManager();
            var operationGuid = Guid.NewGuid().ToString();

            try
            {
                loggerManager.InsertLogoRecord(nameof(AddCompany), nameof(LogLevel.Info), null, data.TransactionId, JsonConvert.SerializeObject(data));

                var orderDemandManager = new OrderDemandManager();
                var newCustomer        = new CreateCompanyData
                {
                    Address          = data.Address,
                    ContactEmail     = data.Email,
                    ContactFirstName = data.FirstName,
                    ContactLastName  = data.LastName,
                    ExternalId       = data.CompanyId,
                    Name             = data.CompanyName,
                    OrderDemandGuid  = operationGuid
                };

                var validator  = new AddCompanyValidator();
                var valResults = validator.Validate(newCustomer);

                var validationSucceeded = valResults.IsValid;
                if (!validationSucceeded)
                {
                    var failures = valResults.Errors;
                    var message  = failures.Aggregate(string.Empty, (current, failure) => current + (failure.ErrorMessage + "<br />"));
                    return(new Result {
                        IsCompleted = false, Success = false, Message = message
                    });
                }

                orderDemandManager.SaveOrderDemand(null, operationGuid, 0, (int)ProvisionType.CreateCustomer, (int)OrderDemandStates.Created, (int)OrderDemandType.Integrated, JsonConvert.SerializeObject(newCustomer), data.TransactionId);
                return(new Result {
                    IsCompleted = false, Success = true
                });
            }
            catch (Exception ex)
            {
                loggerManager.InsertLogoRecord(nameof(AddCompany), nameof(LogLevel.Error), ex.Message + " " + ex.StackTrace, operationGuid, JsonConvert.SerializeObject(data));
                return(new Result {
                    IsCompleted = true, Success = false, Message = ex.Message
                });
            }
        }