Ejemplo n.º 1
0
        //update employee

        public IHttpActionResult PutEmployee(Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data"));
            }

            using (var x = new employeeEntities3())
            {
                var CheckExistingEmployee = x.employees.Where(c => c.ID == employee.ID)
                                            .FirstOrDefault <employee>();
                if (CheckExistingEmployee != null)
                {
                    CheckExistingEmployee.Name    = employee.Name;
                    CheckExistingEmployee.Surname = employee.Surname;

                    x.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }

            return(Ok());
        }
Ejemplo n.º 2
0
        //create employee

        public IHttpActionResult PostNewEmployee(Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Data"));
            }

            using (var x = new employeeEntities3())
            {
                x.employees.Add(new employee()
                {
                    Name    = employee.Name,
                    Surname = employee.Surname,
                });
                x.SaveChanges();
            }
            return(Ok());
        }
Ejemplo n.º 3
0
        //delete employee

        public IHttpActionResult DeleteEmployee(int ID)
        {
            if (ID <= 0)
            {
                return(BadRequest("Invalid ID"));
            }

            using (var x = new employeeEntities3())
            {
                var employee = x.employees
                               .Where(c => c.ID == ID)
                               .FirstOrDefault();

                x.Entry(employee).State = System.Data.Entity.EntityState.Deleted;
                x.SaveChanges();
            }

            return(Ok());
        }
Ejemplo n.º 4
0
    {   //read employee
        public IHttpActionResult GetAllEmployee()
        {
            IList <Employee> employee = null;

            using (var x = new employeeEntities3())

            {
                employee = x.employees
                           .Select(c => new Employee()
                {
                    ID      = c.ID,
                    Name    = c.Name,
                    Surname = c.Surname,
                }).ToList <Employee>();
            }
            if (employee.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(employee));
        }