public async Task <bool> CreateEmployee(Employee employee) { // List<EmployeeCourse> employeeCourseList = new List<EmployeeCourse>(); employee.RowId = Guid.NewGuid().ToString(); _dbContext.Add(employee); try { await _dbContext.SaveChangesAsync(); for (int i = 3; i < 8; i++) { EmployeeCourse employeeCourse = new EmployeeCourse(); employeeCourse.EmployeeID = employee.EmployeeID; employeeCourse.isComplete = false; employeeCourse.CourseID = i; _dbContext.Add(employeeCourse); } await _dbContext.SaveChangesAsync(); return(true); } catch (DbUpdateException) { return(false); } }
public async Task <bool> ChangeCompleteStatus(int id) { var employeeCourse = await _dbContext.EmployeeCourses.FindAsync(id); if (employeeCourse == null) { return(false); } employeeCourse.UpdatedOn = DateTime.Now; employeeCourse.isComplete = !employeeCourse.isComplete; if (employeeCourse.isComplete) { employeeCourse.CompletedOn = DateTime.Now; } //else //{ // employeeCourse.CompletedOn = null; //} _dbContext.Entry(employeeCourse).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); return(true); }
public async Task <bool> CreateCourse(Course course) { course.RowId = Guid.NewGuid().ToString(); _dbContext.Add(course); try { await _dbContext.SaveChangesAsync(); return(true); } catch (DbUpdateException) { return(false); } }