Ejemplo n.º 1
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (API_DatabaseEntities db = new API_DatabaseEntities())
                {
                    var checkeidexistance = db.tbl_Employee.FirstOrDefault(v => v.ID == id);
                    if (checkeidexistance == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id" + id.ToString() + " " + "Not found"));
                    }

                    else
                    {
                        db.tbl_Employee.Remove(checkeidexistance);
                        db.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 2
0
 public HttpResponseMessage Post([FromBody] tbl_Employee employee)
 {
     using (API_DatabaseEntities db = new API_DatabaseEntities())
     {
         try
         {
             db.tbl_Employee.Add(employee); //tbl_Employee is an object of DbSet<tbl_Employee> tbl_Employee
             db.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, employee);
             message.Headers.Location = new Uri(Request.RequestUri + employee.ID.ToString());
             return(message);
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }