Esempio n. 1
0
        public async Task <EntityEntry <Employee> > AddOrUpdateAsync(Employee entity)
        {
            var existedEmployee = await _indeavorDbContext.Employees.FirstOrDefaultAsync(
                x => x.Id == entity.Id || x.Email == entity.Email || x.ENumber == entity.ENumber);

            if (existedEmployee != null)
            {
                existedEmployee.Update(entity);
                _indeavorDbContext.Entry(existedEmployee).State = EntityState.Modified;

                return(_indeavorDbContext.Entry(existedEmployee));
            }

            return(await _indeavorDbContext.Employees.AddAsync(entity));
        }
Esempio n. 2
0
        public async Task <EntityEntry <Department> > AddOrUpdateAsync(Department entity)
        {
            var existedDepartment = await _indeavorDbContext.Departments.FirstOrDefaultAsync(
                x => x.Id == entity.Id || x.Code == entity.Code);

            if (existedDepartment != null)
            {
                existedDepartment.Update(entity);
                _indeavorDbContext.Entry(existedDepartment).State = EntityState.Modified;

                return(_indeavorDbContext.Entry(existedDepartment));
            }

            return(await _indeavorDbContext.Departments.AddAsync(entity));
        }