public void EditOrderRegel(OrderRegel orderRegel) { bool newProduct = true; foreach (OrderRegel regel in GetOrderRegels()) { if (regel.product.id == orderRegel.product.id) { newProduct = false; } } DtoOrderRegel DTO = orderRegel.ToDTO(); IDalOrder orderDAL = DalFactory.CreateOrderDal(); if (newProduct && orderRegel.aantal > 0) { orderDAL.AddOrderRegel(id, DTO); } else if (!newProduct && orderRegel.aantal > 0) { orderDAL.UpdateOrderRegel(id, DTO); } else if (!newProduct && orderRegel.aantal == 0) { orderDAL.DeleteOrderRegel(id, DTO); } }
public List <DtoOrderRegel> GetOrderRegels(int orderId) { List <DtoOrderRegel> orderRegels = new List <DtoOrderRegel>(); try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = string.Format("select * from OrderRegel where OrderId={0}", orderId); using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { DtoOrderRegel newOrderRegel = new DtoOrderRegel { Aantal = reader.GetInt32(0), ProductId = reader.GetInt32(2) }; orderRegels.Add(newOrderRegel); } } } } catch (SqlException se) { Console.Write(se.Message); } return(orderRegels); }
public void DeleteOrderRegel(int orderId, DtoOrderRegel orderRegel) { try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "Delete from OrderRegel WHERE OrderId = @orderId AND ProductId = @prodId"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); command.Parameters.AddWithValue("@orderId", orderId); command.Parameters.AddWithValue("@prodId", orderRegel.ProductId); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } } } catch (SqlException se) { Console.Write(se.Message); } }
public void AddOrderRegel(int orderId, DtoOrderRegel orderRegel) { try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "insert into OrderRegel ( Aantal, OrderId, ProductId) values(@aantal,@orderId,@prodId)"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); command.Parameters.AddWithValue("@aantal", orderRegel.Aantal); command.Parameters.AddWithValue("@orderId", orderId); command.Parameters.AddWithValue("@prodId", orderRegel.ProductId); command.CommandType = CommandType.Text; int rowsAdded = command.ExecuteNonQuery(); } } } catch (SqlException se) { Console.Write(se.Message); } }