Exemple #1
0
 public IEnumerable <OfficeEmployee> Get()
 {
     using (EmployeeServiceEntities entities = new EmployeeServiceEntities())
     {
         return(entities.OfficeEmployees.ToList());
     }
 }
Exemple #2
0
 public Employee GetEmployee(string code)
 {
     using (EmployeeServiceEntities entities = new EmployeeServiceEntities())
     {
         return(entities.Employees.FirstOrDefault(e => e.code == code));
     }
 }
Exemple #3
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 #4
0
        public HttpResponseMessage Get(int id)
        {
            using (EmployeeServiceEntities entities = new EmployeeServiceEntities())
            {
                var entity = entities.OfficeEmployees.FirstOrDefault(e => e.empid == id);

                if (entity != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, entity));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id = " + id.ToString() + "Not Found "));
                }
            }
        }
Exemple #5
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 #6
0
        public IEnumerable <Employee> Get()
        {
            EmployeeServiceEntities _db = new EmployeeServiceEntities();
            IEnumerable <Employee>  empList;

            try
            {
                empList = _db.Employees.ToList();
            }
            catch (Exception e)
            {
                empList = null;
            }
            finally
            {
            }
            return(empList);
        }
Exemple #7
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));
            }
        }