public async Task ChangeOrganizationActiveStatusAsync(OrganizationActiveStatusDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } var orgStatusCalculationDto = await _organizationsRepository .GetOrganizationStatusCalculationDataAsync(dto.Id) .ConfigureAwait(false); dto.Status = !dto.IsActive ? OrganizationStatus.NotActive : CalculateOrganizationStatus(orgStatusCalculationDto, false); await _organizationsRepository .ChangeOrganizationActiveStatusAsync(dto) .ConfigureAwait(false); }
public async Task <ActionResult> ChangeOrganizationActiveStateAsync(OrganizationActiveStatusDto dto) { if (dto == null) { return(BadRequest()); } await _organizationsService .ChangeOrganizationActiveStatusAsync(dto) .ConfigureAwait(false); if (!_organizationsService.ValidationDictionary.IsValid()) { return(BadRequest(new { errors = _organizationsService.ValidationDictionary.GetErrorMessages() })); } return(NoContent()); }
public async Task ChangeOrganizationActiveStatusAsync(OrganizationActiveStatusDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } await using var context = ContextFactory.CreateDataContext(null); var organizations = context.Organizations; var entity = await organizations.AsNoTracking() .FirstOrDefaultAsync(t => t.Id == dto.Id) .ConfigureAwait(false); if (entity != null) { entity.Status = dto.Status; entity.LastUpdatedOn = DateTime.UtcNow; context.Entry(entity).State = EntityState.Modified; context.Organizations.Update(entity); await context.SaveChangesAsync() .ConfigureAwait(false); } }