Example #1
0
        public async Task Update(
            Guid reservationId,
            ReservationStatus status,
            DateTime?confirmedDate     = null,
            long?cohortId              = null,
            long?draftApprenticeshipId = null)
        {
            using (var transaction = _dataContext.Database.BeginTransaction())
            {
                var reservation = await _dataContext.Reservations.FindAsync(reservationId);

                if (reservation == null)
                {
                    throw new InvalidOperationException($"Reservation not found in database with ReservationId: {reservationId}");
                }

                if (!reservation.IsLevyAccount)
                {
                    if (status == ReservationStatus.Pending &&
                        reservation.Status != (short)ReservationStatus.Confirmed &&
                        !reservation.ConfirmedDate.HasValue &&
                        !reservation.CohortId.HasValue &&
                        !reservation.DraftApprenticeshipId.HasValue
                        )
                    {
                        throw new DbUpdateException($"Unable to change reservation {reservationId} to pending as it has not been confirmed", (Exception)null);
                    }
                }


                reservation.Status = (short)status;

                switch (status)
                {
                case ReservationStatus.Confirmed:
                    reservation.ConfirmedDate         = confirmedDate;
                    reservation.CohortId              = cohortId;
                    reservation.DraftApprenticeshipId = draftApprenticeshipId;
                    break;

                case ReservationStatus.Pending:
                    reservation.ConfirmedDate         = null;
                    reservation.CohortId              = null;
                    reservation.DraftApprenticeshipId = null;
                    break;
                }

                _dataContext.SaveChanges();
                transaction.Commit();
            }
        }
        public async Task Add(Account account)
        {
            var existingEntity = await _dataContext.Accounts.FindAsync(account.Id);

            if (existingEntity != null)
            {
                return;
            }

            try
            {
                await _dataContext.Accounts.AddAsync(account);

                _dataContext.SaveChanges();
            }
            catch (DbUpdateException e)
            {
                if (e.GetBaseException() is SqlException sqlException &&
                    (sqlException.Number == UniqueConstraintViolation || sqlException.Number == UniqueKeyViolation))
                {
                    _logger.LogWarning($"AccountRepository: Rolling back Id:{account.Id} - item already exists.");
                }
            }
        }
        public async Task Add(Course course)
        {
            var courseStored = await _reservationsDataContext.Apprenticeships.FindAsync(course.CourseId);

            if (courseStored != null)
            {
                courseStored.Level       = course.Level;
                courseStored.Title       = course.Title;
                courseStored.EffectiveTo = course.EffectiveTo;
            }
            else
            {
                await _reservationsDataContext.Apprenticeships.AddAsync(course);
            }
            _reservationsDataContext.SaveChanges();
        }
Example #4
0
        public async Task Add(ProviderPermission permission)
        {
            var existingPermission = await _dataContext.ProviderPermissions.FindAsync(permission.AccountId,
                                                                                      permission.AccountLegalEntityId, permission.ProviderId);

            if (existingPermission == null)
            {
                await _dataContext.ProviderPermissions.AddAsync(permission);
            }
            else
            {
                existingPermission.CanCreateCohort = permission.CanCreateCohort;
            }

            _dataContext.SaveChanges();
        }
Example #5
0
        public async Task Add(Course course)
        {
            using (var transaction = _reservationsDataContext.Database.BeginTransaction())
            {
                var courseStored = await _reservationsDataContext.Apprenticeships.FindAsync(course.CourseId);

                if (courseStored != null)
                {
                    courseStored.Level       = course.Level;
                    courseStored.Title       = course.Title;
                    courseStored.EffectiveTo = course.EffectiveTo;
                }
                else
                {
                    await _reservationsDataContext.Apprenticeships.AddAsync(course);
                }
                _reservationsDataContext.SaveChanges();
                transaction.Commit();
            }
        }
        public async Task Add(ProviderPermission permission)
        {
            using (var transaction = _dataContext.Database.BeginTransaction())
            {
                var existingPermission = await _dataContext.ProviderPermissions.FindAsync(permission.AccountId,
                                                                                          permission.AccountLegalEntityId, permission.ProviderId);

                if (existingPermission == null)
                {
                    await _dataContext.ProviderPermissions.AddAsync(permission);
                }
                else
                {
                    existingPermission.CanCreateCohort = permission.CanCreateCohort;
                }

                _dataContext.SaveChanges();
                transaction.Commit();
            }
        }