コード例 #1
0
 // DELETE: api/Employee/5
 public void Delete(int id)
 {
     using (EmpModel db = new EmpModel())
     {
         db.Employees.Remove(db.Employees.Where(x => x.Id == id).FirstOrDefault());
         db.SaveChanges();
     }
 }
コード例 #2
0
 // POST: api/Employee
 public void Post([FromBody] Employee value)
 {
     using (EmpModel db = new EmpModel())
     {
         db.Employees.Add(value);
         db.SaveChanges();
     }
 }
コード例 #3
0
 // PUT: api/Employee/5
 public void Put(int id, [FromBody] Employee value)
 {
     using (EmpModel db = new EmpModel())
     {
         Employee y = db.Employees.Where(x => x.Id == id).FirstOrDefault();
         if (y != null)
         {
             y.FirstName = value.FirstName;
             y.LastName  = value.LastName;
             y.Salary    = value.Salary;
             y.Email     = value.Email;
             y.StartDate = value.StartDate;
             y.EndDate   = value.EndDate;
             y.Title     = value.Title;
             db.SaveChanges();
         }
     }
 }