public void SetAddress(int employeeId, string address) { var employee = context.Employees.Find(employeeId); if (employee == null) { throw new ArgumentException("Invalid Id"); } employee.Address = address; context.SaveChanges(); }
public void SetManager(int employeeId, int managerId) { var employee = this.context.Employees.Find(employeeId); var manager = this.context.Employees.Find(managerId); if (employee == null || manager == null) { throw new ArgumentException("Invalid id"); } employee.Manager = manager; context.SaveChanges(); }
public bool Add(Employee entity) { if (_dbContext.Employees.Any(emp => emp.Id == entity.Id) || !IsValid(entity)) { return(false); } try { if (entity.Id == 0) { entity.Id = DataSet.Count + 1; } _dbContext.Employees.Add(entity); _dbContext.SaveChanges(); return(true); } catch (Exception e) { _logger.Error(e, $"Error Adding employee Id: {entity.Id} Name: {entity.Name} Job Title: {entity.JobTitle} !"); return(false); } }