Example #1
0
        public HttpResponseMessage Delete(int id)
        {
            var DataAccess = new EmployeeDataAccess();

            //new instance
            try
            {
                DataAccess.Delete(id);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception Ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Ex));
            }

            //using (var Connection= new SqlConnection(ConfigurationManager.ConnectionStrings["Chinook"].ConnectionString))
            //{
            //    try
            //    {
            //        Connection.Open();
            //        var Result = Connection.Execute("Delete From Employee where EmployeeId = @EmpId", new {EmpId = Id });

            //        return Request.CreateResponse(HttpStatusCode.OK,Result);

            //    }
            //    catch(Exception Ex)
            //    {
            //        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Ex);
            //    }
            //}
        }
 // DELETE api/values/5
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         var employee  = new EmployeeDataAccess();
         var rowDelete = employee.Delete(id);
         return(Request.CreateResponse(HttpStatusCode.OK, $"Row deleted {rowDelete}"));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                //connection.Open();

                //connection.Execute("delete from Employee where EmployeeId = @thisEmployee",
                //                    new { thisEmployee = id });

                var employeeData = new EmployeeDataAccess();
                var rowsDeleted  = employeeData.Delete(id);

                return(Request.CreateResponse(HttpStatusCode.OK, $"{rowsDeleted} rows deleted"));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }