Exemple #1
0
        public async Task Change(Customer customer, CustomerExternalLogin customerExternalLogin)
        {
            bool isChanged = await _customerRepository.Change(customer, customerExternalLogin);

            if (!isChanged)
            {
                throw new MessageException(ResourceKey.Customer_Version_Changed);
            }
        }
 public async Task <bool> Change(Customer customer, CustomerExternalLogin customerExternalLogin)
 {
     return(await WithConnection(async (connection, transaction) =>
     {
         DynamicParameters parameters = new DynamicParameters();
         parameters.Add("@CustomerId", customer.Id, DbType.String);
         parameters.Add("@VERSION", customer.Version, DbType.Int32);
         int rowCount = await connection.ExecuteAsync(ProcName.Customer_ChangeVersion, parameters, transaction, commandType: CommandType.StoredProcedure);
         if (rowCount == 0)
         {
             throw new MessageException(ResourceKey.Customer_Version_Changed);
         }
         parameters = new DynamicParameters();
         parameters.Add("@LoginProvider", customerExternalLogin.LoginProvider.AsEnumToInt(), DbType.Int32);
         parameters.Add("@ProviderKey", customerExternalLogin.ProviderKey, DbType.String);
         parameters.Add("@ProviderDisplayName", customerExternalLogin.ProviderDisplayName, DbType.String);
         parameters.Add("@CustomerId", customerExternalLogin.CustomerId, DbType.String);
         parameters.Add("@Info", customerExternalLogin.Info, DbType.String);
         await connection.ExecuteAsync(ProcName.CustomerExternalLogin_Add, parameters, transaction, commandType: CommandType.StoredProcedure);
         return true;
     }));
 }
Exemple #3
0
        public async Task <ICommandResult> Handle(CustomerExternalLoginAddCommand mesage)
        {
            try
            {
                ICommandResult result;
                RCustomer      customerFromDb = await _customerService.GetFromDb(mesage.CustomerId);

                if (customerFromDb == null)
                {
                    result = new CommandResult()
                    {
                        Message      = "",
                        ObjectId     = "",
                        Status       = CommandResult.StatusEnum.Fail,
                        ResourceName = ResourceKey.Customer_NotExist
                    };
                    return(result);
                }
                customerFromDb.CustomerExternalLogins = await _customerService.GetCustomerExternalLoginByCustomerId(customerFromDb.Id);

                Customer customer = new Customer(customerFromDb);
                CustomerExternalLogin customerExternalLogin = customer.AddExternalLogin(mesage);
                if (customerExternalLogin != null)
                {
                    await _customerService.Change(customer, customerExternalLogin);
                }
                if (!string.IsNullOrEmpty(mesage.VerifyId))
                {
                    RVerify rverify = await _emailSmsService.GetVerifyFromDb(mesage.VerifyId);

                    if (rverify != null)
                    {
                        Verify verify = new Verify(rverify);
                        verify.ChangeStatusToVerified();
                        await _emailSmsService.ChangeVerifyStatus(verify.Id, verify.Status);
                    }
                }
                result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = customer.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (MessageException e)
            {
                e.Data["Param"] = mesage;
                ICommandResult result = new CommandResult()
                {
                    Message      = e.Message,
                    Status       = CommandResult.StatusEnum.Fail,
                    ResourceName = e.ResourceName
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = mesage;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }