コード例 #1
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
 public Business CreateBusiness(Business business)
 {
     try
     {
         int newId = database.CreateBusiness(business.Name, business.RegNumber);
         return (Business)GetParty(Convert.ToString(newId));
     }
     catch (Exception ex)
     {
         throw MakeWebFaultException(ex);
     }
 }
コード例 #2
0
        public int CreateBusiness(string name, string regNumber)
        {
            try
            {
                using (PartyEntities context = new PartyEntities(this.connectionString))
                {
                    Business business = new Business();
                    business.Name = name;
                    business.RegNumber = regNumber;
                    business.Type = "B";

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

                    return business.Id;
                }

            }
            catch (Exception ex)
            {
                if (ex is UpdateException) { throw ex.InnerException; }
                throw;
            }
        }
コード例 #3
0
ファイル: Service.cs プロジェクト: offspin/building_blocks
        public Business UpdateBusiness(string idStr, Business business)
        {
            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("Business {0} not found", id)),
                        HttpStatusCode.OK));
                }

                database.UpdateBusiness(id, business.Name, business.RegNumber);

                return (Business)GetParty(idStr);
            }
            catch (Exception ex)
            {
                throw MakeWebFaultException(ex);
            }
        }