示例#1
0
 public void SetCustomer(Domain.Entities.Customer customer)
 {
     SetCustomerId(customer.Id);
     if (Item != null)
     {
         Item.Customer = customer;
     }
 }
示例#2
0
        public Task <Unit> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = new Domain.Entities.Customer(request.Name, request.Surname, request.PhoneNumber,
                                                        request.Email, request.Nationality);

            _unitOfWork.Add(customer);
            _unitOfWork.Commit();

            return(Task.FromResult(Unit.Value));
        }
        public void ErrorAuthenticateUserEmailOrPasswordInvalid()
        {
            Domain.Entities.Customer customer = null;
            _userRepo.Setup((s) => s.Authenticate(It.IsAny <Domain.Entities.User>())).Returns(Task.FromResult(customer));

            var command       = new AuthenticateUserCommand("[email protected]", "abc123", _appSettings);
            var commandResult = new UserCommandHandler(_mapper, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(2004));
        }
示例#4
0
        public void ErrorUpdateCustomerIdUserNotExists()
        {
            _customerRepo.Setup(s => s.IdCustomerExists(It.IsAny <int>())).Returns(Task.FromResult(true));
            var customer = new Domain.Entities.Customer(1, 1, "MY NAME", "MY ADDRESS");

            _customerRepo.Setup(s => s.GetCustomer(It.IsAny <int>())).Returns(Task.FromResult(customer));
            _userRepo.Setup((s) => s.IdUserExists(It.IsAny <int>())).Returns(Task.FromResult(false));

            var command       = new UpdateCustomerCommand(1, "Luciano Pereira", "[email protected]", "abc123", "New York", true, _appSettings);
            var commandResult = new CustomerCommandHandler(_mapper, _customerRepo.Object, _userRepo.Object)
                                .Handle(command, new CancellationToken()).Result;

            Assert.True(commandResult.HasError(2000));
        }
示例#5
0
            public async Task <Unit> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
            {
                var entity = new Domain.Entities.Customer
                {
                    Cpf  = request.Cpf,
                    Name = request.Name
                };

                _context.Customers.Add(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
        public async Task <bool> CreateAsync(CreateCustomerRequest request)
        {
            var entity = new Domain.Entities.Customer()
            {
                Address = request.CustomerModel.Address,
                Name    = request.CustomerModel.Name,
                Phone   = request.CustomerModel.Phone,
                POCode  = request.CustomerModel.POCode
            };

            await _dbContext.Customers.AddAsync(entity);

            await _dbContext.SaveChangesAsync();

            return(true);
        }
示例#7
0
            public async Task <Unit> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
            {
                var entity = new Domain.Entities.Customer
                {
                    CustomerId  = request.Id,
                    ContactName = request.ContactName
                };

                _context.Customers.Add(entity);

                await _context.SaveChangesAsync(cancellationToken);

                await _mediator.Publish(new CustomerCreated { CustomerId = entity.CustomerId }, cancellationToken);

                return(Unit.Value);
            }
示例#8
0
        public async Task <CreateCustomerResponse> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            var customer = new Domain.Entities.Customer()
            {
                Id = new Guid(), FirstName = request.FirstName, LastName = request.LastName
            };

            _context.Customers.Add(customer);
            await _context.SaveChangesAsync(cancellationToken);

            var response = new CreateCustomerResponse()
            {
                Id = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, CreatedAt = customer.CreatedAt, UpdatedAt = customer.UpdatedAt
            };

            return(response);
        }
示例#9
0
        public bool CreateCustomer(Domain.Entities.Customer customer, bool real_time_update)
        {
            _customerRepository.Upsert(customer);

            if (real_time_update)
            {
                //var current = GetById(customer.business_id, customer.id);
                //if (current != null) _counterService.UpdateCustomerCounters(customer.business_id, current, true);
                //_counterService.UpdateCustomerCounters(customer.business_id, customer, false);
                try
                {
                    CopyCustomerToRealTimeDB(customer.business_id, customer);
                }
                catch
                {
                    BackgroundJob.Enqueue <CustomerService>(x => x.CopyCustomerToRealTimeDB(customer.business_id, customer.id));
                }
            }

            return(true);
        }
示例#10
0
        public Customer CreateCustomer(string business_id, string customer_id, Thread thread, bool real_time_update)
        {
            var customer = GetById(business_id, customer_id);

            if (customer == null)
            {
                customer = new Domain.Entities.Customer
                {
                    id           = customer_id,
                    ext_id       = thread.owner_ext_id,
                    app_id       = thread.owner_app_id,
                    name         = thread.owner_name,
                    avatar       = thread.owner_avatar,
                    timestamp    = thread.timestamp,
                    business_id  = business_id,
                    channel_id   = thread.channel_id,
                    created_time = thread.created_time,
                    updated_time = thread.updated_time
                };
            }
            return(CreateCustomer(customer, thread, real_time_update).Result);
        }
示例#11
0
        public Customer CreateCustomer(string business_id, string customer_id, Message message)
        {
            string owner_id = (message.author == message.channel_id ? business_id + "_" + message.recipient_id : message.author);
            var    customer = GetById(business_id, customer_id);

            if (customer == null)
            {
                customer = new Domain.Entities.Customer
                {
                    id          = customer_id,
                    business_id = business_id
                };
            }
            customer.ext_id       = customer.ext_id == message.author ? message.sender_id : message.channel_ext_id;
            customer.avatar       = customer.ext_id == message.author ? message.sender_avatar ?? customer.avatar : customer.avatar;
            customer.name         = customer.ext_id == message.author ? message.sender_name ?? customer.name : customer.name;
            customer.updated_time = message.created_time;
            customer.timestamp    = message.timestamp;

            CreateCustomer(customer);

            return(customer);
        }
示例#12
0
        public async Task <BaseDto <CustomerInput> > Handle(BaseRequest <CustomerInput> request, CancellationToken cancellationToken)
        {
            var input    = request.data.attributes;
            var customer = new Domain.Entities.Customer
            {
                full_name    = input.full_name,
                username     = input.username,
                birthdate    = input.birthdate,
                password     = input.password,
                gender       = input.gender,
                email        = input.email,
                phone_number = input.phone_number
            };

            _context.customers.Add(customer);
            await _context.SaveChangesAsync(cancellationToken);

            return(new BaseDto <CustomerInput>
            {
                Message = "Success add customer data",
                Status = true,
                Data = input
            });
        }
        public async Task <Customer> GetCustomer(Channel channel, ZaloMessage msg, Customer customer, string customer_ext_id)
        {
            string  business_id = channel.business_id;
            string  channel_id  = channel.id;
            var     timestamp   = msg.timestamp;
            var     time        = Core.Helpers.CommonHelper.UnixTimestampToDateTime(timestamp);
            dynamic profile     = null;

            if (customer == null)
            {
                var customer_id = CustomerService.FormatId01(business_id, customer_ext_id);

                profile = await GetProfile(customer_ext_id, Convert.ToInt64(channel.ext_id), channel.token);

                if (profile == null)
                {
                    return(null);
                }
                DateTime birthDate = DateTime.MinValue;
                try
                {
                    var birth = (long)profile.data.birthDate;
                    birthDate = Core.Helpers.CommonHelper.UnixTimestampToDateTime(birth);
                }
                catch { }
                customer = new Domain.Entities.Customer
                {
                    id           = customer_id,
                    global_id    = customer_id,
                    ext_id       = customer_ext_id,
                    app_id       = msg.appid.ToString(),
                    business_id  = business_id,
                    channel_id   = channel_id,
                    status       = "pending",
                    created_time = time,
                    updated_time = time,
                    unread       = true,
                    nonreply     = true,
                    birthdate    = birthDate,
                    timestamp    = timestamp
                };
            }

            if ((string.IsNullOrWhiteSpace(customer.name) || string.IsNullOrWhiteSpace(customer.avatar) || string.IsNullOrWhiteSpace(customer.sex)))
            {
                if (profile != null)
                {
                    customer.updated_time = time;
                    customer.timestamp    = timestamp;
                    if (string.IsNullOrWhiteSpace(customer.avatar))
                    {
                        customer.avatar = string.IsNullOrWhiteSpace(customer.avatar) ? profile.data.avatar : customer.avatar;
                    }

                    var url = customer.avatar;
                    if (!string.IsNullOrWhiteSpace(url) && !url.Contains("hibaza") && !url.Contains("firebase"))
                    {
                        try
                        {
                            customer.avatar = await DownloadToLocalAsync(url);
                        }
                        catch { }
                    }
                    if (string.IsNullOrWhiteSpace(customer.name))
                    {
                        customer.name = profile.data.displayName;
                    }
                    if (string.IsNullOrWhiteSpace(customer.sex))
                    {
                        customer.sex = (string)profile.data.userGender == "1" ? "male" : "female";
                    }
                }
            }
            return(customer);
        }
示例#14
0
 public void Delete(DomainCustomer customer)
 {
     context.Customers.Remove(context.Customers.Find(customer.Id));
 }
        public async Task <Response <int> > Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
        {
            var currentUserLogin = await _authenticatedUserService.GetCurentApplicationUser();

            Domain.Entities.Customer customer = null;

            if (request.CompanyId.HasValue)
            {
                if (request.CompanyId.Value == currentUserLogin.CompanyId)
                {
                    throw new ApiException("Can not add your company to customer list");
                }

                var company = await _companyRepository.GetByIdAsync(request.CompanyId.Value);

                if (company is null)
                {
                    throw new ApiException("Company ID does not exist.");
                }

                bool isExist = await _customerRepository.Exist(currentUserLogin.CompanyId.Value, company.Id);

                if (isExist)
                {
                    throw new ApiException($"{company.Name} already added to customer list.");
                }

                customer = new Domain.Entities.Customer
                {
                    CompanyId         = company.Id,
                    BelongToCompanyId = currentUserLogin.CompanyId.GetValueOrDefault(),
                    Address           = company.Address,
                    BankAccount       = company.BankAccount,
                    BusinessLicense   = company.BusinessLicense,
                    Email             = company.Email,
                    Name          = company.Name,
                    PhoneNumber   = company.PhoneNumber,
                    TaxCode       = company.TaxCode,
                    Representaive = company.Representaive
                };
            }
            else
            {
                customer = new Domain.Entities.Customer
                {
                    BelongToCompanyId = currentUserLogin.CompanyId.GetValueOrDefault(),
                    Address           = request.Address,
                    BankAccount       = request.BankAccount,
                    BusinessLicense   = request.BusinessLicense,
                    Email             = request.Email,
                    Name          = request.Name,
                    PhoneNumber   = request.PhoneNumber,
                    TaxCode       = request.TaxCode,
                    Representaive = request.Representaive
                };
            }

            await _customerRepository.AddAsync(customer);

            return(new Response <int>(customer.Id));
        }
示例#16
0
 public bool CreateCustomer(Domain.Entities.Customer customer)
 {
     _customerRepository.Upsert(customer.business_id, customer);
     return(true);
 }