Ejemplo n.º 1
0
 public Address CreateAddress(Address address)
 {
     try
     {
         int newId = database.CreateAddress(address.Street, address.Town, address.County, address.PostCode);
         return (Address)GetContact(Convert.ToString(newId));
     }
     catch (Exception ex)
     {
         throw MakeWebFaultException(ex);
     }
 }
        public int CreateAddress(string street, string town, string county, string postCode)
        {
            try
            {
                using (PartyEntities context = new PartyEntities(this.connectionString))
                {
                    Address address = new Address();
                    address.Street = street;
                    address.Town = town;
                    address.County = county;
                    address.PostCode = postCode;
                    address.Type = "A";

                    context.Contacts.AddObject(address);
                    context.SaveChanges();
                    return address.Id;
                }
            }
            catch (Exception ex)
            {
                if (ex is UpdateException) { throw ex.InnerException; }
                throw;
            }
        }
Ejemplo n.º 3
0
        public Address UpdateAddress(string idStr, Address address)
        {
            try
            {
                int id;

                if (!int.TryParse(idStr, out id))
                {
                    throw (new WebFaultException<Error>(
                        new Error(string.Format("'{0}' is not a valid contact identifier", idStr)),
                        HttpStatusCode.OK));
                }

                if (database.GetContact(id) == null)
                {
                    throw (new WebFaultException<Error>(
                        new Error(string.Format("Address {0} not found", id)),
                        HttpStatusCode.OK));
                }

                database.UpdateAddress(id, address.Street, address.Town, address.County, address.PostCode);

                return (Address)GetContact(idStr);
            }
            catch (Exception ex)
            {
                throw MakeWebFaultException(ex);
            }
        }