public async Task <Organisation> UpdateOrganisation( Organisation organisation) { var organisationEntity = _assessorDbContext.Organisations.First(q => q.EndPointAssessorOrganisationId == organisation.EndPointAssessorOrganisationId); if (string.IsNullOrEmpty(organisation.PrimaryContact)) { organisationEntity.PrimaryContact = null; } else { var contact = _assessorDbContext.Contacts.First(q => q.Username == organisation.PrimaryContact); organisationEntity.PrimaryContact = contact.Username; } // Only update if a new status was specified! if (!string.IsNullOrEmpty(organisation.Status)) { organisationEntity.Status = organisation.Status; } // Only update if OrganisationData was specified! if (organisation.OrganisationData != null) { organisationEntity.OrganisationData = organisation.OrganisationData; } organisationEntity.EndPointAssessorName = organisation.EndPointAssessorName; organisationEntity.EndPointAssessorUkprn = organisation.EndPointAssessorUkprn; organisationEntity.ApiEnabled = organisation.ApiEnabled; organisationEntity.ApiUser = organisation.ApiUser; // Workaround for Mocking _assessorDbContext.MarkAsModified(organisationEntity); await _assessorDbContext.SaveChangesAsync(); return(organisationEntity); }
public async Task Update(UpdateContactRequest updateContactRequest) { var contactEntity = await _assessorDbContext.Contacts.FirstOrDefaultAsync(q => q.Username == updateContactRequest.UserName); if (contactEntity == null) { contactEntity = await _assessorDbContext.Contacts.OrderBy(q => q.CreatedAt).FirstOrDefaultAsync(q => q.Email == updateContactRequest.Email); } if (contactEntity == null) { throw new NotFound(); } contactEntity.Username = updateContactRequest.UserName; contactEntity.DisplayName = updateContactRequest.DisplayName; contactEntity.Email = updateContactRequest.Email; // Workaround for Mocking _assessorDbContext.MarkAsModified(contactEntity); await _assessorDbContext.SaveChangesAsync(); }