public int insertPhoneSale(PhoneSale phoneSale) { SqlConnection connection = new SqlConnection(this.connectionString); string sqlStoredProcedure = "PAInsert_SaleXPhones"; SqlCommand cmdInsert = new SqlCommand(sqlStoredProcedure, connection); cmdInsert.CommandType = CommandType.StoredProcedure; cmdInsert.Parameters.Add(new SqlParameter("@idsale", phoneSale.Sale.IdSale)); cmdInsert.Parameters.Add(new SqlParameter("@idPhone", phoneSale.Phone.IdPhone)); cmdInsert.Parameters.Add(new SqlParameter("@quantity", phoneSale.Quantity)); SqlParameter parameterCode = new SqlParameter("@idPhoneSale", SqlDbType.Int); parameterCode.Direction = ParameterDirection.Output; cmdInsert.Parameters.Add(parameterCode); cmdInsert.Connection.Open(); cmdInsert.ExecuteNonQuery(); int answer = Int32.Parse(cmdInsert.Parameters["@idPhoneSale"].Value.ToString()); cmdInsert.Connection.Close(); return(answer); }
public string registerSale(string idClient, string phonesQuantities, string total, string key) { EncryptionMethods em = new EncryptionMethods(); string conn = WebConfigurationManager.ConnectionStrings["KeggPhonesConnectionString"].ToString(); ClientBusiness cb = new ClientBusiness(conn); SaleBusiness sb = new SaleBusiness(conn); PhoneSaleBusiness psb = new PhoneSaleBusiness(conn); PhoneBusiness pb = new PhoneBusiness(conn); Client client = cb.getClientById(Int32.Parse(em.decrypting(idClient, key))); Sale sale = new Sale(0, client, Int32.Parse(em.decrypting(total, key)), DateTime.Today.ToString()); int r = sb.insertSale(sale); sale.IdSale = r; string phonesQ = em.decrypting(phonesQuantities, key); string[] phones = phonesQ.Split('#'); for (int i = 0; i < phones.Length; i++) { string[] data = phones[i].Split(';'); Phone phone = pb.getPhoneById(Int32.Parse(data[0])); PhoneSale ps = new PhoneSale(0, phone, sale, Int32.Parse(data[1])); psb.insertPhoneSale(ps); } string response = "1"; return(em.encrypt(response, key)); }
public int insertPhoneSale(PhoneSale phoneSale) { return(PhoneSaleData.insertPhoneSale(phoneSale)); }