Beispiel #1
0
        public async Task <Em.VwEmpDetails> PutAsync(string id, Em.VwEmpDetails updateRequest)
        {
            int empNo;

            if (!int.TryParse(id, out empNo))
            {
                return(await Task.FromResult <Em.VwEmpDetails>(null));
            }

            Em.Employees employee = await _context.Employees
                                    .Where(i => i.EmpNo == empNo)
                                    .FirstOrDefaultAsync();

            Em.VwSalariesCurrent salary = await _context.VwSalariesCurrent
                                          .Where(i => i.EmpNo == empNo)
                                          .FirstOrDefaultAsync();

            Em.VwTitlesCurrent title = await _context.VwTitlesCurrent
                                       .Where(i => i.EmpNo == empNo)
                                       .FirstOrDefaultAsync();

            Em.VwDeptEmpCurrent deptEmp = await _context.VwDeptEmpCurrent
                                          .Where(i => i.EmpNo == empNo)
                                          .FirstOrDefaultAsync();

            if (title.Title != updateRequest.Title)
            {
                throw new NotImplementedException();
            }

            if (salary.Salary != updateRequest.Salary)
            {
                throw new NotImplementedException();
            }

            if (deptEmp.DeptNo != updateRequest.DeptNo)
            {
                throw new NotImplementedException();
            }

            if (employeeBasicInfoChanged(employee, updateRequest))
            {
                employee.BirthDate = updateRequest.BirthDate;
                employee.FirstName = updateRequest.FirstName;
                employee.LastName  = updateRequest.LastName;
                employee.Gender    = updateRequest.Gender;
                employee.HireDate  = updateRequest.HireDate;

                _context.Entry(employee).State = EntityState.Modified;
            }

            await _context.SaveChangesAsync();

            return(updateRequest);
        }
Beispiel #2
0
        private bool employeeBasicInfoChanged(
            Em.Employees employee,
            Em.VwEmpDetails employeeDetailUpdateRequest)
        {
            bool result =
                employee.BirthDate != employeeDetailUpdateRequest.BirthDate ||
                employee.FirstName != employeeDetailUpdateRequest.FirstName ||
                employee.LastName != employeeDetailUpdateRequest.LastName ||
                employee.Gender != employeeDetailUpdateRequest.Gender ||
                employee.HireDate != employeeDetailUpdateRequest.HireDate;

            return(result);
        }