/// <summary> /// We will get a list of all the prices and view them to send to the buissness logic. /// </summary> /// <returns></returns> public List <OrderDO> ViewPrices() { List <OrderDO> orderDo = new List <OrderDO>(); try { using (SqlConnection pcConnection = new SqlConnection(_ConnectionString)) using (SqlCommand viewPrices = new SqlCommand("VIEW_USERNAME_AND_PRICE", pcConnection)) { viewPrices.CommandType = CommandType.StoredProcedure; viewPrices.CommandTimeout = 60; pcConnection.Open(); using (SqlDataReader reader = viewPrices.ExecuteReader()) { while (reader.Read()) { OrderDO order = mapper.TopFive(reader); orderDo.Add(order); } } } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(orderDo); }
/// <summary> /// We update our order base on the information given by the view /// </summary> /// <param name="updatedOrder"></param> public void UpdateOrder(OrderDO updatedOrder) { try { using (SqlConnection orderConnection = new SqlConnection(_ConnectionString)) using (SqlCommand updateOrder = new SqlCommand("UPDATE_ORDER", orderConnection)) { updateOrder.CommandType = CommandType.StoredProcedure; updateOrder.CommandTimeout = 60; updateOrder.Parameters.AddWithValue("Address", updatedOrder.Address); updateOrder.Parameters.AddWithValue("Country", updatedOrder.Country); updateOrder.Parameters.AddWithValue("Price", updatedOrder.price); updateOrder.Parameters.AddWithValue("OrderID", updatedOrder.OrderID); orderConnection.Open(); updateOrder.ExecuteNonQuery(); } } catch (SqlException ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } }
/// <summary> /// We take in the orders mapped to us and add them to the order. /// </summary> /// <param name="newOrder"></param> public void CreateOrder(OrderDO newOrder) { try { using (SqlConnection orderconnection = new SqlConnection(_ConnectionString)) using (SqlCommand createOrder = new SqlCommand("ADD_ORDER", orderconnection)) { createOrder.CommandType = CommandType.StoredProcedure; createOrder.CommandTimeout = 60; createOrder.Parameters.AddWithValue("@UserID", newOrder.userID); createOrder.Parameters.AddWithValue("@Address", newOrder.Address); createOrder.Parameters.AddWithValue("@Country", newOrder.Country); createOrder.Parameters.AddWithValue("@PCID", newOrder.pcID); createOrder.Parameters.AddWithValue("@Username", newOrder.userName); createOrder.Parameters.AddWithValue("@Price", newOrder.price); createOrder.Parameters.AddWithValue("@PCName", newOrder.pcName); orderconnection.Open(); createOrder.ExecuteNonQuery(); } } catch (SqlException ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } }
private void UpdateOrder(OrderDO updatedOrder) { var orderItems = updatedOrder.LineItems; var existingLineItems = new List <OrderLineItemDO>(); for (int i = 0; i < orderItems.Count; i++) { // Collect all line items of the order together ( Append Quantities ) var item = orderItems[i]; if (existingLineItems.Exists(l => l.Product.ProductId == item.Product.ProductId)) { var existingItem = existingLineItems.FirstOrDefault(l => l.Product.ProductId == item.Product.ProductId); existingItem.Quantity += item.Quantity; existingItem.Total += item.Total; orderItems.Remove(item); } else { existingLineItems.Add(item); } } updatedOrder.LineItems = existingLineItems; db.Orders.Update(updatedOrder); db.SaveChanges(); }
/// <summary> /// We make a list of the orders avaiable and return the list /// </summary> /// <returns></returns> public List <OrderDO> ViewOrders() { List <OrderDO> orderList = new List <OrderDO>(); try { using (SqlConnection OrderConnection = new SqlConnection(_ConnectionString)) using (SqlCommand ViewOrders = new SqlCommand("VIEW_ORDER", OrderConnection)) { ViewOrders.CommandType = CommandType.StoredProcedure; OrderConnection.Open(); using (SqlDataReader sqlReader = ViewOrders.ExecuteReader()) { while (sqlReader.Read()) { OrderDO order = mapper.MapReadertoSingle(sqlReader); orderList.Add(order); } } } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(orderList); }
public static OrderDO DataRowToOrderDO(DataRow row) { OrderDO orderDO = new OrderDO(); try { orderDO.OrderID = long.Parse(row["OrderID"].ToString()); orderDO.UserID = long.Parse(row["UserID"].ToString()); orderDO.Status = row["Status"].ToString(); orderDO.IsDelivery = bool.Parse(row["IsDelivery"].ToString()); orderDO.OrderFulfilledTime = row["OrderFulfilledTime"] as DateTime?; orderDO.DriverID = row["DriverID"] as long?; orderDO.DriverFirstName = row["DriverFirstName"].ToString(); orderDO.OrderDate = (DateTime)row["OrderDate"]; orderDO.BuyerName = row["BuyerName"].ToString(); orderDO.BuyerAddress = row["BuyerAddress"].ToString(); orderDO.Total = (decimal)row["Total"]; orderDO.Paid = (bool)row["Paid"]; } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); throw exception; } finally { } return(orderDO); }
public ActionResult UpdateOrder(long OrderId) { //set response ActionResult responce; try { //grabbing the order do order id OrderDO updateOrder = _OrderDataAccess.ViewOrderById(OrderId); //maping order do to orderpo Order Order = OrderMapper.MapDoToPo(updateOrder); //set orderid = to order.orderid OrderId = Order.OrderId; //check if (OrderId > 0) { responce = View(Order); } else { responce = RedirectToAction("ViewAllGames", "Game"); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); responce = RedirectToAction("Index", "Home"); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); responce = RedirectToAction("Index", "Home"); } return(responce); }
public void UpdateOrder(OrderDO orderUpdate) { try { using (SqlConnection connectionGamestore = new SqlConnection(_ConnectionString)) using (SqlCommand updateOrder = new SqlCommand("ORDER_UPDATE", connectionGamestore)) { updateOrder.CommandType = CommandType.StoredProcedure; updateOrder.CommandTimeout = 60; updateOrder.Parameters.AddWithValue("@OrderId", orderUpdate.OrderId); updateOrder.Parameters.AddWithValue("@Email_Address", orderUpdate.EmailAddress); updateOrder.Parameters.AddWithValue("@Address", orderUpdate.Address); updateOrder.Parameters.AddWithValue("@Phone", orderUpdate.Phone); connectionGamestore.Open(); updateOrder.ExecuteNonQuery(); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } }
public ActionResult UpdatePizzaInOrder(long ID) { ActionResult response = null; try { PizzaDO pizzaDOtoUpdate = _pizzaDAO.ViewPizzaByID(ID); if (pizzaDOtoUpdate != null) { // This pizza exists in the database. OrderDO pizzaOrderDO = _orderDAO.GetOrderByID((long)pizzaDOtoUpdate.OrderID); if (pizzaOrderDO.UserID == GetSessionUserID() || GetSessionRole() == 1) { // The user is associated with this pizza OR the admin is trying to update the pizza. PizzaPO pizzaPOtoUpdate = Mapping.PizzaMapper.PizzaDOtoPizzaPO(pizzaDOtoUpdate); FillPizzaSelectItems(pizzaPOtoUpdate); response = View(pizzaPOtoUpdate); } else { // A regular user tried to update someone elses pizza. Logger.Log("WARNING", "PizzaController", "UpdatePizzaInOrder", "UserID: " + GetSessionUserID() + " tried to update someone else's pizza."); response = RedirectToAction("MyOrders", "Order"); } } else { // Pizza doesn't exist. if (GetSessionRole() == 1) // If the admin is using { TempData["ErrorMessage"] = "That doesn't exist."; RedirectToAction("ViewPendingOrders", "Order"); } else { response = RedirectToAction("MyOrders", "Order"); } } } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } } return(response); }
public List <OrderDO> ViewOrder() { List <OrderDO> order = new List <OrderDO>(); try { using (SqlConnection connection = new SqlConnection(_ConnectionString)) using (SqlCommand command = new SqlCommand("ORDER_VIEW", connection)) { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 60; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { OrderDO orders = _Mapper.MapReaderToSingle(reader); order.Add(orders); } } } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(order); }
public long CreateOrder(OrderDO OrderCreate) { long GameId = 0; try { using (SqlConnection connection = new SqlConnection(_ConnectionString)) using (SqlCommand command = new SqlCommand("ORDER_CREATE", connection)) { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 60; command.Parameters.AddWithValue("@EmailAddress", OrderCreate.EmailAddress); command.Parameters.AddWithValue("@Address", OrderCreate.Address); command.Parameters.AddWithValue("@Phone", OrderCreate.Phone); command.Parameters.AddWithValue("@UserId", OrderCreate.UserId); connection.Open(); //pulls back the Id of the row you entered object tempGameId = command.ExecuteScalar(); GameId = Convert.ToInt64(tempGameId); connection.Close(); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); } return(GameId); }
public OrderDO MapReaderToSingle(SqlDataReader reader) { OrderDO result = new OrderDO(); if (reader["OrderId"] != DBNull.Value) { result.OrderId = (long)reader["OrderId"]; } if (reader["Email Address"] != DBNull.Value) { result.EmailAddress = (string)reader["Email Address"]; } if (reader["Address"] != DBNull.Value) { result.Address = (string)reader["Address"]; } if (reader["Phone"] != DBNull.Value) { result.Phone = (string)reader["Phone"]; } if (reader["UserId"] != DBNull.Value) { result.UserId = (long)reader["UserId"]; } return(result); }
public ActionResult UpdateOrder(Order form) { ActionResult respose; try { if (ModelState.IsValid) { //maps order po to order do OrderDO OrderDO = OrderMapper.MapPoToDo(form); //da call for orderdo _OrderDataAccess.UpdateOrder(OrderDO); respose = View(form); } else { respose = RedirectToAction("Login", "Account"); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); respose = RedirectToAction("Index", "Home"); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); respose = RedirectToAction("Index", "Home"); } return(respose); }
public ActionResult UpdateOrder(long OrderID) { ActionResult response; if ((string)Session["RoleName"] == "Admin") { //check id CANT be default or less than 0 if (OrderID > 0) { OrderDO orderDO = ordersDAO.ViewByOrderID(OrderID); Order orderPo = orderMapper.MapDoToPO(orderDO); response = View(orderPo); } else { response = RedirectToAction("Index", "Home"); } } else { response = RedirectToAction("Index", "Home"); } return(response); }
public async Task <ActionResult> Index(String customerID) { List <OrderDO> orders = await OrderDO.GetOrdersAsync(customerID); ViewBag.Orders = orders; return(View()); }
public OrderBO MapDoToBo(OrderDO from) { OrderBO to = new OrderBO(); to.Price = from.price; to.UserID = from.userID; to.UserName = from.userName; return(to); }
public OrderDO MapPoToDo(Order from) { OrderDO to = new OrderDO(); to.OrderId = from.OrderId; to.EmailAddress = from.EmailAddress; to.Address = from.Address; to.Phone = from.Phone; to.UserId = from.UserId; return(to); }
public void UpdateOrder(OrderDO updatedOrder) { var existingOrder = GetOrderById(updatedOrder.OrderId); //existingOrder.LineItems = updatedOrder.LineItems; existingOrder.Total = updatedOrder.Total; Debug.WriteLine(db.Entry(updatedOrder).State); db.Orders.Update(existingOrder); //db.Entry(updatedOrder).State = EntityState.Modified; db.SaveChanges(); }
public Order MapDoToPo(OrderDO from) { Order to = new Order(); to.OrderId = from.OrderId; to.EmailAddress = from.EmailAddress; to.Address = from.Address; to.Phone = from.Phone; to.UserId = from.UserId; return(to); }
public ActionResult CreateOrder(OrderPO form) { ActionResult response = null; if (Session["RoleID"] != null && ((int)Session["RoleID"] == 2 || (int)Session["RoleID"] == 3)) { if (ModelState.IsValid) { try { OrderDO dataObject = OrderMappers.OrderPOtoDO(form); _orderDataAccess.CreateOrder(dataObject); response = RedirectToAction("Index", "Order"); } catch (Exception exception) { ErrorLogger.LogExceptions(exception); response = View(form); } finally { } } else { //Returning a list of products from the readall function in the DAL foreach (ProductDO dataObject in _productDataAccess.ReadAllProducts()) { //declaring a selectlistitem for the list in the OrderPO property ProductsDropDown SelectListItem listItem = new SelectListItem(); //Assigning the product's name to the listitem's text listItem.Text = dataObject.Name; //Assigning the product's ID to the listitem's value listItem.Value = dataObject.ProductID.ToString(); //Adding the listitem, with its text and value, to the ProductsDropDown property of the OrderPO object form.ProductsDropDown.Add(listItem); } response = View(form); } } else { response = RedirectToAction("Index", "Home"); } return(response); }
public void AddLineItemsForOrder(List <OrderLineItemDO> orderLineItems, OrderDO order) { foreach (var item in orderLineItems) { item.OrderId = order.OrderId; item.Order = order; db.OrderLineItems.Add(item); } db.SaveChanges(); }
/// <summary> /// Inserts a new order in the DB and returns the primary key of the newly /// created order. /// </summary> /// <param name="newOrder">The object whose properties will be stored in the DB.</param> /// <returns>The Scope Indentity of the newly inserted Order.</returns> public long CreateOrder(OrderDO newOrder) { // Set up the return value. long incrementedID = -1; SqlConnection sqlConnection = null; SqlCommand sqlCommand = null; try { // Initialize the connection to SQL sqlConnection = new SqlConnection(_connectionString); // Initialize a the stored procedure sqlCommand = new SqlCommand("CREATE_ORDER", sqlConnection); sqlCommand.CommandType = CommandType.StoredProcedure; // Add the paramaters that the stored procedure requires. sqlCommand.Parameters.AddWithValue("@UserID", newOrder.UserID); sqlCommand.Parameters.AddWithValue("@Status", newOrder.Status); sqlCommand.Parameters.AddWithValue("@IsDelivery", newOrder.IsDelivery); sqlCommand.Parameters.AddWithValue("@OrderDate", newOrder.OrderDate); sqlCommand.Parameters.AddWithValue("@Paid", newOrder.Paid); sqlCommand.Parameters.AddWithValue("@Total", newOrder.Total); // Open the connection to the database. sqlConnection.Open(); // Get the ID of the newly inserted Order. incrementedID = Convert.ToInt64(sqlCommand.ExecuteScalar()); } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); throw exception; } finally { // Manually close anything that has a dispose. if (sqlConnection == null) { sqlConnection.Close(); sqlConnection.Dispose(); } if (sqlCommand == null) { sqlCommand.Dispose(); } } return(incrementedID); }
public static OrderBO OrderDOtoBO(OrderDO input) { OrderBO output = new OrderBO(); output.OrderID = input.OrderID; output.Quantity = input.Quantity; output.DateOfOrder = input.DateOfOrder; output.ExpectedArrivalDate = input.ExpectedArrivalDate; output.DistributionCenter = input.DistributionCenter; output.ProductID = input.ProductID; return(output); }
public ActionResult CompleteDelivery(long ID) { ActionResult response = null; try { // Get the order the user is wanting to delete. OrderDO orderDOtoComplete = _orderDAO.GetOrderByID(ID); if (orderDOtoComplete != null) // If the order exists. { // Map the orderDO to an orderPO OrderPO orderPOtoComplete = Mapping.OrderMapper.OrderDOtoOrderPO(orderDOtoComplete); // If the order is in fact a delivery order. if (orderPOtoComplete.IsDelivery) { // Complete the order. _orderDAO.CompleteOrder(ID); TempData["SuccessMessage"] = "Order Complete"; } else // The order the user is trying to delete is not a delivery order. { TempData["ErrorMessage"] = "That order# " + ID + " is not a delivery order. The order may have been changed to carryout."; } } else // The order doesn't exist. { TempData["ErrorMessage"] = "Order# " + ID + " doesn't exist. The order may have been deleted."; } response = RedirectToAction("MyDeliveries", "Order"); return(response); } catch (Exception exception) { Logger.LogExceptionNoRepeats(exception); } finally { if (response == null) { response = RedirectToAction("Index", "Home"); } else /* The response was not null */ } { } return(response); }
public ActionResult UpdateOrder(int orderID) { OrderDO item = null; OrderPO display = null; ActionResult response = RedirectToAction("Index", "Home"); //Available to all roles if (Session["RoleID"] != null) { try { item = _orderDataAccess.ReadIndividualOrder(orderID); display = OrderMappers.OrderDOtoPO(item); //Filling selectlist foreach (ProductDO dataObject in _productDataAccess.ReadAllProducts()) { //declaring a selectlistitem for the list in the OrderPO property ProductsDropDown SelectListItem listItem = new SelectListItem(); //Assigning the product's name to the listitem's text listItem.Text = dataObject.Name; //Assigning the product's ID to the listitem's value listItem.Value = dataObject.ProductID.ToString(); //Adding the listitem, with its text and value, to the ProductsDropDown property of the OrderPO object display.ProductsDropDown.Add(listItem); } //Setting the dropdown list to the correct product: display.ProductID = item.ProductID; } catch (Exception exception) { ErrorLogger.LogExceptions(exception); response = View(orderID); } finally { } response = View(display); } else { response = RedirectToAction("Index", "Home"); } return(response); }
public void DeleteOrder(Order orderToRemove) { OrderDO orderDO = dbContext.Orders.SingleOrDefault(order => orderToRemove.Id == order.Id); if (orderDO != null) { dbContext.Orders.Remove(orderDO); } else { throw new EntryPointNotFoundException(); } dbContext.SaveChanges(); }
//READ ONE ORDER public OrderDO ReadIndividualOrder(int OrderID) { OrderDO orderDataObject = new OrderDO(); SqlConnection connection = null; SqlCommand readIndividualOrderCommand = null; SqlDataReader reader = null; try { connection = new SqlConnection(_connectionString); readIndividualOrderCommand = new SqlCommand("READ_INDIVIDUAL_ORDER_BY_ID", connection); readIndividualOrderCommand.CommandType = CommandType.StoredProcedure; connection.Open(); readIndividualOrderCommand.Parameters.AddWithValue("OrderID", OrderID); reader = readIndividualOrderCommand.ExecuteReader(); reader.Read(); //Pass name? orderDataObject.OrderID = (int)reader["OrderID"]; orderDataObject.Quantity = (int)reader["Quantity"]; orderDataObject.DateOfOrder = reader["DateOfOrder"].ToString(); orderDataObject.ExpectedArrivalDate = reader["ExpectedArrivalDate"].ToString(); orderDataObject.DistributionCenter = reader["DistributionCenter"].ToString(); orderDataObject.ProductID = (int)reader["ProductID"]; //There's no product name in the order table: //orderDataObject.Name = reader["Name"].ToString(); reader.Close(); } catch (Exception exception) { ErrorLogger.LogExceptions(exception); } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } return(orderDataObject); }
public OrderDO MappPoToDO(Order from) { OrderDO to = new OrderDO(); to.pcID = from.PcID; to.Address = from.Address; to.Country = from.Country; to.userID = from.UserID; to.OrderID = from.OrderID; to.pcName = from.PCName; to.userName = from.Username; to.price = from.price; return(to); }
public Order MapDoToPO(OrderDO from) { Order to = new Order(); to.Address = from.Address; to.Country = from.Country; to.OrderID = from.OrderID; to.PCName = from.pcName; to.UserID = from.userID; to.Username = from.userName; to.PcID = from.pcID; to.price = from.price; return(to); }
private static OrderDO OrderTranslateDatabaseRowToItemInObject(DataRow databaseInput) { OrderDO output = new OrderDO(); output.OrderID = (int)databaseInput["OrderID"]; output.Quantity = (int)databaseInput["Quantity"]; output.DateOfOrder = databaseInput["DateOfOrder"].ToString(); output.ExpectedArrivalDate = databaseInput["ExpectedArrivalDate"].ToString(); output.DistributionCenter = databaseInput["DistributionCenter"].ToString(); //Here I think productid has to be replaced with the product name: //output.ProductID = (int)databaseInput["ProductID"]; output.Name = databaseInput["Name"].ToString(); return(output); }