Пример #1
0
        /// <summary>
        /// Updates worker with new data from
        /// </summary>
        /// <param name="">Updated worker</param>
        /// <returns>
        ///  0 if worker was updated successfully
        /// -1 if worker with such ID was not found
        /// </returns>
        public int EditWorker(IWorkerDTO updatedW)
        {
            // Get index of the being updated worker
            int wi = Workers.FindIndex(w => w.ID == updatedW.ID);

            // Check if worker type was changed
            // In this case need to "cast" new type
            // It is not real casting of a type, but creating instance of new type
            // and copiying proper fields.
            // Creation of an instance of new type is done through specific constructor
            // which copies readonly unique worker ID

            Worker newW = new Intern(updatedW);

            //if (updatedW.OriginalWorkerType != updatedW.SelectedWorkerType)
            //{
            // Here new Director(updatedW), new Employee(..), new Intern(..)
            // Create new type and update salary
            switch (updatedW.SelectedWorkerType)
            {
            case WorkerHierarchy.Director:
                newW = new Director(updatedW);
                break;

            case WorkerHierarchy.Employee:
                newW = new Employee(updatedW);
                (newW as Employee).HourlyRate  = updatedW.HourlyRate;
                (newW as Employee).HoursWorked = updatedW.HoursWorked;
                break;

            case WorkerHierarchy.Intern:
                newW.Salary = updatedW.IntSalary;
                break;
            }
            //}
            //else
            //{
            //	// Only update salary
            //	switch (updatedW.SelectedWorkerType)
            //	{
            //		case WorkerHierarchy.Director:
            //			break;
            //		case WorkerHierarchy.Employee:
            //			(newW as Employee).HourlyRate  = updatedW.HourlyRate;
            //			(newW as Employee).HoursWorked = updatedW.HoursWorked;
            //			break;
            //		case WorkerHierarchy.Intern:
            //			newW.Salary = updatedW.IntSalary;
            //			break;
            //	}
            //}

            Workers[wi] = newW;

            // Update worker's properties
            Workers[wi].Position      = updatedW.Position;
            Workers[wi].PositionTitle = updatedW.PositionTitle;

            var d = Department(updatedW.DeptID);

            UpdateSalaries(d as BaseDepartment);

            return(0);                      // Worker was updated successfully
        }
Пример #2
0
 public void DismissWorker(int ind)
 {
     //count--;
     //Workers.RemoveAt(ind);
     Workers.RemoveAt(Workers.FindIndex(p => p.Index == ind));
 }