简体   繁体   中英

how do I add employee ID and create collection and list for employees?

public class Employee : IEmployee
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime StartDate { get; set; }
    public PayFrequency PayFrequency { get; set; }
    public decimal Salary { get; set; }
    public SickPay SickPay { get; set; }


    //create collection and list for employees
    //create employee
    //view employee
    //update employee
    //delete employee
    //add employee ID

    public static IEmployee CreateEmployee(string fName, string lName, DateTime startDate, PayFrequency payFrequency, decimal salary, SickPay sickPay)
    {
        
        Employee employee = new Employee();
        employee.FirstName = fName;
        employee.LastName = lName;
        employee.StartDate = startDate;
        employee.PayFrequency = payFrequency;
        employee.Salary = salary;
        employee.SickPay = sickPay;
        return employee;           
    }
}

I have this code and I need to add an employee ID and create a collection and list for employees to show on console, but I am not sure how to do it.

void IEmployee.AddDeduction(Deduction type)
{
    //switch case or if else, 
    //based on the deduction type calculate the deduction
}

decimal IEmployee.CalculateLabourCost(DateTime weekStart, int hours, int minutes, decimal sickdays)
{
    //Calculate salary logic
    return 0;
}

This is also part of it. I need to calculate their salary, but I am not sure how do I do it either. I am not sure how to start the calculation. I want to calculate the employees salary according to their pay frequency and any deductions or any schemes.

In your code, In properties add EmployeeId as string datatype like

public string EmployeeId {get;set;}.  

In CreateEmployee() method update your code as

Guid guid = Guid.NewGuid();

EmployeeId=guid.ToString();

here, everytime new employee is created guid generate a unique id and stores in EmployeeId Guid generates a unique id everytime is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM