Exemplo n.º 1
0
        public AddressModel Post([FromBody] AddressModel model, int id = 0)
        {
            Address      addr   = DataSession.Single <Address>(model.AddressID);
            AddressModel result = null;

            if (addr != null)
            {
                addr.City            = model.City;
                addr.Country         = model.Country;
                addr.InternalAddress = model.Attention;
                addr.State           = model.State;
                addr.StrAddress1     = model.StreetAddress1;
                addr.StrAddress2     = model.StreetAddress2;
                addr.Zip             = model.Zip;
                DataSession.SaveOrUpdate(addr);
                result = ApiUtility.CreateAddressModel("client", addr);
            }
            else
            {
                //add a new address to this ClientOrg
                ClientOrg co = DataSession.Single <ClientOrg>(id);
                if (co != null)
                {
                    addr = new Address()
                    {
                        City            = model.City,
                        Country         = model.Country,
                        InternalAddress = model.Attention,
                        State           = model.State,
                        StrAddress1     = model.StreetAddress1,
                        StrAddress2     = model.StreetAddress2,
                        Zip             = model.Zip
                    };

                    DataSession.SaveOrUpdate(addr);

                    co.ClientAddressID = addr.AddressID;

                    DataSession.SaveOrUpdate(co);

                    result = ApiUtility.CreateAddressModel("client", addr);
                }
            }

            return(result);
        }