예제 #1
0
        public async Task <string> UpdateEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return("Cannot be updated!");
            }

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

            try
            {
                await _context.SaveChangesAsync();

                return("Data updated successfully!");
            }
            catch (DbUpdateConcurrencyException exp)
            {
                if (!EmployeeExists(id))
                {
                    return("Data not found!");
                }
                else
                {
                    throw (exp);
                }
            }
        }
예제 #2
0
 public void InsertOrUpdate(Employee employee)
 {
     if (employee.Id == default(int))
     {
         // New entity
         context.Employees.Add(employee);
     }
     else
     {
         // Existing entity
         context.Entry(employee).State = System.Data.Entity.EntityState.Modified;
     }
 }