//• SetBirthday <employeeId> <date: "dd-MM-yyyy"> – sets the birthday of the employee to the given date public string Execute(string[] args) { var empId = int.Parse(args[0]); DateTime loadedDate = DateTime.ParseExact(args[1], "dd-MM-yyyy", null); var currEmplpoyee = context.Employees.Find(empId); if (currEmplpoyee == null) { throw new ArgumentException("No such person in the system!"); } currEmplpoyee.Birthday = loadedDate; context.SaveChanges(); return ($"Birthday date {loadedDate} successfully added to person {currEmplpoyee.FirstName} {currEmplpoyee.LastName}"); }
public string Execute(string[] args) { var empId = int.Parse(args[0]); var managerId = int.Parse(args[1]); var employee = context.Employees.Find(empId); var manager = context.Employees.Find(managerId); if (employee == null) { throw new ArgumentException("No such person in system."); } employee.Manager = manager; context.SaveChanges(); return("Manager added"); }
public string Execute(string[] args) { //• SetAddress <employeeId> <address> – sets the address of the employee to the given string var empId = int.Parse(args[0]); var address = args[1]; var currEmplpoyee = context.Employees.Find(empId); if (currEmplpoyee == null) { throw new ArgumentException("No such person in the system!"); } currEmplpoyee.Address = address; if (context.SaveChanges() == 0) { throw new OperationCanceledException("No changes has been made"); } var empDto = mapper.CreateMappedObject <SetAddressDto>(currEmplpoyee); return($"Address {address} successfully added to person {empDto.FirstName} {empDto.LastName}"); }
public string Execute(string[] args) { //• AddEmployee <firstName> <lastName> <salary> – adds a new Employee to the database string firstName = args[0]; string lastName = args[1]; decimal salary = decimal.Parse(args[2]); //TODO validate var emp = new Employee() { FirstName = firstName, LastName = lastName, Salary = salary }; var empDto = mapper.CreateMappedObject <EmployeeDto>(emp); context.Employees.Add(emp); context.SaveChanges(); return($"Registered {empDto.FirstName} {empDto.LastName} with Salary ${empDto.Salary}."); }