Beispiel #1
0
 public ActionResult Edit(Employee employee)
 {
     if (TryUpdateModel(employee))
     {
         _employeeDb.Entry(employee).State = EntityState.Modified;
         _employeeDb.SaveChanges();
         return(RedirectToAction("Index", new { id = employee.Id }));
     }
     return(View(employee));
 }
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
 public async Task ExecuteAsync(EmployeeEntity employee)
 {
     using (var dbContext = new EmployeeDb(_connectionString))
     {
         //var model = await dbContext.Employee.AddAsync(employee);
         dbContext.Entry(employee).State = EntityState.Modified;
         await dbContext.SaveChangesAsync();
     }
 }
Beispiel #4
0
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Beispiel #5
0
        // PUT api/HomeApi/5
        public HttpResponseMessage PutEmployee(int id, Employee employee)
        {
            if (ModelState.IsValid && id == employee.EmployeeId)
            {
                db.Entry(employee).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }