public async Task <IActionResult> PutCatalog(int id, UpdateCatalogRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var catalog = new Catalog { Id = id, Name = request.Name }; _context.Entry(catalog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CatalogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async stt::Task UpdateCatalogRequestObjectAsync() { moq::Mock <CatalogService.CatalogServiceClient> mockGrpcClient = new moq::Mock <CatalogService.CatalogServiceClient>(moq::MockBehavior.Strict); UpdateCatalogRequest request = new UpdateCatalogRequest { Catalog = new Catalog(), UpdateMask = new wkt::FieldMask(), }; Catalog expectedResponse = new Catalog { CatalogName = CatalogName.FromProjectLocationCatalog("[PROJECT]", "[LOCATION]", "[CATALOG]"), DisplayName = "display_name137f65c2", ProductLevelConfig = new ProductLevelConfig(), }; mockGrpcClient.Setup(x => x.UpdateCatalogAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Catalog>(stt::Task.FromResult(expectedResponse), null, null, null, null)); CatalogServiceClient client = new CatalogServiceClientImpl(mockGrpcClient.Object, null); Catalog responseCallSettings = await client.UpdateCatalogAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Catalog responseCancellationToken = await client.UpdateCatalogAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task <ServiceResponse <Catalog> > Update(Guid id, UpdateCatalogRequest request) { try { var result = await _baseRepository.GetById(id); if (result == null) { return(new ServiceResponse <Catalog>($"The requested Catalog could not be found")); } result.Name = request.Name; result.Description = request.Description; result.LastUpdated = DateTime.Now; result.EffectiveDate = request.EffectiveDate; result.EndDate = request.EndDate; result.EntityId = request.EntityId; result.Published = request.Published; await _baseRepository.Update(id, result); return(new ServiceResponse <Catalog>(result)); } catch (Exception ex) { return(new ServiceResponse <Catalog>($"An Error Occured While Updating The Catalog. {ex.Message}")); } }
/// <summary>Snippet for UpdateCatalog</summary> public void UpdateCatalogRequestObject() { // Snippet: UpdateCatalog(UpdateCatalogRequest, CallSettings) // Create client CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create(); // Initialize request argument(s) UpdateCatalogRequest request = new UpdateCatalogRequest { Catalog = new Catalog(), UpdateMask = new FieldMask(), }; // Make the request Catalog response = catalogServiceClient.UpdateCatalog(request); // End snippet }
/// <summary>Snippet for UpdateCatalogAsync</summary> public async Task UpdateCatalogRequestObjectAsync() { // Snippet: UpdateCatalogAsync(UpdateCatalogRequest, CallSettings) // Additional: UpdateCatalogAsync(UpdateCatalogRequest, CancellationToken) // Create client CatalogServiceClient catalogServiceClient = await CatalogServiceClient.CreateAsync(); // Initialize request argument(s) UpdateCatalogRequest request = new UpdateCatalogRequest { Catalog = new Catalog(), UpdateMask = new FieldMask(), }; // Make the request Catalog response = await catalogServiceClient.UpdateCatalogAsync(request); // End snippet }
public async Task <ActionResult> Edit(Guid id, EditCatalogViewModel request) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } if (!id.Equals(request.CatalogId)) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var catalogUpdateRequest = new UpdateCatalogRequest { CatalogId = request.CatalogId, Name = request.Name, Description = request.Description, EffectiveDate = request.EffectiveDate, EndDate = request.EndDate, EntityId = request.EntityId, Published = request.Published }; var result = await _catalogService.Update(id, catalogUpdateRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Catalog Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
public void UpdateCatalog() { moq::Mock <CatalogService.CatalogServiceClient> mockGrpcClient = new moq::Mock <CatalogService.CatalogServiceClient>(moq::MockBehavior.Strict); UpdateCatalogRequest request = new UpdateCatalogRequest { Catalog = new Catalog(), UpdateMask = new wkt::FieldMask(), }; Catalog expectedResponse = new Catalog { CatalogName = CatalogName.FromProjectLocationCatalog("[PROJECT]", "[LOCATION]", "[CATALOG]"), DisplayName = "display_name137f65c2", ProductLevelConfig = new ProductLevelConfig(), }; mockGrpcClient.Setup(x => x.UpdateCatalog(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); CatalogServiceClient client = new CatalogServiceClientImpl(mockGrpcClient.Object, null); Catalog response = client.UpdateCatalog(request.Catalog, request.UpdateMask); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
protected override void ProcessRecord() { base.ProcessRecord(); UpdateCatalogRequest request; try { request = new UpdateCatalogRequest { CatalogId = CatalogId, UpdateCatalogDetails = UpdateCatalogDetails, IfMatch = IfMatch, OpcRequestId = OpcRequestId }; response = client.UpdateCatalog(request).GetAwaiter().GetResult(); WriteOutput(response, response.Catalog); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }