Exemplo n.º 1
0
        public bool Update(EmployeeM updEmployee)
        {
            bool isUpdated = false;
            bool isFound   = false;

            // Age must be between 18 and 65.
            if (updEmployee.Age < 18 || updEmployee.Age > 65)
            {
                throw new ArgumentException("Invalid age. Must be between 18 and 65.");
            }

            for (int i = 0; i < MyEmployees.Count; i++)
            {
                if (MyEmployees[i].Id == updEmployee.Id)
                {
                    MyEmployees[i].Name = updEmployee.Name;
                    MyEmployees[i].Age  = updEmployee.Age;

                    isUpdated = true;
                    isFound   = true;
                    break;
                }
            }

            // Error message in case the employee not found.
            if (!isFound)
            {
                throw new ArgumentException("Employee not found.");
            }

            return(isUpdated);
        }
Exemplo n.º 2
0
        public bool Add(EmployeeM freshEmployee)
        {
            // Age must be between 18 and 65.
            if (freshEmployee.Age < 18 || freshEmployee.Age > 65)
            {
                throw new ArgumentException("Invalid age. Must be between 18 and 65.");
            }

            // Adds a new employee with the same details.
            MyEmployees.Add(new EmployeeM()
            {
                Id = freshEmployee.Id, Name = freshEmployee.Name, Age = freshEmployee.Age
            });

            return(true);
        }