Esempio n. 1
0
        public IActionResult CreateCustomer([FromBody] Model.Sales.CreateCustomer model)
        {
            try
            {
                var customer = new Core.Domain.Sales.Customer()
                {
                    Party = new Core.Domain.Party()
                    {
                        PartyType = Core.Domain.PartyTypes.Customer,
                        Name      = model.Name,
                        Phone     = model.Phone,
                    },
                };

                _salesService.AddCustomer(customer);

                var customerModel = new Model.Sales.Customer();
                customerModel.Id    = customer.Id;
                customerModel.No    = customer.No;
                customerModel.Name  = customer.Party.Name;
                customerModel.Phone = customer.Party.Phone;

                return(new ObjectResult(customerModel));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
Esempio n. 2
0
        public IActionResult GetCustomers()
        {
            IList <Model.Sales.Customer> model = new List <Model.Sales.Customer>();

            try
            {
                var customers = _salesService.GetCustomers();
                foreach (var customer in customers)
                {
                    var customerModel = new Model.Sales.Customer()
                    {
                        Id      = customer.Id,
                        No      = customer.No,
                        Name    = customer.Party.Name,
                        Email   = customer.Party.Email,
                        Phone   = customer.Party.Phone,
                        Fax     = customer.Party.Fax,
                        Balance = customer.Balance
                    };

                    model.Add(customerModel);
                }

                return(new ObjectResult(model));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
Esempio n. 3
0
        public IActionResult GetCustomerById(int id)
        {
            try
            {
                var customer = _salesService.GetCustomerById(id);

                if (customer == null)
                {
                    return(HttpNotFound());
                }

                var customerModel = new Model.Sales.Customer()
                {
                    Id      = customer.Id,
                    No      = customer.No,
                    Name    = customer.Party.Name,
                    Email   = customer.Party.Email,
                    Phone   = customer.Party.Phone,
                    Fax     = customer.Party.Fax,
                    Balance = customer.Balance
                };

                return(new ObjectResult(customerModel));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex));
            }
        }