Esempio n. 1
0
        /// <summary>
        /// Updates orders
        /// </summary>
        /// <param name="order"></param>
        public void UpdateOrder(Order order)
        {
            using (SqlConnection conn = CreateConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("appSchema.uspUpdateOrder", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    conn.Open();
                    cmd.Parameters.Add("@OrderID", SqlDbType.Int, 4).Value = order.OrderID;
                    cmd.Parameters.Add("@UserID", SqlDbType.Int, 4).Value = order.UserID;
                    cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = order.Name;
                    cmd.Parameters.Add("@Date", SqlDbType.DateTime,8).Value = order.Date;
                    cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 30).Value = order.Address;
                    cmd.Parameters.Add("@Postnumber", SqlDbType.NVarChar, 6).Value = order.Postnumber;
                    cmd.Parameters.Add("@City", SqlDbType.NVarChar, 20).Value = order.City;
                    cmd.Parameters.Add("@PaymentID", SqlDbType.Int, 4).Value = order.PaymentID;
                    cmd.Parameters.Add("@StatusID", SqlDbType.Int, 4).Value = order.StatusID;
                    cmd.ExecuteNonQuery();

                }
                catch
                {
                    throw new ApplicationException("An error occured in the data access layer.");
                }
            }
        }
Esempio n. 2
0
 public void UpdateOrder(Order order)
 {
     ICollection<ValidationResult> validationResults;
     if (!order.Validate(out validationResults))
     {
         var ex = new ValidationException("Objektet klarade inte valideringen.");
         ex.Data.Add("ValidationResults", validationResults);
         throw ex;
     }
     if (order.OrderID == 0) // New post if ID is 0!
     {
         OrderDAL.InsertOrder(order);
     }
     else
     {
         OrderDAL.UpdateOrder(order);
     }
 }