Exemplo n.º 1
0
 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);
     }
 }
        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;
            }
        }
Exemplo n.º 3
0
        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);
            }
        }