コード例 #1
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
 public Person CreatePerson(Person person)
 {
     try
     {
         int newId = database.CreatePerson(person.FirstName, person.LastName, person.DateOfBirth);
         return (Person)GetParty(Convert.ToString(newId));
     }
     catch (Exception ex)
     {
         throw MakeWebFaultException(ex);
     }
 }
コード例 #2
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
        public Person UpdatePerson(string idStr, Person person)
        {
            try
            {
                int id;

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

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

                database.UpdatePerson(id, person.FirstName, person.LastName, person.DateOfBirth);

                return (Person)GetParty(idStr);

            }
            catch (Exception ex)
            {
                throw MakeWebFaultException(ex);
            }
        }
コード例 #3
0
        public int CreatePerson(string firstName, string lastName, DateTime dateOfBirth)
        {
            try
            {
                using (PartyEntities context = new PartyEntities(this.connectionString))
                {
                    Person person = new Person();
                    person.FirstName = firstName;
                    person.LastName = lastName;
                    person.DateOfBirth = dateOfBirth;
                    person.Type = "P";

                    context.Parties.AddObject(person);
                    context.SaveChanges();

                    return person.Id;
                }
            }
            catch (Exception ex)
            {
                if (ex is UpdateException) { throw ex.InnerException; }
                throw;
            }
        }