public CustomerAPIViewModel CreateWithContrans(string cardcode, CustomerAPIViewModel customer)
        {
            #region call service
            var customerService = this.Service<ICustomerService>();
            var mbsCardService = this.Service<IMembershipService>();
            var accountService = this.Service<IAccountService>();
            var cardService = this.Service<ICardService>();
            #endregion
            int id;
            var customerVM = new CustomerAPIViewModel();
            using (var trans = new TransactionScope(TransactionScopeOption.Required))
            {


                var entity = customer.ToEntity();
                try
                {
                    #region Check phone and email exist
                    // check phone exist //
                    if (!string.IsNullOrEmpty(customer.AccountPhone))
                    {
                        var customerCheck = customerService.GetCustomersByAccountPhone(customer.AccountPhone, customer.BrandId.Value);
                        if (customerCheck != null)
                        {
                            throw ApiException.Get(false, ConstantManager.MES_CUSTOMER_PHONE_EXIST, ResultEnum.CreateFail, HttpStatusCode.BadRequest);
                        }
                    }

                    // check email exist
                    if (!string.IsNullOrEmpty(customer.Email))
                    {
                        var customerCheck = customerService.GetCustomerByEmail(customer.Email, customer.BrandId.Value);
                        if (customerCheck != null)
                        {
                            throw ApiException.Get(false, ConstantManager.MES_CUSTOMER_EMAIL_EXIST, ResultEnum.CreateFail, HttpStatusCode.BadRequest);
                        }
                    }
                    #endregion

                    // Create Customer
                    id = customerService.CreateCustomer(entity);
                    // create Membership
                    var mbsCard = mbsCardService.AddMembership(id, (int)MembershipCardTypeEnum.Newbie);
                    // create Card
                    var newCard = cardService.AddCard(cardcode, customer.BrandId.Value, mbsCard, (int)CardTypeEnum.MobieCard);
                    // create Account Creadit and Point Member
                    accountService.CreateAccountByMemCard(mbsCard.MembershipCode, 0, customer.BrandId.Value, mbsCard.Id, (int)AccountTypeEnum.CreditAccount);
                    accountService.CreateAccountByMemCard(mbsCard.MembershipCode, 0, customer.BrandId.Value, mbsCard.Id, (int)AccountTypeEnum.PointAccount);
                    // End Transaction
                    trans.Complete();
                    trans.Dispose();

                }

                catch (Exception ex)
                {
                    // roll back transaction
                    trans.Dispose();
                    Console.WriteLine("Error Create : " + ex);
                    if (ex is ApiException)
                    {
                        throw ex;
                    }
                    else
                    {
                        throw ApiException.Get(false, ex.ToString(), ResultEnum.CreateFail, HttpStatusCode.InternalServerError);
                    }

                }
               


            }
            //customerVM = customerService.GetCustomerById(id);
            //if (customerVM == null)
            //{
            //    throw ApiException.Get(false, ConstantManager.MES_LOGIN_FAIL, ResultEnum.CreateFail, HttpStatusCode.BadRequest);
            //}
            customerVM = customerService.GetCustomerById(id);
            if(customerVM != null)
            {
                return customerVM;
            }
            return null;
            //return customerVM;
        }
 public int AddCustomer(CustomerAPIViewModel customer)
 {
     var customerService = this.Service<ICustomerService>();
     var entity = customer.ToEntity();
     return customerService.CreateCustomer(entity);
 }