コード例 #1
0
        public ActionResult PlaneOrder(int airportID, string datePlane, string timePlane, string note)
        {
            var planeOrderResult = new Dictionary <string, object>();
            var userIDObject     = Session["LoggedInUserID"];

            if (userIDObject == null)
            {
                planeOrderResult.Add("Succeeded", false);
                planeOrderResult.Add("Error", "用户尚未登录或登录已过期,请登录后再试");
                return(Json(planeOrderResult, JsonRequestBehavior.DenyGet));
            }
            var userID        = (int)(userIDObject);
            var orderUser     = DataRuntime.RuntimeData.Users.First(user => user.ID == userID);
            var orderAirport  = DataRuntime.RuntimeData.Airports.First(airport => airport.ID == airportID);
            var orderDateTime = CommonHelpers.ParseDateTime(datePlane, timePlane);
            var newOrder      = new PlaneOrder(orderUser, orderAirport, orderDateTime, note);

            try
            {
                DataRuntime.RuntimeData.DataContext.PlaneOrders.Add(newOrder);
                DataRuntime.RuntimeData.DataContext.SaveChanges();
                DataRuntime.RuntimeData.PlaneOrders = DataRuntime.RuntimeData.DataContext.PlaneOrders.ToList();
                planeOrderResult.Add("Succeeded", true);
                planeOrderResult.Add("OrderID", newOrder.ID);
            }
            catch (Exception e)
            {
                planeOrderResult.Add("Succeeded", false);
                planeOrderResult.Add("Error", e.Message);
            }
            return(Json(planeOrderResult, JsonRequestBehavior.DenyGet));
        }
コード例 #2
0
        /// <summary>
        /// 添加到订单
        /// </summary>
        /// <param name="planeOrder">订单</param>
        /// <returns></returns>
        public int AddPlaneOrder(PlaneOrder planeOrder)
        {
            using (IDbConnection conn = new MySqlConnection(connection))
            {
                string sql    = string.Format("INSERT into planeorder VALUES(null,'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", planeOrder.OrderUnitPrice, planeOrder.OrderLeaveCity, planeOrder.OrderArriveCity, planeOrder.OrderLeaveDate, planeOrder.OrderTypeID, planeOrder.OrderTicket, planeOrder.OrderLeaveTime, planeOrder.OrderArriveTime, planeOrder.OrderPhone, planeOrder.OrderState, planeOrder.OrderTotalsum, planeOrder.AccountName);
                int    result = conn.Execute(sql);

                string sqlsel = "select * from plane where ID=" + planeOrder.PlaneID;
                Plane  plane  = conn.Query <Plane>(sqlsel).FirstOrDefault();
                if (planeOrder.OrderTicket <= plane.Inventory)
                {
                    plane.Inventory = plane.Inventory - planeOrder.OrderTicket;
                    string sqlUpd = "update plane set Inventory=" + plane.Inventory + " where ID=" + planeOrder.PlaneID;
                    conn.Execute(sqlUpd);
                }
                else
                {
                    result = -1;
                }



                return(result);
            }
        }
コード例 #3
0
        public int AddPlaneOrder(PlaneOrder planeOrder)
        {
            int i = this.PlaneRespository.AddPlaneOrder(planeOrder);

            return(i);
        }