Example #1
0
        public HttpResponseMessage Get()
        {
            // using (var connection =
            //new SqlConnection(ConfigurationManager.ConnectionStrings["Chinook"].ConnectionString))
            //{
            try
            {
                // connection.Open();

                //var result = connection.Query<EmployeeListResult>("select * " +
                //  "from Employee");
                //return Request.CreateResponse(HttpStatusCode.OK, result);

                var employeeData = new EmployeeDataAccess();
                //employeeData is an instance of the EmployeeDataAccess class so it can use it's functions
                var AllemployeeList = employeeData.GetAll();
                return(Request.CreateResponse(HttpStatusCode.OK, AllemployeeList));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Query blew up"));
            }
            //}
        }
        //api/employees (defined above in RoutePrefix)
        public HttpResponseMessage Get()
        {
            try
            {
                var employeeData = new EmployeeDataAccess();
                var employees    = employeeData.GetAll();

                return(Request.CreateResponse(HttpStatusCode.OK, employees));
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Query blew up"));
            }
            // The commented code has been moved to EmployeeDataAccess.cs / no Console.WriteLines / only interacting w database
            //    using (var connection =
            //        new SqlConnection(ConfigurationManager.ConnectionStrings["Chinook"].ConnectionString))
            //  {
            //       try
            //       {
            //           connection.Open();

            //            var result = connection.Query<EmployeeListResult>("select * " +
            //                                                              "from Employee");


            //           return Request.CreateResponse(HttpStatusCode.OK, result);
            //        }
            //        catch (Exception ex)
            //        {
            //            Console.WriteLine(ex.Message);
            //            Console.WriteLine(ex.StackTrace);
            //            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Query blew up");
            //        }
            //    }
        }
        //api/employees
        public HttpResponseMessage Get()
        {
            try
            {
                var employeeData = new EmployeeDataAccess();
                var employees    = employeeData.GetAll();

                return(Request.CreateResponse(HttpStatusCode.OK, employees));
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Query blew up"));
            }
        }