示例#1
0
        public EventMgmt Get(int id)
        {
            SqlDataReader reader       = null;
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = @"Server=(localdb)\v11.0;Database=MVCAPP;";

            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandType = CommandType.Text;
            sqlCmd.CommandText = "Select * from EventTB where EventID=" + id + "";
            sqlCmd.Connection  = myConnection;
            myConnection.Open();
            reader = sqlCmd.ExecuteReader();
            EventMgmt ee = null;

            while (reader.Read())
            {
                ee                = new EventMgmt();
                ee.EventID        = Convert.ToInt32(reader.GetValue(0));
                ee.EventName      = Convert.ToString(reader.GetValue(1));
                ee.EventStartDate = Convert.ToDateTime(reader.GetValue(2));
                ee.EventEndDate   = Convert.ToDateTime(reader.GetValue(3));
                ee.EventLocation  = Convert.ToString(reader.GetValue(4));
            }

            myConnection.Close();
            return(ee);
        }
示例#2
0
        static async Task MyAPIPut(HttpClient cons)
        {
            using (cons)
            {
                HttpResponseMessage res = await cons.GetAsync("api/values/2");

                res.EnsureSuccessStatusCode();
                if (res.IsSuccessStatusCode)
                {
                    // EventMgmt tag = await res.Content.ReadAsAsync<EventMgmt>();
                    EventMgmt tag = new EventMgmt();
                    // tag.EventID = "2";
                    tag.EventName = "House warming";
                    res           = cons.PutAsJsonAsync("api/values/2", "House warming22").Result;
                    Console.WriteLine("\n");
                    Console.WriteLine("---------------------Calling put Operation------------------------");
                    Console.WriteLine("\n");
                    Console.WriteLine("tagId    tagName          tagDescription");
                    Console.WriteLine("-----------------------------------------------------------");
                    Console.WriteLine("{0}\t{1}\t\t{2}", tag.EventID, tag.EventName, tag.EventLocation);
                    Console.ReadLine();
                }
            }
        }