Ejemplo n.º 1
0
        private async Task LoadCustomers()
        {
            IsBusy = true;
            try
            {
                var list = await _customerRepo.GetCustomersAsync();

                CustomerList = await CustomersMapper.Map(list);

                CustomersView = CollectionViewSource.GetDefaultView(CustomerList);

                if (CustomerList.Count >= SelectedIndex)
                {
                    SelectedCustomer = CustomerList[SelectedIndex];
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
        public CustomerViewEntity GetById(int customerId)
        {
            CustomerDTO customerDTO = new CustomerDTO();

            var customer = _customerRepository.GetById(customerId);

            Core.Entities.EF.Person person = null;
            Core.Entities.EF.Store  store  = null;
            if (customer.PersonId != null)
            {
                person = _peopleRepository.GetById((int)customer.PersonId);
            }
            if (customer.StoreId != null)
            {
                store = _storeRepository.GetById((int)customer.StoreId);
            }

            customerDTO = new CustomerDTO()
            {
                CustomerId = customer.CustomerId,
                FirstName  = person?.FirstName,
                MiddleName = person?.MiddleName,
                LastName   = person?.LastName,
                StoreName  = store?.Name,
                Title      = person?.Title
            };

            return(CustomersMapper.MapTo(customerDTO));
        }
        public IEnumerable <CustomerViewEntity> GetAll(int?numberOfResult = null)
        {
            IEnumerable <CustomerDTO> customerDTO = new List <CustomerDTO>();

            customerDTO = numberOfResult == null?_customerRepository.GetAllCustomer() : _customerRepository.GetAllCustomer().Take((int)numberOfResult);

            return(CustomersMapper.MapTo(customerDTO));
        }
Ejemplo n.º 4
0
        public int Add(CustomerRequest customerRequest)
        {
            if (!customerRequest.PersonId.HasValue && !customerRequest.StoreId.HasValue)
            {
                throw new ArgumentException($"Neither {nameof(customerRequest.PersonId)} nor {nameof(customerRequest.StoreId)} have value");
            }

            var customer = CustomersMapper.MapTo(customerRequest);

            customer.ModifiedDate = DateTime.Now;

            var customerRepository = _uow.GetCustomerRepository();

            customerRepository.Add(customer);
            _uow.SaveChanges();

            return(customer.CustomerId);
        }