コード例 #1
0
        public ActionResult Create(OrderPO form)
        {
            ActionResult oResponse = RedirectToAction("Index", "Game");

            if (ModelState.IsValid)
            {
                try
                {
                    form.UserID = (Int64)Session["UserID"];
                    OrdersDO dataObject = OrderMapper.MapPoToDo(form);
                    dataAccess.CreateNewOrder(dataObject, Session["Cart"] as List <int>);

                    TempData["Message"] = $"{form.Name} order has been created";
                }
                catch (Exception ex)
                {
                    oResponse = View(form);
                }
            }
            else
            {
                oResponse = View(form);
            }
            Session["Cart"] = null;
            return(oResponse);
        }
コード例 #2
0
        public ActionResult UpdateOrder(int OrderID)
        {
            ActionResult response;

            try
            {
                //mapping user input to database
                OrdersDO orderDO = _OrdersDAO.ViewOrderByID(OrderID);
                OrdersPO orderPO = Mapper.OrdersDOtoOrdersPO(orderDO);

                response = View(orderPO);
            }
            //logging errors and redirecting
            catch (SqlException sqlEx)
            {
                Logger.SqlErrorLog(sqlEx);
                response = View("Error");
            }
            catch (Exception ex)
            {
                Logger.ErrorLog(ex);
                response = View("Error");
            }
            //return view
            return(response);
        }
コード例 #3
0
        //Maps all Orders
        public OrdersDO MapAllOrders(DataRow row)
        {
            try
            {
                OrdersDO order = new OrdersDO();

                //If the game ID is not null, then add values to the game object from the database
                if (row["OrderID"] != DBNull.Value)
                {
                    order.OrderID = (Int64)row["OrderID"];
                }
                order.Name    = row["Name"].ToString();
                order.Address = row["Address"].ToString();
                order.Phone   = row["Phone"].ToString();
                order.ZipCode = row["ZipCode"].ToString();

                //Returning the object with a row updated from SQL
                return(order);
            }
            catch (Exception ex)
            {
                OrderErrorHandler(false, "fatal", "OrderDAO", "MapAllOrders", ex.Message, ex.StackTrace);
                throw;
            }
        }
コード例 #4
0
        public OrdersDO ViewOrderByUser(Int64 orderId)
        {
            OrdersDO orders = new OrdersDO();

            try
            {
                using (SqlConnection orderConn = new SqlConnection(connectString))
                {
                    SqlCommand enterCommand = new SqlCommand("VIEWORDERSBYUSER", orderConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;
                    enterCommand.Parameters.AddWithValue("UserID", orderId);
                    orderConn.Open();

                    DataTable orderInfo = new DataTable();
                    using (SqlDataAdapter orderAdapter = new SqlDataAdapter(enterCommand))
                    {
                        orderAdapter.Fill(orderInfo);
                        orderAdapter.Dispose();
                    }

                    foreach (DataRow row in orderInfo.Rows)
                    {
                        orders = MapAllOrders(row);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(orders);
        }
コード例 #5
0
        //Method that will Update a orders information
        public void UpdateOrder(OrdersDO orders)
        {
            try
            {
                //Opens SQL Connection
                using (SqlConnection orderConn = new SqlConnection(connectString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("UPDATE_ORDERS", orderConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;

                    //Parameters that are being passed to the stored procedures
                    enterCommand.Parameters.AddWithValue("@Name", orders.Name);
                    enterCommand.Parameters.AddWithValue("@Address", orders.Address);
                    enterCommand.Parameters.AddWithValue("@Phone", orders.Phone);
                    enterCommand.Parameters.AddWithValue("@ZipCode", orders.ZipCode);
                    enterCommand.Parameters.AddWithValue("@OrderID", orders.OrderID);

                    //Opens Connection
                    orderConn.Open();

                    //Execute Non Query
                    enterCommand.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                OrderErrorHandler(false, "fatal", "OrderDAO", "UpdateOrder", ex.Message, ex.StackTrace);
                throw;
            }
        }
コード例 #6
0
        public ActionResult UpdateOrder(OrdersPO form)
        {
            ActionResult response;

            //checking modelstate
            if (ModelState.IsValid)
            {
                try
                {
                    //mapping user inpit to database
                    OrdersDO OrderDO = Mapper.OrdersPOtoOrdersDO(form);
                    _OrdersDAO.UpdateOrder(OrderDO);
                    response = RedirectToAction("ViewOrderByID", "Orders", new { OrderDO.OrderID });
                }
                //logging errors and redirecting
                catch (SqlException sqlEx)
                {
                    Logger.SqlErrorLog(sqlEx);
                    response = View("Error");
                }
                catch (Exception ex)
                {
                    Logger.ErrorLog(ex);
                    response = View("Error");
                }
            }
            else
            {
                //returning to form view if model state is invalid
                response = View(form);
            }
            //return view
            return(response);
        }
コード例 #7
0
        public ActionResult ConfirmAssign(int OrderID)
        {
            OrdersDO Order        = _OrdersDAO.ViewOrderByID(OrderID);
            OrdersPO orderDetails = Mapper.OrdersDOtoOrdersPO(Order);

            return(View(orderDetails));
        }
コード例 #8
0
        public ActionResult CreateNewOrder(OrdersPO form)
        {
            ActionResult response;

            //checking modelstate
            if (ModelState.IsValid)
            {
                try
                {
                    //taking user input and saving it to the database
                    OrdersDO newOrder = Mapper.OrdersPOtoOrdersDO(form);
                    _OrdersDAO.CreateNewOrder(newOrder);
                    //redirecting to Order page when finished
                    response = RedirectToAction("ViewOrderByUserID", "Orders", new { newOrder.UserID });
                }
                //logging errors and redirecting
                catch (SqlException sqlEx)
                {
                    Logger.SqlErrorLog(sqlEx);
                    response = View("Error");
                }
                catch (Exception ex)
                {
                    Logger.ErrorLog(ex);
                    response = View("Error");
                }
            }
            else
            {
                //returning to form view if model state is invalid
                response = View(form);
            }
            //returning to home page
            return(response);
        }
コード例 #9
0
        public static OrdersDO MapPoToDo(OrderPO from)
        {
            OrdersDO to = new OrdersDO();

            to.OrderID = from.OrderID;
            to.Name    = from.Name;
            to.Address = from.Address;
            to.Phone   = from.Phone;
            to.ZipCode = from.ZipCode;
            to.UserID  = from.UserID;

            return(to);
        }
コード例 #10
0
        public ActionResult UpdateOrder(Int64 orderID)
        {
            OrderPO displayObject = new OrderPO();

            try
            {
                OrdersDO item = dataAccess.ViewOrdersByID(orderID);
                displayObject = OrderMapper.MapDoToPo(item);
            }
            catch (Exception ex)
            {
            }
            return(View(displayObject));
        }
コード例 #11
0
        public static List <OrdersDO> MapPoToDo(List <OrderPO> from)
        {
            List <OrdersDO> to = new List <OrdersDO>();

            if (from != null)
            {
                foreach (OrderPO item in from)
                {
                    OrdersDO mappedItem = MapPoToDo(item);
                    to.Add(mappedItem);
                }
            }
            return(to);
        }
コード例 #12
0
ファイル: Mapper.cs プロジェクト: alexnott42/Capstone
        //Mapping to presentation layer from DLL
        public static OrdersPO OrdersDOtoOrdersPO(OrdersDO from)
        {
            //mapping each individual attribute
            OrdersPO to = new OrdersPO();

            to.OrderID    = from.OrderID;
            to.UserID     = from.UserID;
            to.Requested  = from.Requested;
            to.Due        = from.Due;
            to.CrafterID  = from.CrafterID;
            to.Status     = from.Status;
            to.Username   = from.Username;
            to.Crafter    = from.Crafter;
            to.Pricetotal = from.Pricetotal;
            //making it usable in future
            return(to);
        }
コード例 #13
0
ファイル: MapperDAL.cs プロジェクト: alexnott42/Capstone
        //Getting Order Data from the Database
        public static OrdersDO ReaderToOrder(SqlDataReader from)
        {
            OrdersDO to = new OrdersDO();

            //mapping data
            to.OrderID    = (int)from["OrderID"];
            to.UserID     = (int)from["UserID"];
            to.Requested  = (DateTime)from["Requested"];
            to.Due        = (DateTime)from["Due"];
            to.CrafterID  = from["CrafterId"] as int?;
            to.Status     = (byte)from["Status"];
            to.Username   = from["Username"] as string;
            to.Crafter    = from["Crafter"] as string;
            to.Pricetotal = from["Pricetotal"] as int?;
            //Returning Order Data
            return(to);
        }
コード例 #14
0
        //Retrieving a single order from the database
        public OrdersDO ViewOrderByID(int OrderID)
        {
            OrdersDO orderData = new OrdersDO();

            try
            {
                //defining commands to access the database
                using (SqlConnection sqlConnection = new SqlConnection(_ConnectionString))
                    using (SqlCommand viewByID = new SqlCommand("ORDERS_SELECT_BY_ID", sqlConnection))
                    {
                        //give up after 60 seconds
                        viewByID.CommandType    = CommandType.StoredProcedure;
                        viewByID.CommandTimeout = 60;

                        //inserting the UserID to sort through entries
                        viewByID.Parameters.AddWithValue("OrderID", OrderID);

                        //reading the data and using Mapper to store it
                        sqlConnection.Open();
                        using (SqlDataReader reader = viewByID.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                orderData = MapperDAL.ReaderToOrder(reader);
                            }
                        }
                    }
            }
            //logging any errors
            catch (SqlException sqlEx)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.SqlErrorLog(sqlEx);
                throw sqlEx;
            }
            catch (Exception ex)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.ErrorLog(ex);
                throw ex;
            }
            // returning order
            return(orderData);
        }
コード例 #15
0
        public ActionResult ViewOrderByID(int OrderID)
        {
            ActionResult response;
            OrdersVM     orderDetails = new OrdersVM();

            try
            {
                //mapping all the data to the view page
                OrdersPO       order      = Mapper.OrdersDOtoOrdersPO(_OrdersDAO.ViewOrderByID(OrderID));
                List <ItemsPO> orderItems = Mapper.ItemsListDOtoPO(_ItemsDAO.ItemsByOrderID(OrderID));

                //sending to business logic layer
                OrdersBO       calcOrder = Mapper.OrdersPOtoOrdersBO(order);
                List <ItemsBO> calcItems = Mapper.ItemsListPOtoBO(orderItems);

                //doing valculations
                calcOrder        = Calculation.PriceTotalCalculator(calcItems);
                order.Pricetotal = calcOrder.Pricetotal;

                //assigning new total price
                OrdersDO newTotal = Mapper.OrdersPOtoOrdersDO(order);
                _OrdersDAO.UpdateOrderPricetotal(newTotal);

                //assigning objects to viewmodel
                orderDetails.Order = order;
                orderDetails.Items = orderItems;

                response = View(orderDetails);
            }
            //logging errors and redirecting
            catch (SqlException sqlEx)
            {
                Logger.SqlErrorLog(sqlEx);
                response = View("Error");
            }
            catch (Exception ex)
            {
                Logger.ErrorLog(ex);
                response = View("Error");
            }
            //return view
            return(response);
        }
コード例 #16
0
        //Method that views a certain order by it's ID
        public OrdersDO ViewOrdersByID(Int64 orderId)
        {
            OrdersDO orders = new OrdersDO();

            try
            {
                //Opens SQL Connection


                using (SqlConnection orderConn = new SqlConnection(connectString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("VIEW_ORDERID", orderConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;
                    enterCommand.Parameters.AddWithValue("@OrderID", orderId);
                    orderConn.Open();

                    //Using a SQLDataAdapter to get the SQL table
                    DataTable orderInfo = new DataTable();
                    using (SqlDataAdapter orderAdapter = new SqlDataAdapter(enterCommand))
                    {
                        orderAdapter.Fill(orderInfo);
                        orderAdapter.Dispose();
                    }

                    //Maps
                    foreach (DataRow row in orderInfo.Rows)
                    {
                        orders = MapAllOrders(row);
                    }
                }
            }
            catch (Exception ex)
            {
                OrderErrorHandler(false, "fatal", "OrderDAO", "ViewOrdersByID", ex.Message, ex.StackTrace);

                throw;
            }

            return(orders);
        }
コード例 #17
0
        //Method that will display all the orders in the database
        public List <OrdersDO> ViewAllOrders()
        {
            List <OrdersDO> allOrders = new List <OrdersDO>();

            try
            {
                //Opens SQL Connection
                using (SqlConnection orderConn = new SqlConnection(connectString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("READ_ORDERS", orderConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;
                    orderConn.Open();

                    //Using a SQLDataAdapter to get the SQL table
                    DataTable orderInfo = new DataTable();
                    using (SqlDataAdapter orderAdapter = new SqlDataAdapter(enterCommand))
                    {
                        orderAdapter.Fill(orderInfo);
                        orderAdapter.Dispose();
                    }

                    //Mapping datarow to a List of the orders
                    foreach (DataRow row in orderInfo.Rows)
                    {
                        OrdersDO mappedRows = MapAllOrders(row);
                        allOrders.Add(mappedRows);
                    }
                }
            }
            catch (Exception ex)
            {
                OrderErrorHandler(false, "fatal", "OrderDAO", "ViewAllOrders", ex.Message, ex.StackTrace);

                throw ex;
            }
            //returning a list of the games
            return(allOrders);
        }
コード例 #18
0
        //Method that creates a order
        public void CreateNewOrder(OrdersDO orders, List <int> gameId)
        {
            Int64 uniqueID = 0;

            try
            {
                //Creates a new SQL Connection
                using (SqlConnection orderConn = new SqlConnection(connectString))
                {
                    //Creating a Command to use a stored procedure
                    SqlCommand enterCommand = new SqlCommand("CREATE_ORDERS", orderConn);
                    enterCommand.CommandType = CommandType.StoredProcedure;

                    //Parameters that are being passed to the stored procedures
                    enterCommand.Parameters.AddWithValue("@Name", orders.Name);
                    enterCommand.Parameters.AddWithValue("@Address", orders.Address);
                    enterCommand.Parameters.AddWithValue("@Phone", orders.Phone);
                    enterCommand.Parameters.AddWithValue("@ZipCode", orders.ZipCode);
                    enterCommand.Parameters.AddWithValue("@UserID", orders.UserID);


                    //Opens SQL connection
                    orderConn.Open();
                    uniqueID = Convert.ToInt64(enterCommand.ExecuteScalar());



                    orderConn.Close();
                    orderConn.Dispose();
                }
            }
            catch (Exception ex)
            {
                OrderErrorHandler(false, "fatal", "OrderDAO", "CreateNewOrder", ex.Message, ex.StackTrace);
                throw ex;
            }

            CreateOrder(gameId, uniqueID);
        }
コード例 #19
0
        //updating an existing order's crafer
        public int UpdateOrderCrafter(OrdersDO newInfo)
        {
            int rowsAffected = 0;

            try
            {
                //defining some commands
                using (SqlConnection sqlConnection = new SqlConnection(_ConnectionString))
                    using (SqlCommand updateOrder = new SqlCommand("ORDERS_UPDATE_CRAFTER", sqlConnection))
                    {
                        //timing out after 60 seconds
                        updateOrder.CommandType    = CommandType.StoredProcedure;
                        updateOrder.CommandTimeout = 60;

                        //inserting information
                        updateOrder.Parameters.AddWithValue("OrderID", newInfo.OrderID);
                        updateOrder.Parameters.AddWithValue("CrafterID", newInfo.CrafterID);
                        updateOrder.Parameters.AddWithValue("Status", newInfo.Status);

                        //Saving information to database
                        sqlConnection.Open();
                        rowsAffected = updateOrder.ExecuteNonQuery();
                    }
            }
            //logging errors
            catch (SqlException sqlEx)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.SqlErrorLog(sqlEx);
                throw sqlEx;
            }
            catch (Exception ex)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.ErrorLog(ex);
                throw ex;
            }
            return(rowsAffected);
        }
コード例 #20
0
        public ActionResult AssignMeToOrder(OrdersPO form)
        {
            ActionResult response;

            if (ModelState.IsValid)
            {
                try
                {
                    OrdersDO newInfo = Mapper.OrdersPOtoOrdersDO(form);
                    //running the stored procedure

                    newInfo.CrafterID = (int)Session["UserID"];
                    newInfo.Crafter   = (string)Session["Username"];
                    newInfo.Status    = 2;
                    _OrdersDAO.UpdateOrderCrafter(newInfo);

                    response = RedirectToAction("ViewOrderByID", "Orders", new { form.OrderID });
                }
                //logging errors and redirecting
                catch (SqlException sqlEx)
                {
                    Logger.SqlErrorLog(sqlEx);
                    response = View("Error");
                }
                catch (Exception ex)
                {
                    Logger.ErrorLog(ex);
                    response = View("Error");
                }
            }
            else
            {
                //returning to form view if model state is invalid
                response = View(form);
            }
            //returning response page
            return(response);
        }
コード例 #21
0
        public ActionResult UpdateOrder(OrderPO form)
        {
            ActionResult oReponse = RedirectToAction("Index", "Order");

            if (ModelState.IsValid)
            {
                try
                {
                    form.UserID = (Int64)Session["UserID"];
                    OrdersDO dataObject = OrderMapper.MapPoToDo(form);
                    dataAccess.UpdateOrder(dataObject);
                }
                catch (Exception ex)
                {
                    oReponse = View(form);
                }
            }
            else
            {
                oReponse = View(form);
            }
            return(oReponse);
        }
コード例 #22
0
        //creating a new order
        public void CreateNewOrder(OrdersDO orderInfo)
        {
            try
            {
                //defining commands
                using (SqlConnection sqlConnection = new SqlConnection(_ConnectionString))
                    using (SqlCommand createOrder = new SqlCommand("ORDERS_CREATE_NEW", sqlConnection))
                    {
                        //timing out after 60 seconds
                        createOrder.CommandType    = CommandType.StoredProcedure;
                        createOrder.CommandTimeout = 60;

                        //inserting information
                        createOrder.Parameters.AddWithValue("UserID", orderInfo.UserID);
                        createOrder.Parameters.AddWithValue("Requested", orderInfo.Requested);
                        createOrder.Parameters.AddWithValue("Due", orderInfo.Due);
                        createOrder.Parameters.AddWithValue("Status", orderInfo.Status);

                        //Saving information to database
                        sqlConnection.Open();
                        createOrder.ExecuteNonQuery();
                    }
            }
            //logging errors
            catch (SqlException sqlEx)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.SqlErrorLog(sqlEx);
                throw sqlEx;
            }
            catch (Exception ex)
            {
                LoggerDAL.ErrorLogPath = _ErrorLogPath;
                LoggerDAL.ErrorLog(ex);
                throw ex;
            }
        }