public IActionResult Customers()
        {
            IList <Dto.Sales.Customer> customersDto = new List <Dto.Sales.Customer>();

            try
            {
                var customers = _salesService.GetCustomers().Where(p => p.Party != null);
                foreach (var customer in customers)
                {
                    var customerDto = new Dto.Sales.Customer()
                    {
                        Id = customer.Id,
                        No = customer.No,
                    };

                    customerDto.Name                = customer.Party.Name;
                    customerDto.Email               = customer.Party.Email;
                    customerDto.Website             = customer.Party.Website;
                    customerDto.Phone               = customer.Party.Phone;
                    customerDto.Fax                 = customer.Party.Fax;
                    customerDto.Balance             = customer.Balance;
                    customerDto.PrepaymentAccountId = customer.CustomerAdvancesAccountId;
                    customerDto.Contact             = customer.PrimaryContact.FirstName + " " + customer.PrimaryContact.LastName;
                    customerDto.TaxGroup            = customer.TaxGroup == null ? string.Empty : customer.TaxGroup.Description;
                    customersDto.Add(customerDto);
                }

                return(new ObjectResult(customersDto));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
        public IActionResult Customer(int id)
        {
            try
            {
                var customer = _salesService.GetCustomerById(id);

                var customerDto = new Dto.Sales.Customer()
                {
                    Id = customer.Id,
                    No = customer.No,
                    AccountsReceivableId   = customer.AccountsReceivableAccountId.GetValueOrDefault(),
                    SalesAccountId         = customer.SalesAccountId.GetValueOrDefault(),
                    PrepaymentAccountId    = customer.CustomerAdvancesAccountId.GetValueOrDefault(),
                    SalesDiscountAccountId = customer.SalesDiscountAccountId.GetValueOrDefault(),
                    PaymentTermId          = customer.PaymentTermId.GetValueOrDefault(),
                    TaxGroupId             = customer.TaxGroupId.GetValueOrDefault()
                };
                customerDto.Name    = customer.Party.Name;
                customerDto.Email   = customer.Party.Email;
                customerDto.Website = customer.Party.Website;
                customerDto.Phone   = customer.Party.Phone;
                customerDto.Fax     = customer.Party.Fax;

                if (customer.PrimaryContact != null)
                {
                    customerDto.PrimaryContact.FirstName     = customer.PrimaryContact.FirstName;
                    customerDto.PrimaryContact.LastName      = customer.PrimaryContact.LastName;
                    customerDto.PrimaryContact.Party.Email   = customer.PrimaryContact.Party.Email;
                    customerDto.PrimaryContact.Party.Phone   = customer.PrimaryContact.Party.Phone;
                    customerDto.PrimaryContact.Party.Fax     = customer.PrimaryContact.Party.Fax;
                    customerDto.PrimaryContact.Party.Website = customer.PrimaryContact.Party.Website;
                    customerDto.PrimaryContact.Party.Name    = customer.PrimaryContact.Party.Name;
                }

                return(new ObjectResult(customerDto));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex));
            }
        }
        public IActionResult SaveCustomer([FromBody] Dto.Sales.Customer customerDto)
        {
            bool isNew = customerDto.Id == 0;

            Core.Domain.Sales.Customer customer = null;

            if (isNew)
            {
                customer = new Core.Domain.Sales.Customer();

                customer.Party = new Core.Domain.Party()
                {
                    PartyType = Core.Domain.PartyTypes.Customer,
                };

                customer.PrimaryContact = new Core.Domain.Contact()
                {
                    ContactType = Core.Domain.ContactTypes.Customer,
                    Party       = new Core.Domain.Party()
                    {
                        PartyType = Core.Domain.PartyTypes.Contact
                    }
                };
            }
            else
            {
                customer = _salesService.GetCustomerById(customerDto.Id);
            }

            customer.No                           = customerDto.No;
            customer.Party.Name                   = customerDto.Name;
            customer.Party.Phone                  = customerDto.Phone;
            customer.Party.Email                  = customerDto.Email;
            customer.Party.Fax                    = customerDto.Fax;
            customer.Party.Website                = customerDto.Website;
            customer.PrimaryContact.FirstName     = customerDto.PrimaryContact.FirstName;
            customer.PrimaryContact.LastName      = customerDto.PrimaryContact.LastName;
            customer.PrimaryContact.Party.Name    = customerDto.PrimaryContact.Party.Name;
            customer.PrimaryContact.Party.Phone   = customerDto.PrimaryContact.Party.Phone;
            customer.PrimaryContact.Party.Email   = customerDto.PrimaryContact.Party.Email;
            customer.PrimaryContact.Party.Fax     = customerDto.PrimaryContact.Party.Fax;
            customer.PrimaryContact.Party.Website = customerDto.PrimaryContact.Party.Website;
            customer.AccountsReceivableAccountId  = customerDto.AccountsReceivableId;
            customer.SalesAccountId               = customerDto.SalesAccountId;
            customer.CustomerAdvancesAccountId    = customerDto.PrepaymentAccountId;
            customer.SalesDiscountAccountId       = customerDto.SalesDiscountAccountId;
            customer.PaymentTermId                = customerDto.PaymentTermId;
            customer.TaxGroupId                   = customerDto.TaxGroupId;
            customer.ModifiedBy                   = GetUserNameFromRequestHeader();

            if (isNew)
            {
                _salesService.AddCustomer(customer);
            }
            else
            {
                _salesService.UpdateCustomer(customer);
            }

            return(Ok());
        }