public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EmployeeID)
            {
                return(BadRequest());
            }

            db.Entry(employee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public static void DeleteEmployee()
        {
            EmployeesDBEntities context = new EmployeesDBEntities();
            var employees = context.Employees;
            var employee  = new Employee {
                EmpID = 4
            };

            employees.Attach(employee);
            employees.Remove(employee);
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public static void ModifyEmployee()
        {
            EmployeesDBEntities context = new EmployeesDBEntities();
            var employee = context.Employees;
            var empList  = from emp in employee
                           orderby emp.Salary
                           select emp;

            foreach (var emp in empList)
            {
                if (emp.EmpID == 1)
                {
                    emp.Name = "mathew mcdonald";
                }
            }
            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Post([FromBody] Employee employee)
        {
            try
            {
                using (var entities = new EmployeesDBEntities())
                {
                    entities.Employees.Add(employee);
                    entities.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));
            }
        }