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));
        }
Esempio n. 2
0
        public IHttpActionResult PutTRABALHADOR(int id, TRABALHADOR tRABALHADOR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tRABALHADOR.cd_trabalhador)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public HttpResponseMessage Put(Request.Department department)
        {
            EmployeeModel employeeModel = new EmployeeModel();
            var           dep           = MapperWrapper.Mapper.Map <Department>(department);

            employeeModel.Entry(dep).State = EntityState.Modified;
            employeeModel.SaveChanges();
            return(Request.CreateResponse("Success"));
        }
Esempio n. 4
0
        public HttpResponseMessage Put(Request.Employee employee)
        {
            EmployeeModel employeeModel = new EmployeeModel();
            var           dep           = MapperWrapper.Mapper.Map <EmployeeRepository.Employee>(employee);

            employeeModel.Entry(dep).State = EntityState.Modified;
            employeeModel.SaveChanges();
            return(Request.CreateResponse("Success"));
        }
 public ActionResult Edit([Bind(Include = "EmployeeId,LastName,FirstName")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
        public HttpResponseMessage Delete(int departmentid)
        {
            EmployeeModel employeeModel = new EmployeeModel();
            var           department    = employeeModel.Departments.Find(departmentid);
            var           dep           = MapperWrapper.Mapper.Map <Department>(department);

            employeeModel.Entry(dep).State = EntityState.Deleted;
            employeeModel.SaveChanges();
            return(Request.CreateResponse(HttpStatusCode.OK, dep));
        }
Esempio n. 7
0
 public ActionResult Edit([Bind(Include = "ID,Name,Gender,Email,EmailConfirm")] Employee employee)// lesson 85 had to add EmailConfirm
 {
     if (ModelState.IsValid)
     {
         _db.Entry(employee).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Esempio n. 8
0
        public HttpResponseMessage Delete(int employeeid)
        {
            EmployeeModel employeeModel = new EmployeeModel();
            var           employee      = employeeModel.Employees.Find(employeeid);
            var           dep           = MapperWrapper.Mapper.Map <EmployeeRepository.Employee>(employee);

            employeeModel.Entry(dep).State = EntityState.Deleted;
            employeeModel.SaveChanges();
            return(Request.CreateResponse("Success"));
        }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "Id,Name,Gender,Age,Position,Office,HireDate,Salary,DepartmentId")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DepartmentName", employee.DepartmentId);
     return(View(employee));
 }