private static void PrepareCommand(SqlCommand command, SingleOrderModel singleOrder)
 {
     command.Parameters.AddWithValue("@CustomerId", singleOrder.CustomerId);
     command.Parameters.AddWithValue("@PaymentType", singleOrder.PaymentType);
     command.Parameters.AddWithValue("@Adress", singleOrder.Adress);
     command.Parameters.AddWithValue("@DeliveryType", singleOrder.DeliveryType);
     command.Parameters.AddWithValue("@Price", singleOrder.Price);
 }
        public static int Insert(Database db, SingleOrderModel singleOrder)
        {
            db.Connect();

            SqlCommand command = db.CreateCommand(SQL_INSERT);

            PrepareCommand(command, singleOrder);

            int ret = db.ExecuteNonQuery(command);

            db.Close();

            return(ret);
        }
Exemplo n.º 3
0
        public static int CreateSingleOrder(int id, int customerid, string paymenttype, string adress, string deliverytype, double price)
        {
            db = new Database();
            SingleOrderModel data = new SingleOrderModel()
            {
                CustomerId   = customerid,
                PaymentType  = paymenttype,
                Adress       = adress,
                DeliveryType = deliverytype,
                Price        = price,
            };

            return(SingleOrderDao.Insert(db, data));
        }
        private static Collection <SingleOrderModel> Read(SqlDataReader reader)
        {
            Collection <SingleOrderModel> orders = new Collection <SingleOrderModel>();

            while (reader.Read())
            {
                int i = -1;
                SingleOrderModel order = new SingleOrderModel();
                order.Id           = reader.GetInt32(++i);
                order.CustomerId   = reader.GetInt32(++i);
                order.PaymentType  = reader.GetString(++i);
                order.Adress       = reader.GetString(++i);
                order.DeliveryType = reader.GetString(++i);
                order.Price        = reader.GetDouble(++i);
                orders.Add(order);
            }
            return(orders);
        }
 public int Post([FromBody] SingleOrderModel model)
 {
     return(SingleOrderProcessor.CreateSingleOrder(model.Id, model.CustomerId, model.PaymentType, model.Adress,
                                                   model.DeliveryType, model.Price));
 }