Example #1
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);
            }
        }