public IEnumerable <ServiceCustomerOrder> GetCancelledOrders() { List <ServiceCustomerOrder> customerOrders = new List <ServiceCustomerOrder>(); using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand cmdGetCancelledOrders = connection.CreateCommand()) { cmdGetCancelledOrders.CommandText = "SELECT orderId, finalPrice, orderStatus, dateOrder, customerId, paymentMethodId FROM CustomerOrder WHERE orderStatus = @cancelled "; cmdGetCancelledOrders.Parameters.AddWithValue("@cancelled", "Cancelled"); SqlDataReader allOrdersReader = cmdGetCancelledOrders.ExecuteReader(); while (allOrdersReader.Read()) { ServiceCustomerOrder customerOrder = new ServiceCustomerOrder(); customerOrder.FinalPrice = allOrdersReader.GetDecimal(allOrdersReader.GetOrdinal("finalPrice")); customerOrder.Status = allOrdersReader.GetString(allOrdersReader.GetOrdinal("orderStatus")); customerOrder.DateOrder = allOrdersReader.GetDateTime(allOrdersReader.GetOrdinal("dateOrder")); customerOrder.CustomerId = allOrdersReader.GetInt32(allOrdersReader.GetOrdinal("customerId")); customerOrder.PaymentMethod = allOrdersReader.GetInt32(allOrdersReader.GetOrdinal("paymentMethodId")); customerOrder.OrderId = allOrdersReader.GetInt32(allOrdersReader.GetOrdinal("orderId")); customerOrders.Add(customerOrder); } } } return(customerOrders); }
public void UpdateOrder(ServiceCustomerOrder order) { using (CustomerOrderServiceClient orderProxy = new CustomerOrderServiceClient()) { orderProxy.UpdateOrder(order); } }
public ServiceCustomerOrder GetOrder(int customerOrderId) { using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand cmdGetOrder = connection.CreateCommand()) { ServiceCustomerOrder customerOrder = null; cmdGetOrder.CommandText = "SELECT finalPrice, orderStatus, dateOrder, customerId, paymentMethodId, orderId FROM CustomerOrder WHERE orderId = @orderId"; cmdGetOrder.Parameters.AddWithValue("orderId", customerOrderId); SqlDataReader orderReader = cmdGetOrder.ExecuteReader(); while (orderReader.Read()) { customerOrder = new ServiceCustomerOrder(); customerOrder.FinalPrice = orderReader.GetDecimal(orderReader.GetOrdinal("finalPrice")); customerOrder.Status = orderReader.GetString(orderReader.GetOrdinal("orderStatus")); customerOrder.DateOrder = orderReader.GetDateTime(orderReader.GetOrdinal("dateOrder")); customerOrder.CustomerId = orderReader.GetInt32(orderReader.GetOrdinal("customerId")); customerOrder.PaymentMethod = orderReader.GetInt32(orderReader.GetOrdinal("paymentMethodId")); customerOrder.OrderId = orderReader.GetInt32(orderReader.GetOrdinal("orderId")); } return(customerOrder); } } }
public bool FinishCheckout(ServiceCustomerOrder order) { bool success = false; using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); try { using (TransactionScope scope = new TransactionScope()) { int orderID = InsertOrder(order); order.OrderId = orderID; if (order.DiscountCode != null) { InsertDiscountOrder(orderID, order.DiscountCode); } decimal totalPrice = -1; foreach (var item in order.ShoppingCart) { item.OrderId = orderID; totalPrice += item.SubTotal; dataProductLine.InsertProductLine(item); for (int i = 0; i < 5; i++) { ServiceProduct productFromDB = dataProduct.GetProductById(item.Product.ProductId); int remainingAmountOnStock = productFromDB.AmountOnStock - item.Amount; if (remainingAmountOnStock < 0) { throw new TransactionAbortedException(); } else { productFromDB.AmountOnStock = remainingAmountOnStock; int affectedRows = dataProduct.UpdateProduct(productFromDB); if (affectedRows != 0) { break; } } } } order.FinalPrice = totalPrice; UpdateOrder(order); scope.Complete(); success = true; } } catch (TransactionAbortedException ex) { success = false; } } return(success); }
public ServiceCustomerOrder ConvertToServiceOrder(Order order) { ServiceCustomerOrder orderToReturn = new ServiceCustomerOrder(); orderToReturn.OrderId = order.OrderId; orderToReturn.Status = order.Status.ToString(); return(orderToReturn); }
public bool FinishCheckout(Order order) { bool success = false; using (CustomerOrderServiceClient proxy = new CustomerOrderServiceClient()) { ServiceCustomerOrder orderToInsert = Converter.ConvertToServiceCustomerOrder(order); success = proxy.FinishCheckout(orderToInsert); } return(success); }
public Order ConvertFromServiceOrder(ServiceCustomerOrder serviceOrder) { Order orderToReturn = new Order(); orderToReturn.FinalPrice = serviceOrder.FinalPrice; orderToReturn.Status = serviceOrder.Status; orderToReturn.DateOrder = serviceOrder.DateOrder; orderToReturn.CustomerId = serviceOrder.CustomerId; orderToReturn.DiscountCode = serviceOrder.DiscountCode; orderToReturn.PaymentMethod = serviceOrder.PaymentMethod; return(orderToReturn); }
public Order ConvertFromServiceOrder(ServiceCustomerOrder item) { Order orderToReturn = null; if (item != null) { orderToReturn = new Order(); orderToReturn.Date = item.DateOrder; orderToReturn.OrderId = item.OrderId; if (item.Status != null) { orderToReturn.Status = (EnumOrderStatus)Enum.Parse(typeof(EnumOrderStatus), item.Status); } } return(orderToReturn); }
public void TestCancelOrder() { //Arrange DataCustomerOrder dataOrder = new DataCustomerOrder(); ServiceCustomerOrder order = new ServiceCustomerOrder(); // Get the first order in the DB order = dataOrder.GetOrder(1); // Change the order status to Cancelled order.Status = "Cancelled"; //Act dataOrder.UpdateOrder(order); // Update the order and update the database //Assert Assert.AreEqual("Cancelled", dataOrder.GetOrder(1).Status); }
public int UpdateOrder(ServiceCustomerOrder order) { int rowsAffected; using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand cmdUpdateOrder = connection.CreateCommand()) { cmdUpdateOrder.CommandText = "UPDATE CustomerOrder SET orderStatus = @orderStatus, finalPrice = @finalPrice WHERE orderId = @orderId"; cmdUpdateOrder.Parameters.AddWithValue("orderStatus", order.Status); cmdUpdateOrder.Parameters.AddWithValue("finalPrice", order.FinalPrice); cmdUpdateOrder.Parameters.AddWithValue("orderId", order.OrderId); rowsAffected = cmdUpdateOrder.ExecuteNonQuery(); } } return(rowsAffected); }
public void InsertOrderTest() { //Arrange DataProduct dataProduct = new DataProduct(); DataCustomerOrder dataCustomerOrder = new DataCustomerOrder(); ServiceCustomer customer = new ServiceCustomer(); customer.Name = "Peter J."; customer.Address = "Sofiendalsvej"; customer.ZipCode = 9000; customer.PhoneNo = "12345678"; ServiceProduct product = new ServiceProduct(); product = dataProduct.GetProductById(4); ServiceProductLine productLine = new ServiceProductLine(); productLine.Amount = 1; productLine.SubTotal = product.Price; productLine.Product = product; ServiceCustomerOrder order = new ServiceCustomerOrder(); order.FinalPrice = productLine.SubTotal; order.Status = "Active"; order.DateOrder = DateTime.Now; order.PaymentMethod = 1; order.DiscountCode = null; List <ServiceProductLine> productLines = new List <ServiceProductLine>(); productLines.Add(productLine); order.ShoppingCart = productLines; //Act bool success = dataCustomerOrder.FinishCheckout(order); //Assert Assert.IsTrue(success); }
public void SetPaymentMethodTest() { //Arrange ServiceCustomerOrder order = new ServiceCustomerOrder(); DataCustomerOrder dco = new DataCustomerOrder(); ServiceCustomerOrder testOrder; order.DateOrder = DateTime.Today; order.FinalPrice = 5000; order.Status = "Test Status"; order.PaymentMethod = 1; order.CustomerId = 1; //Act int idOfTestOrder = dco.InsertOrder(order); testOrder = dco.GetOrder(idOfTestOrder); //Assert Assert.IsNotNull(testOrder.PaymentMethod); }
public int InsertOrder(ServiceCustomerOrder order) { using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); int orderId = 0; using (SqlCommand cmdInsertOrder = connection.CreateCommand()) { //InsertsOrder (Regardless of discount) cmdInsertOrder.CommandText = "INSERT INTO CustomerOrder (finalPrice, orderStatus, dateOrder, customerId, paymentMethodId) OUTPUT INSERTED.orderId VALUES (@finalPrice, @orderStatus, @dateOrder, @customerId, @paymentMethodId)"; cmdInsertOrder.Parameters.AddWithValue("finalPrice", order.FinalPrice); cmdInsertOrder.Parameters.AddWithValue("orderStatus", order.Status); cmdInsertOrder.Parameters.AddWithValue("dateOrder", order.DateOrder); cmdInsertOrder.Parameters.AddWithValue("customerId", order.CustomerId); cmdInsertOrder.Parameters.AddWithValue("paymentMethodId", order.PaymentMethod); orderId = (int)cmdInsertOrder.ExecuteScalar(); } return(orderId); } }
public ServiceCustomerOrder ConvertToServiceCustomerOrder(Order webshopOrder) { ServiceCustomerOrder orderToReturn = new ServiceCustomerOrder(); orderToReturn.FinalPrice = webshopOrder.FinalPrice; orderToReturn.Status = webshopOrder.Status; orderToReturn.DateOrder = webshopOrder.DateOrder; orderToReturn.CustomerId = webshopOrder.CustomerId; orderToReturn.DiscountCode = webshopOrder.DiscountCode; orderToReturn.PaymentMethod = webshopOrder.PaymentMethod; orderToReturn.OrderId = webshopOrder.OrderId; orderToReturn.ShoppingCart = new OrderServiceReference.ServiceProductLine[webshopOrder.ShoppingCart.Count]; for (int i = 0; i < webshopOrder.ShoppingCart.Count; i++) { orderToReturn.ShoppingCart[i] = new ConvertProductLine().ConvertToServiceProductLine(webshopOrder.ShoppingCart[i]); } return(orderToReturn); }
public void OrderWithoutDiscount() { //ARRANGE ServiceCustomerOrder order = new ServiceCustomerOrder(); DataCustomerOrder dco = new DataCustomerOrder(); ServiceCustomerOrder testOrder = new ServiceCustomerOrder(); // Set all attributes except Discount order.DateOrder = DateTime.Today; order.FinalPrice = 1000; order.Status = "Test Status"; order.PaymentMethod = 1; order.CustomerId = 1; //ACT int testId = dco.InsertOrder(order); testOrder = dco.GetOrder(testId); //ASSERT Assert.IsNotNull(testOrder); }
public bool FinishCheckout(ServiceCustomerOrder order) { return(customerOrderControl.finishCheckout(order)); }
public void UpdateOrder(ServiceCustomerOrder order) { customerOrderControl.UpdateOrder(order); }
public int InsertOrder(ServiceCustomerOrder order) { return(customerOrderControl.InsertOrder(order)); }
public bool finishCheckout(ServiceCustomerOrder order) { return(dataCustomerOrder.FinishCheckout(order)); }
public int InsertOrder(ServiceCustomerOrder order) { return(dataCustomerOrder.InsertOrder(order)); }
public void UpdateOrder(ServiceCustomerOrder order) { dataCustomerOrder.UpdateOrder(order); }