コード例 #1
0
        public IHttpActionResult SearchEmployee(int id)
        {
            var employee = OfficeEmployee.GetEmployeeById(id);

            if (employee == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(employee));
            }
        }
コード例 #2
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();
            }
        }
コード例 #3
0
        // [ActionFilterDemo]
        public HttpResponseMessage Search(int id)
        {
            var employee = OfficeEmployee.GetEmployeeById(id);

            if (employee == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, new Exception("No Employee Available")));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, employee));
            }
        }
コード例 #4
0
        public IHttpActionResult PutComplex(int id, OfficeEmployee officeEmployee)
        {
            var empResult = OfficeEmployee.GetEmployeeById(id);

            if (empResult == null)
            {
                return(NotFound());
            }
            else
            {
                empResult.Name   = officeEmployee.Name;
                empResult.Salary = officeEmployee.Salary;

                return(Ok(empResult));
            }
        }
コード例 #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));
            }
        }
コード例 #6
0
 public OfficeEmployee FindEmployeeById(int id)
 {
     return(OfficeEmployee.GetEmployeeById(id));
 }
コード例 #7
0
        public List <OfficeEmployee> GetAllEMployees()
        {
            var employees = OfficeEmployee.GetEmployeeDetails();

            return(employees);
        }
コード例 #8
0
 public string Post(OfficeEmployee officeEmployee)
 {
     OfficeEmployee.AddEmployee(officeEmployee);
     return("Employee added sucessfully");
 }
コード例 #9
0
 public IHttpActionResult Put(int id, string name)
 {
     OfficeEmployee.GetEmployeeById(id).Name = name;
     return(Ok(name));
 }
コード例 #10
0
 public List <OfficeEmployee> GetAllEmployees()
 {
     return(OfficeEmployee.GetEmployeeDetails());
 }
コード例 #11
0
 public EmployeeController()
 {
     OfficeEmployee.GetEmployeeDetails();
 }