public DeleteCustomerResponse DeleteCustomer(DeleteCustomerRequest request)
        {
            AdministrationServiceDAO adminDAO = new AdministrationServiceDAO();
            bool result = adminDAO.DeleteCustomer(request.customer);

            return(new DeleteCustomerResponse(result));
        }
Ejemplo n.º 2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "customers/{id}")]
            HttpRequest req,
            string id,
            [Inject] ICustomerService customerService,
            ILogger logger
            )
        {
            logger.LogInformation($"Calling {nameof(DeleteCustomerFunction)}");

            if (!int.TryParse(id, out var customerId))
            {
                logger.LogError($"Error: Invalid request, id must be integer: {id}");
                return(new BadRequestObjectResult($"Invalid request, id must be integer: {id}"));
            }

            var deleteCustomerRequest = new DeleteCustomerRequest(customerId);
            var isValid = deleteCustomerRequest.Validate();

            if (!isValid)
            {
                logger.LogError("Error: Invalid request");
                return(new BadRequestObjectResult("Invalid request"));
            }

            var operationResult = await customerService.DeleteCustomerAsync(deleteCustomerRequest).ConfigureAwait(false);

            if (operationResult.Status)
            {
                return(new OkObjectResult("Customer deleted successfully"));
            }

            return(new BadRequestObjectResult(operationResult.Message));
        }
Ejemplo n.º 3
0
 private static async Task DeleteCustomer(CustomerServiceDefinition.CustomerServiceDefinitionClient customerClient)
 {
     var input = new DeleteCustomerRequest {
         Id = 3
     };
     var reply = await customerClient.DeleteCustomerAsync(input);
 }
Ejemplo n.º 4
0
        public async Task TestSuccess()
        {
            // Arrange
            Mock <IDataRepository <Customer, Guid> > mockRepository = new Mock <IDataRepository <Customer, Guid> >();
            Guid     id       = new Guid("b7c2acaa-ad72-47b3-b858-26357cf14fbb");
            Customer customer = new Customer()
            {
                Id = id
            };

            mockRepository.Setup(m => m.FindAsync(id, default)).Returns(new ValueTask <Customer>(customer));
            DeleteCustomerRequest request = new DeleteCustomerRequest()
            {
                Id = id
            };
            DeleteCustomerCommand sut = new DeleteCustomerCommand(MockHelpers.GetLogger <DeleteCustomerCommand>(), mockRepository.Object);

            // Act
            DeleteCustomerResponse result = await sut.Handle(request, default);

            // Assert
            Assert.IsNotNull(result);
            mockRepository.VerifyAll();
            mockRepository.Verify(m => m.FindAsync(id, default), Times.Once);
            mockRepository.Verify(m => m.Delete(customer), Times.Once);
        }
Ejemplo n.º 5
0
 public DeleteCustomerResponse DeleteCustomer(DeleteCustomerRequest deleteCustomerRequest)
 {
     try
     {
         Customer customer = _customerRepository.FindBy(deleteCustomerRequest.Id);
         if (customer != null)
         {
             _customerRepository.Delete(customer);
             _unitOfWork.Commit();
             return(new DeleteCustomerResponse());
         }
         else
         {
             return(new DeleteCustomerResponse()
             {
                 Exception = GetStandardCustomerNotFoundException()
             });
         }
     }
     catch (Exception ex)
     {
         return(new DeleteCustomerResponse()
         {
             Exception = ex
         });
     }
 }
        public async void Run_DeleteCustomerTest()
        {
            ShowTestOnTerminal("DeleteCustomer");

            UpdateCustomerRequest setupRequest = new UpdateCustomerRequest
            {
                Customer = new Customer
                {
                    FirstName    = "Test",
                    LastName     = "Customer",
                    CompanyName  = "Test Company",
                    EmailAddress = "*****@*****.**",
                    SmsNumber    = "(123) 123-1234",
                },
            };

            output.WriteLine("Setup request: {0}", setupRequest);

            CustomerResponse setupResponse = await blockchyp.UpdateCustomerAsync(setupRequest);

            output.WriteLine("Setup Response: {0}", setupResponse);

            DeleteCustomerRequest request = new DeleteCustomerRequest
            {
                CustomerId = setupResponse.Customer.Id,
            };

            output.WriteLine("Request: {0}", request);

            DeleteCustomerResponse response = await blockchyp.DeleteCustomerAsync(request);

            output.WriteLine("Response: {0}", response);

            Assert.True(response.Success, "response.Success");
        }
Ejemplo n.º 7
0
        public async Task With_Valid_Request_Existing_Customer_Can_Be_Deleted()
        {
            //
            // Arrange
            //
            var httpResponse = await _client.PostAsJsonAsync(BaseUrl, new CreateCustomerRequest
            {
                FirstName   = "john",
                LastName    = "snow",
                DateOfBirth = new DateTime(2000, 1, 1)
            });

            var createdCustomerDto = JsonConvert.DeserializeObject <DisplayCustomerDto>(await httpResponse.Content.ReadAsStringAsync());
            var deleteRequest      = new DeleteCustomerRequest
            {
                CustomerId = createdCustomerDto.Id
            };

            //
            // Act
            //
            httpResponse = await _client.SendAsync(new HttpRequestMessage(HttpMethod.Delete, BaseUrl)
            {
                Content = new StringContent(JsonConvert.SerializeObject(deleteRequest), Encoding.UTF8, "application/json")
            });

            //
            // Assert
            //
            httpResponse.EnsureSuccessStatusCode();
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> DeleteCustomerAsync(int id)
        {
            var request = new DeleteCustomerRequest {
                Id = id
            };
            var response = await Service.DeleteCustomerAsync(request);

            return(NoContent());
        }
Ejemplo n.º 9
0
        public DeleteCustomerResponse DeleteCustomer(DeleteCustomerRequest request)
        {
            DeleteCustomerResponse    response = new DeleteCustomerResponse();
            CustomerBusinessComponent bc       = DependencyInjectionHelper.GetCustomerBusinessComponent();

            bc.DeleteCustomer(request.CustomerId);

            return(response);
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Delete([FromBody] DeleteCustomerRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var res = await _customerService.DeleteAsync(request);

            return(Ok(res));
        }
Ejemplo n.º 11
0
        public async Task <string> DeleteAsync(DeleteCustomerRequest request)
        {
            var customer = await _dbContext.Customers.FirstOrDefaultAsync(p => p.Id == new Guid(request.Id));

            customer.IsDelete = true;

            await _dbContext.SaveChangesAsync();

            return(customer.Id.ToString());
        }
Ejemplo n.º 12
0
        public async Task DeleteCustomer_NotExistRequest_ThrowsNotFoundRequestException()
        {
            var id = Guid.NewGuid();

            var deleteRequest = new DeleteCustomerRequest {
                Id = id
            };

            await Assert.ThrowsAsync <NotFoundRequestException>(() => Fixture.Customers.DeleteCustomerAsync(deleteRequest));
        }
Ejemplo n.º 13
0
        public async Task DeleteCustomer_ValidRequest_ReturnsResponse()
        {
            var customerRecord = _customerRecords[0];
            var id             = customerRecord.Id;

            var deleteRequest = new DeleteCustomerRequest {
                Id = id
            };
            var deleteResponse = await Fixture.Customers.DeleteCustomerAsync(deleteRequest);
        }
Ejemplo n.º 14
0
        public JsonResult DeleteCustomer([FromBody] DeleteCustomerRequest request)
        {
            BaseResponse baseResponse = new BaseResponse();

            Bayi.DataAccess.Customer byId = this._customerService.GetById(request.CustomerId);
            byId.IsActive = false;
            this._customerService.Update(byId);
            baseResponse.Number  = 1;
            baseResponse.Message = "Kullanıcı başarıyla silinmiştir..";
            return(this.Json((object)baseResponse));
        }
Ejemplo n.º 15
0
        public async Task DeleteCustomer_NotExist_NotFound()
        {
            var id = Guid.NewGuid();

            var deleteRequest = new DeleteCustomerRequest {
                Id = id
            };

            var deleteResponse = await Fixture.Api.Customers.DeleteCustomerAsync(deleteRequest);

            Assert.Equal(HttpStatusCode.NotFound, deleteResponse.StatusCode);
        }
        public async Task <DeleteCustomerResponse> DeleteCustomerAsync(
            long customerId,
            byte[] timeStamp)
        {
            var request = new DeleteCustomerRequest
            {
                CustomerId = customerId,
                TimeStamp  = timeStamp
            };

            return(await CustomerManagementService.CallAsync((s, r) => s.DeleteCustomerAsync(r), request));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Delete([FromBody] DeleteCustomerRequest request)
        {
            var operationResult = await _customerService.DeleteCustomerAsync(request.ToServiceRequest()).ConfigureAwait(false);

            if (!operationResult.Status)
            {
                _logger.LogError($"Error: Cannot delete customer");
            }

            var actionResult = _deleteCustomerResponsePresenter.Handle(operationResult);

            return(actionResult);
        }
Ejemplo n.º 18
0
        public async Task DeleteCustomer_Valid_OK()
        {
            var customerRecord = _customerRecords[0];
            var id             = customerRecord.Id;

            var deleteRequest = new DeleteCustomerRequest {
                Id = id
            };

            var deleteResponse = await Fixture.Api.Customers.DeleteCustomerAsync(deleteRequest);

            Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);
        }
        /// <summary>Snippet for DeleteCustomer</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public void DeleteCustomerRequestObject()
        {
            // Create client
            CloudChannelServiceClient cloudChannelServiceClient = CloudChannelServiceClient.Create();
            // Initialize request argument(s)
            DeleteCustomerRequest request = new DeleteCustomerRequest
            {
                CustomerName = CustomerName.FromAccountCustomer("[ACCOUNT]", "[CUSTOMER]"),
            };

            // Make the request
            cloudChannelServiceClient.DeleteCustomer(request);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Deletes the customer.  --Robin
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public bool DeleteCustomer(int id)
        {
            DeleteCustomerRequest request = new DeleteCustomerRequest();

            request.Id = id;
            DeleteCustomerResponse response = MyChannelFactory.CreateChannel().DeleteCustomer(request);

            if (response.IsFailed)
            {
                throw new Exception("We have a error!" + response.Message);
            }
            return(response.IsFailed);
        }
Ejemplo n.º 21
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dgvList.CurrentRow == null)
     {
         SOAFramework.Client.Controls.MessageBox.Show(this, "请选择一条数据");
         return;
     }
     if (SOAFramework.Client.Controls.MessageBox.Show(this, "确认删除选中的数据吗?", "删除", MessageBoxButtons.YesNo) == DialogResult.No) return;
     DeleteCustomerRequest request = new DeleteCustomerRequest();
     request.token = this.Token;
     var customer = dgvList.CurrentRow.DataBoundItem as Customer;
     request.id = customer.ID;
     SDKSync<CommonResponse>.CreateInstance(this).Execute(request, Delete_Callback);
 }
        public override async Task <DeleteCustomerResponse> DeleteCustomer(DeleteCustomerRequest request,
                                                                           ServerCallContext context)
        {
            if (await repository.DeleteCustomer(Guid.Parse(request.Id)))
            {
                return(new DeleteCustomerResponse {
                    Id = request.Id, Result = "SUCCESS"
                });
            }

            return(new DeleteCustomerResponse {
                Id = string.Empty, Result = "FAILURE"
            });
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Delete(string id)
        {
            var request = new DeleteCustomerRequest(new DeleteCustomerModel()
            {
                Id = id
            });
            var result = await _mediator.Send(request);

            if (result.IsDeleted == false)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Ejemplo n.º 24
0
 public void DeleteCustomer(int customerId)
 {
     try
     {
         DeleteCustomerRequest request = new DeleteCustomerRequest();
         request.CustomerId = customerId;
         DeleteCustomerResponse response = Service.DeleteCustomer(request);
     }
     catch (Exception ex)
     {
         if (ExceptionPolicy.HandleException(ex, "PL Policy"))
         {
             throw;
         }
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Deletes the customer.  --Robin
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public bool DeleteCustomer(int id)
        {
            DeleteCustomerRequest request = new DeleteCustomerRequest();

            request.Id = id;
            DeleteCustomerResponse response = MyChannelFactory.CreateChannel().DeleteCustomer(request);

            if (response.IsFailed)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("error", new Exception(response.Message));
                log.Fatal("fatal", new Exception(response.Message));
                throw new Exception("We have a error!");
            }
            return(true);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Deletes the customer.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public DeleteCustomerResponse DeleteCustomer(DeleteCustomerRequest request)
        {
            CustomerService        service  = new CustomerService();
            DeleteCustomerResponse response = new DeleteCustomerResponse();

            try
            {
                service.DeleteCustomer(request.Id);
            }
            catch (System.Exception ex)
            {
                response.IsFailed = true;
                response.Message  = ex.Message;
            }
            return(response);
        }
Ejemplo n.º 27
0
 public SuccessResponse Delete(DeleteCustomerRequest request)
 {
     try
     {
         var customer = _customerRepository.FindBy(request.Id);
         customer.ThrowExceptionIfRecordIsNull();
         _customerRepository.Remove(customer);
         return(new SuccessResponse {
             IsSuccess = true
         });
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
        public void DeleteCustomerResourceNames()
        {
            moq::Mock <CloudChannelService.CloudChannelServiceClient> mockGrpcClient = new moq::Mock <CloudChannelService.CloudChannelServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            DeleteCustomerRequest request = new DeleteCustomerRequest
            {
                CustomerName = CustomerName.FromAccountCustomer("[ACCOUNT]", "[CUSTOMER]"),
            };
            wkt::Empty expectedResponse = new wkt::Empty {
            };

            mockGrpcClient.Setup(x => x.DeleteCustomer(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            CloudChannelServiceClient client = new CloudChannelServiceClientImpl(mockGrpcClient.Object, null);

            client.DeleteCustomer(request.CustomerName);
            mockGrpcClient.VerifyAll();
        }
        public async stt::Task DeleteCustomerResourceNamesAsync()
        {
            moq::Mock <CloudChannelService.CloudChannelServiceClient> mockGrpcClient = new moq::Mock <CloudChannelService.CloudChannelServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            DeleteCustomerRequest request = new DeleteCustomerRequest
            {
                CustomerName = CustomerName.FromAccountCustomer("[ACCOUNT]", "[CUSTOMER]"),
            };
            wkt::Empty expectedResponse = new wkt::Empty {
            };

            mockGrpcClient.Setup(x => x.DeleteCustomerAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <wkt::Empty>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            CloudChannelServiceClient client = new CloudChannelServiceClientImpl(mockGrpcClient.Object, null);
            await client.DeleteCustomerAsync(request.CustomerName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            await client.DeleteCustomerAsync(request.CustomerName, st::CancellationToken.None);

            mockGrpcClient.VerifyAll();
        }
Ejemplo n.º 30
0
        public async Task If_Invalid_Request_Is_Sent_Cannot_Delete_Customer()
        {
            //
            // Arrange
            //
            var customerService = GetCustomerService();
            var emptyRequest    = new DeleteCustomerRequest(string.Empty);
            var nullIdRequest   = new DeleteCustomerRequest(null);
            DeleteCustomerRequest nullRequest = null;
            //
            // Act
            //
            var tasks = new[] { emptyRequest, nullIdRequest, nullRequest }.Select(x => customerService.DeleteCustomerAsync(x));
            var operationResults = await Task.WhenAll(tasks);

            //
            // Assert
            //
            Assert.False(operationResults.All(x => x.Status));
        }
Ejemplo n.º 31
0
        public async Task TestNotFound()
        {
            // Arrange
            Mock <IDataRepository <Customer, Guid> > mockRepository = new Mock <IDataRepository <Customer, Guid> >();
            Guid id = new Guid("b7c2acaa-ad72-47b3-b858-26357cf14fbb");

            mockRepository.Setup(m => m.FindAsync(id, default)).Returns(new ValueTask <Customer>((Customer)null));
            DeleteCustomerRequest request = new DeleteCustomerRequest()
            {
                Id = id
            };
            DeleteCustomerCommand sut = new DeleteCustomerCommand(MockHelpers.GetLogger <DeleteCustomerCommand>(), mockRepository.Object);

            // Act
            await Assert.ThrowsExceptionAsync <NotFoundException>(async() => await sut.Handle(request, default));

            // Assert
            mockRepository.VerifyAll();
            mockRepository.Verify(m => m.FindAsync(id, default), Times.Once);
            mockRepository.Verify(m => m.Delete(It.IsAny <Customer>()), Times.Never);
        }
Ejemplo n.º 32
0
 /// <remarks/>
 public void DeleteCustomerAsync(DeleteCustomerRequest DeleteCustomerRequest) {
     this.DeleteCustomerAsync(DeleteCustomerRequest, null);
 }
Ejemplo n.º 33
0
 /// <remarks/>
 public void DeleteCustomerAsync(DeleteCustomerRequest DeleteCustomerRequest, object userState) {
     if ((this.DeleteCustomerOperationCompleted == null)) {
         this.DeleteCustomerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDeleteCustomerOperationCompleted);
     }
     this.InvokeAsync("DeleteCustomer", new object[] {
                 DeleteCustomerRequest}, this.DeleteCustomerOperationCompleted, userState);
 }