Exemple #1
0
        public void Put(int id, [FromBody] OfficeEmployee officeEmployee)
        {
            using (EmployeeServiceEntities entities = new EmployeeServiceEntities())
            {
                var entity = entities.OfficeEmployees.FirstOrDefault(e => e.empid == id);

                entity.empfirstName = officeEmployee.empfirstName;
                entity.empLastName  = officeEmployee.empLastName;
                entity.empSalary    = officeEmployee.empSalary;

                entities.SaveChanges();
            }
        }
Exemple #2
0
        public HttpResponseMessage Post([FromBody] OfficeEmployee officeEmployee)
        {
            try
            {
                using (EmployeeServiceEntities entities = new EmployeeServiceEntities())
                {
                    entities.OfficeEmployees.Add(officeEmployee);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, officeEmployee);
                    message.Headers.Location = new Uri(Request.RequestUri + officeEmployee.empid.ToString());
                    return(message);
                }
            }catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Exemple #3
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (EmployeeServiceEntities entities = new EmployeeServiceEntities())
                {
                    var entity = entities.OfficeEmployees.FirstOrDefault(e => e.empid == id);

                    if (entity != null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id = " + id.ToString() + "Not found to delete"));
                    }
                    else
                    {
                        entities.OfficeEmployees.Remove(entity);
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }