コード例 #1
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
        public Telephone UpdateTelephone(string idStr, Telephone telephone)
        {
            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("Telephone {0} not found", id)),
                               HttpStatusCode.OK));
                }

                database.UpdateTelephone(id, telephone.SubType, telephone.Number);

                return((Telephone)GetContact(idStr));
            }
            catch (Exception ex)
            {
                throw MakeWebFaultException(ex);
            }
        }
コード例 #2
0
        public void UpdateTelephone(int id, string type, string number)
        {
            try
            {
                using (PartyEntities context = new PartyEntities(this.connectionString))
                {
                    Telephone telephone = (Telephone)
                                          (from t in context.Contacts
                                           where t.Id == id
                                           select t).First();

                    if (telephone != null)
                    {
                        telephone.Number  = number;
                        telephone.SubType = type;
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is UpdateException)
                {
                    throw ex.InnerException;
                }
                throw;
            }
        }
コード例 #3
0
        public int CreateTelephone(string type, string number)
        {
            try
            {
                using (PartyEntities context = new PartyEntities(this.connectionString))
                {
                    Telephone telephone = new Telephone();
                    telephone.Number  = number;
                    telephone.SubType = type;
                    telephone.Type    = "T";

                    context.Contacts.AddObject(telephone);
                    context.SaveChanges();
                    return(telephone.Id);
                }
            }
            catch (Exception ex)
            {
                if (ex is UpdateException)
                {
                    throw ex.InnerException;
                }
                throw;
            }
        }
コード例 #4
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
 public Telephone CreateTelephone(Telephone telephone)
 {
     try
     {
         int newId = database.CreateTelephone(telephone.SubType, telephone.Number);
         return((Telephone)GetContact(Convert.ToString(newId)));
     }
     catch (Exception ex)
     {
         throw MakeWebFaultException(ex);
     }
 }
コード例 #5
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
 public Telephone CreateTelephone(Telephone telephone)
 {
     try
     {
         int newId = database.CreateTelephone(telephone.SubType, telephone.Number);
         return (Telephone)GetContact(Convert.ToString(newId));
     }
     catch (Exception ex)
     {
         throw MakeWebFaultException(ex);
     }
 }
コード例 #6
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
        public Telephone UpdateTelephone(string idStr, Telephone telephone)
        {
            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("Telephone {0} not found", id)),
                        HttpStatusCode.OK));
                }

                database.UpdateTelephone(id, telephone.SubType, telephone.Number);

                return (Telephone)GetContact(idStr);
            }
            catch (Exception ex)
            {
                throw MakeWebFaultException(ex);
            }
        }
コード例 #7
0
        public int CreateTelephone(string type, string number)
        {
            try
            {
                using (PartyEntities context = new PartyEntities(this.connectionString))
                {
                    Telephone telephone = new Telephone();
                    telephone.Number = number;
                    telephone.SubType = type;
                    telephone.Type = "T";

                    context.Contacts.AddObject(telephone);
                    context.SaveChanges();
                    return telephone.Id;
                }
            }
            catch (Exception ex)
            {
                if (ex is UpdateException) { throw ex.InnerException; }
                throw;
            }
        }