public async Task <bool> UpdateEntityByIdAsync(OrganizationUpdateRequest request, int id) { var entity = _mapper.Map <OrganizationUpdateRequest, Organization>(request); entity.Id = id; var existingEntity = await GetEntityByIdAsync(id); //var test = !existingEntity.ImageURL.Equals(entity.ImageURL); /* Here error when I updated organization. * {System.NullReferenceException: Object reference not set to an instance of an object. * at Watcher.Core.Providers.LocalFileStorageProvider.UploadFileBase64Async(String base64string, String imageType, String containerName) * in C:\Users\Eugene\Documents\GitHub\bsa-2018-watcher\backend\Watcher.Core\Providers\LocalFileStorageProvider.cs:line 100} * * * if (existingEntity.ImageURL != null && !existingEntity.ImageURL.Equals(entity.ImageURL)) * { * await _fileStorageProvider.DeleteFileAsync(existingEntity.ImageURL); * } * entity.ImageURL = await _fileStorageProvider.UploadFileBase64Async(entity.ImageURL, request.ImageType); // TODO: change here for real image type */ // In returns updated entity, you could do smth with it or just leave as it is var updated = await _uow.OrganizationRepository.UpdateAsync(entity); var result = await _uow.SaveAsync(); return(result); }
public async Task <IWrappedResponse> Update(OrganizationUpdateRequest request) { var cmd = ServiceCommand <Organization, Rules.Organization.Update.MainRule> .Create(_serviceProvider) .When(new Rules.Organization.Update.MainRule(request)) .Then(UpdateAction); return(await cmd.Execute()); }
public async Task Test_organizations_crud_sequence() { var initialOrganizations = await _apiClient.Organizations.GetAllAsync(new Paging.PaginationInfo()); var createRequest = new OrganizationCreateRequest { Name = ($"integration-testing-" + MakeRandomName()).ToLower(), DisplayName = "Integration testing", Branding = new OrganizationBranding { LogoUrl = "https://cdn.auth0.com/manhattan/versions/1.2800.0/assets/./badge.png", Colors = new BrandingColors { Primary = "#ff0000", PageBackground = "#00ff00" } } }; var createResponse = await _apiClient.Organizations.CreateAsync(createRequest); createResponse.Should().NotBeNull(); createResponse.Name.Should().Be(createRequest.Name); createResponse.Branding.LogoUrl.Should().Be(createRequest.Branding.LogoUrl); createResponse.Branding.Colors.Primary.Should().Be("#ff0000"); createResponse.Branding.Colors.PageBackground.Should().Be("#00ff00"); var updateRequest = new OrganizationUpdateRequest { DisplayName = $"Integration testing 123", }; var updateResponse = await _apiClient.Organizations.UpdateAsync(createResponse.Id, updateRequest); updateResponse.Should().NotBeNull(); updateResponse.DisplayName.Should().Be(updateRequest.DisplayName); var organization = await _apiClient.Organizations.GetAsync(createResponse.Id); organization.Should().NotBeNull(); organization.DisplayName.Should().Be(updateResponse.DisplayName); var organizationByName = await _apiClient.Organizations.GetByNameAsync(organization.Name); organizationByName.Should().NotBeNull(); organizationByName.DisplayName.Should().Be(updateResponse.DisplayName); var organizations = await _apiClient.Organizations.GetAllAsync(new Paging.PaginationInfo()); organizations.Count.Should().Be(initialOrganizations.Count + 1); await _apiClient.Organizations.DeleteAsync(updateResponse.Id); Func <Task> getFunc = async() => await _apiClient.Organizations.GetAsync(organization.Id); getFunc.Should().Throw <ErrorApiException>().And.Message.Should().Be("No organization found by that id or name"); }
public virtual async Task <ActionResult> Update([FromRoute] int id, [FromBody] OrganizationUpdateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _organizationService.UpdateEntityByIdAsync(request, id); if (!result) { return(StatusCode(500)); } return(NoContent()); }
public async Task <Organization> UpdateAsync(Organization organization) { using (_loggerScope(_logger, $"PutAsync")) using (var client = _apiClient.CreateClient(ResourceUri)) { var request = new OrganizationUpdateRequest(organization); var response = await client.PutAsJsonAsync(organization.Id.ToString(), request).ConfigureAwait(false); if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { _logger.LogInformation("Cannot update organization as organization {0} cannot be found", organization.Id); return(null); } response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsAsync <OrganizationResponse>(); return(result.Organization); } }
public MainRule(OrganizationUpdateRequest request, IRule parentRule = null) { // Create Context Context = new ContextModel(request, this); ParentRule = parentRule; }
/// <summary> /// Updates an organization. /// </summary> /// <param name="id">The id of the organization you want to update.</param> /// <param name="request">The <see cref="OrganizationUpdateRequest"/> containing the properties of the organization you want to update.</param> /// <returns>The <see cref="Organization"/> that was updated.</returns> public Task <Organization> UpdateAsync(string id, OrganizationUpdateRequest request) { return(Connection.SendAsync <Organization>(new HttpMethod("PATCH"), BuildUri($"organizations/{EncodePath(id)}"), request, DefaultHeaders)); }
public async Task <ActionResult <Organization> > Patch([FromBody] OrganizationUpdateRequest request) { return(await _organizationsService.Update(request).Convert <Organization>(this)); }