예제 #1
0
        public async Task <AccountResult> CreateEmployee(Employee Employee)
        {
            var resultMessage = new AccountResult();

            _context.Employees.Add(Employee);
            await _context.SaveChangesAsync();

            //var success =  _context.SaveChanges() > 0;

            //if (success)
            //    return success;

            return(resultMessage);

            throw new Exception("Problem Saving Changes");
        }
예제 #2
0
        public async Task <AccountResult> DeleteEmployee(Guid id)
        {
            var resultMessage = new AccountResult();

            var Employee = await _context.Employees.FindAsync(id);

            _context.Remove(Employee);

            var success = _context.SaveChanges() > 0;

            if (success)
            {
                return(resultMessage);
            }

            throw new Exception("Problem Saving Changes");
        }
예제 #3
0
        public async Task <AccountResult> EditEmployee(Employee employee)
        {
            var resultMessage = new AccountResult();

            var oldEmployee = await _context.Employees.FindAsync(employee.Id);

            if (oldEmployee.Id != null)
            {
                oldEmployee.FirstName    = employee.FirstName ?? oldEmployee.FirstName;
                oldEmployee.LastName     = employee.LastName ?? oldEmployee.LastName;
                oldEmployee.Address      = employee.Address ?? oldEmployee.Address;
                oldEmployee.Organization = employee.Organization ?? oldEmployee.Organization;
            }
            var success = _context.SaveChanges() > 0;

            if (success)
            {
                return(resultMessage);
            }

            throw new Exception("Problem Saving Changes");
        }