コード例 #1
0
        /// <summary>
        /// This function is asynchronous, since the retrieval takes some time.
        /// This function retrievs
        /// </summary>
        /// <param name="filterValue">Filter can be Employee Id or Name.
        /// In case th</param>
        /// <returns>List of Employee records</returns>
        public async Task GetEmployeesAsync(string filterValue = "")
        {
            Task <List <Employee> > retrievalTask;
            List <Employee>         _retrievedEmployees = new List <Employee>();

            try
            {
                switch (_searchFilter)
                {
                case SearchFilter.NoFilter:
                    //implement only page wise retrieval of employess and show the first page
                    retrievalTask = Task.Run(() => _employeeQueryHandler.GetEmployeesAsync());
                    await retrievalTask;
                    _retrievedEmployees = retrievalTask.Result;
                    break;

                case SearchFilter.ByEmployeeId:
                    int.TryParse(filterValue, out int employeeId);
                    Employee rerievedEmployee = _employeeQueryHandler.GetEmployeeById(employeeId);
                    if (rerievedEmployee != null)
                    {
                        _retrievedEmployees.Add(rerievedEmployee);
                    }
                    break;

                case SearchFilter.ByEmployeeName:
                    retrievalTask = Task.Run(() => _employeeQueryHandler.GetEmployeesByNameAsync(filterValue));
                    await retrievalTask;
                    _retrievedEmployees = retrievalTask.Result;
                    break;

                case SearchFilter.ByPageNumber:
                    int.TryParse(filterValue, out int pageToRetrieve);
                    retrievalTask = Task.Run(() => _employeeQueryHandler.GetEmployeesByPageAsync(pageToRetrieve));
                    await retrievalTask;
                    _retrievedEmployees = retrievalTask.Result;
                    TotalNoOfPages      = _employeeQueryHandler.ToTalNoOfPages;
                    break;

                default:
                    break;
                }
            }
            catch (Exception ec)
            {
                _messageToUserEventArgs.IsOperationSucceeded = false;
                _messageToUserEventArgs.MessageToShow        = ec.Message;
                ShowMessageToUserEvent?.Invoke(this, _messageToUserEventArgs);
            }
            RetrievedEmployees = _retrievedEmployees;
            return;
        }
コード例 #2
0
        /// <summary>
        /// This function takes care of adding, modifying and making inactive the employ record
        /// </summary>
        /// <returns></returns>
        public bool UpdateEmployee()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            bool   isEmployeeUpdated = false;
            string msgToShow         = string.Empty;

            try
            {
                string updatedTime = DateTimeOffset.Now.ToString("yyyy-MM-dd'T'HH:mm:ssK");
                _employeeToProcess.UpdatedAt = updatedTime;
                switch (_updateType)
                {
                case UpdateType.AddEmployee:
                    _employeeToProcess.Status    = "Active";
                    _employeeToProcess.CreatedAt = updatedTime;
                    _employeeToProcess           = _employeeUpdateHandler.AddEmployee(_employeeToProcess);
                    isEmployeeUpdated            = (_employeeToProcess.Id > 0);
                    break;

                case UpdateType.EditEmployee:
                    isEmployeeUpdated = _employeeUpdateHandler.EditEmployee(_employeeToProcess);
                    break;

                case UpdateType.RemoveEmployee:
                    _employeeToProcess.Status = "Inactive";
                    isEmployeeUpdated         = _employeeUpdateHandler.RemoveEmployee(_employeeToProcess.Id);
                    break;
                }
                _messageToUserEventArgs.IsOperationSucceeded = isEmployeeUpdated;
                ShowMessageToUserEvent?.Invoke(this, _messageToUserEventArgs);

                if (isEmployeeUpdated)
                {
                    //create a new employee object
                    _employeeToProcess = new Employee();
                    ClearView();
                }
            }
            catch (Exception ec)
            {
                _messageToUserEventArgs.IsOperationSucceeded = false;
                _messageToUserEventArgs.MessageToShow        = ec.Message;
                ShowMessageToUserEvent?.Invoke(this, _messageToUserEventArgs);
            }
            Mouse.OverrideCursor = null;
            return(isEmployeeUpdated);
        }