public List <GameOrderDO> ViewAllGameOrders() { List <GameOrderDO> viewAllGameOrders = new List <GameOrderDO>(); try { using (SqlConnection connectionGamestore = new SqlConnection(_ConnectionString)) using (SqlCommand ViewGameOrdersCommand = new SqlCommand("GAMEORDER_VIEW_ALL", connectionGamestore)) { ViewGameOrdersCommand.CommandType = CommandType.StoredProcedure; connectionGamestore.Open(); using (SqlDataReader sqlDataReader = ViewGameOrdersCommand.ExecuteReader()) { //read entries from the database while (sqlDataReader.Read()) { GameOrderDO order = _Mapper.MapReaderToSingle(sqlDataReader); viewAllGameOrders.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(viewAllGameOrders); }
public GameOrderDO MapReaderToSingle(SqlDataReader reader) { GameOrderDO result = new GameOrderDO(); if (reader["GameId"] != DBNull.Value) { result.GameId = (long)reader["GameId"]; } if (reader["Price"] != DBNull.Value) { result.Price = (decimal)reader["Price"]; } return(result); }
public void OrderCreate(GameOrderDO OrderCreate) { try { using (SqlConnection connection = new SqlConnection(_ConnectionString)) using (SqlCommand command = new SqlCommand("GAMEORDER_CREATE", connection)) { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 60; command.Parameters.AddWithValue("@GameId", OrderCreate.GameId); command.Parameters.AddWithValue("@OrderId", OrderCreate.OrderId); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); } }
public ActionResult CreateOrder(Order form) { //set response ActionResult response; try { //check if ((long)Session["RoleId"] > 0) { if (ModelState.IsValid) { //makeing list of long game ids = to the sessiond cart List <long> cart = (List <long>)Session["Cart"]; //check to see if cart is null or 0 if (cart == null) { return(View()); } else { } //check to see if userid is null if (Session["UserId"] == null) { response = RedirectToAction("Register", "Account"); } else { //sets userid = to the session userid long userId = (long)Session["UserId"]; //maping data OrderDO dataObject = new OrderDO(); dataObject.OrderId = form.OrderId; dataObject.EmailAddress = form.EmailAddress; dataObject.Address = form.Address; dataObject.Phone = form.Phone; dataObject.UserId = userId; //creating order and getting back the id dataObject.OrderId = _OrderDataAccess.CreateOrder(dataObject); long orderId = dataObject.OrderId; //make statement that every long gameid that is in the sessioned cart foreach (long gameId in cart) { //instantiate gameorderdo based off of the game id and order id GameOrderDO gameOrder = new GameOrderDO(gameId, orderId); //call on the dao to create an gameorder _GameOrderDataAccess.OrderCreate(gameOrder); } //setiing response response = RedirectToAction("CreateOrder", "Order"); } } else { response = RedirectToAction("Login", "Account"); } } else { response = RedirectToAction("Login", "Account"); } } catch (SqlException sqlex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, sqlex); response = RedirectToAction("Login", "Account"); } catch (Exception ex) { _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex); response = RedirectToAction("Login", "Account"); } return(response); }