/// <summary> /// Saves the specified person. /// </summary> /// <param name="person">The person.</param> /// <returns></returns> public void Save(PersonDTO person) { using (TransactionScope scope = new TransactionScope()) using (SqlConnection conn = new SqlConnection(__connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("usp_addperson", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@firstname", SqlDbType.VarChar, firstnameParamSize, "firstname")).Value = person.Firstname; cmd.Parameters.Add(new SqlParameter("@surname", SqlDbType.VarChar, surnameParamSize, "surname")).Value = person.Surname; cmd.Parameters.Add(new SqlParameter("@address1", SqlDbType.VarChar, address1ParamSize, "address1")).Value = person.Address.Address1; cmd.Parameters.Add(new SqlParameter("@address2", SqlDbType.VarChar, address2ParamSize, "address2")).Value = person.Address.Address2; cmd.Parameters.Add(new SqlParameter("@address3", SqlDbType.VarChar, address3ParamSize, "address3")).Value = person.Address.Address3; cmd.Parameters.Add(new SqlParameter("@country", SqlDbType.VarChar, countryParamSize, "country")).Value = person.Address.Country; cmd.Parameters.Add(new SqlParameter("@city", SqlDbType.VarChar, cityParamSize, "city")).Value = person.Address.City; cmd.Parameters.Add(new SqlParameter("@postcode", SqlDbType.VarChar, postcodeParamSize, "postcode")).Value = person.Address.Postcode; person.PersonID = Convert.ToInt32(cmd.ExecuteScalar()); scope.Complete(); } }
/// <summary> /// Inserts the person and order. /// </summary> /// <returns></returns> private bool InsertPersonAndOrder() { PersonDAL personDAL = new PersonDAL(ConfigurationManager.ConnectionStrings["trainingConnectionString"].ConnectionString); PersonDTO personDTO = new PersonDTO(); personDTO.Firstname = Server.HtmlEncode(FirstName.Text); personDTO.Surname = Server.HtmlEncode(Surname.Text); personDTO.Address = new AddressDTO(); personDTO.Address.Address1 = Server.HtmlEncode(Address1.Text); personDTO.Address.Address2 = Server.HtmlEncode(Address2.Text); personDTO.Address.Address3 = Server.HtmlEncode(Address3.Text); personDTO.Address.City = Server.HtmlEncode(City.Text); personDTO.Address.Country = Server.HtmlEncode(Country.Text); personDTO.Address.Postcode = Server.HtmlEncode(PostCode.Text); try { personDAL.Save(personDTO); } catch (Exception ex) { throw ex; } try { OrderDAL orderDAL = new OrderDAL(ConfigurationManager.ConnectionStrings["trainingConnectionString"].ConnectionString); OrderDTO orderDTO = new OrderDTO(); orderDTO.PersonID = personDTO.PersonID; orderDTO.OrderLines = GetValues(); orderDAL.Save(orderDTO); } catch (Exception ex) { throw ex; //new System.ArgumentException("An error occured when saving an order"); } return true; }