public DeleteUserResponse DeleteUser(DeleteUserRequest request) { var response = new DeleteUserResponse { ResponseStatus = ResponseStatus.Success }; var usersProvider = new UsersProvider(); try { if (request.ActionType == ActionType.Delete) { response.isSuccessful = usersProvider.DeleteUser(request); } else { response.ResponseStatus = ResponseStatus.Failure; response.ResponseDescription = "Not update action"; } } catch (Exception ex) { response.ResponseStatus = ResponseStatus.Failure; response.ResponseDescription = ex.Message; } return(response); }
// Delete public DeleteUserResponse DeleteUser(DeleteUserRequest request) { var response = new DeleteUserResponse(); try { Guard.ArgNotNull(request, "request"); User user = _unitOfWork.UserRepository.GetById(request.Id); Guard.ArgNotNull(user, "user"); _unitOfWork.UserRepository.Delete(user); _unitOfWork.Save(); response.Success = true; Logger.LogInfo("Successfully deleted User Id: " + request.Id.ToString(), LogType.General); } catch (Exception ex) { response.Success = false; response.FailureInformation = ex.Message; Logger.LogError("DeleteUser method failed", ex); } return response; }
public void DeleteUserTest() { var testGuid = Guid.NewGuid(); var request = new DeleteUserRequest(testGuid); var expectedResonse = new DeleteUserResponse { Exception = null }; var mockService = new Mock <IUserService>(); mockService.Setup(x => x.DeleteUser(request)).Returns(expectedResonse); var mockLogger = new Mock <ILoggingService>(); var mockEmail = new Mock <IEmailService>(); var mockConfig = new Mock <IAppConfig <IServiceConfigOptions> >(); var service = new EnrichedUserService(mockService.Object, mockLogger.Object, mockEmail.Object, mockConfig.Object); var response = service.DeleteUser(request); Assert.IsNull(response.Exception); Assert.AreEqual(expectedResonse.Exception, response.Exception); mockService.Verify(x => x.DeleteUser(request), Times.Once); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { DeleteUserResponse response = new DeleteUserResponse(); return response; }
public async Task <IActionResult> DeleteUserConfirmedByToken(DeleteUserRequest request) { var accessToken = HttpContext.Request.Headers["Authorization"].ToString(); if (accessToken == null) { return(NotFound("Something is wrong with your authorization token")); } if (request == null) { return(BadRequest("You must fill in all the fields")); } DeleteUserResponse deletionResult = await _identityService.DeleteUserByIdIfTokenHasSameAspNetUserId(request.aspUserId, accessToken); if (deletionResult.Success) { _logger.LogInfo($"Delete user with {request.aspUserId} succeded"); return(Ok(new SimpleSuccessResponse { Success = true, Message = "Confirm, user deleted" })); } else { _logger.LogError("Delete user error occured : " + deletionResult.Errors); return(BadRequest($"User deletion failed.{deletionResult.Message}")); } }
public void DeleteTest() { var testGuid = Guid.NewGuid(); var expected = new DeleteUserResponse { Result = true }; var mockService = new Mock <IUserService>(); mockService.Setup(x => x.DeleteUser(It.IsAny <DeleteUserRequest>())).Returns(expected); var mockRespoonseBuilder = new Mock <IHttpResponseBuilder>(); var controller = new UserController(mockService.Object, mockRespoonseBuilder.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; mockRespoonseBuilder.Setup(x => x.BuildResponse(controller.Request, expected)) .Returns(controller.Request.CreateResponse(HttpStatusCode.OK, expected.Result)); var response = controller.Delete(testGuid); bool result; response.TryGetContentValue(out result); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsTrue(result); mockService.Verify(x => x.DeleteUser(It.IsAny <DeleteUserRequest>()), Times.Once); }
public DeleteUserResponse DeleteUser(Guid userIdentifier) { var response = new DeleteUserResponse(); using (var context = new DatabaseContext()) using (var transaction = context.Database.BeginTransaction()) { try { var user = context.Users.First(x => x.Identifier == userIdentifier); user.Active = false; context.SaveChanges(); transaction.Commit(); } catch (Exception exception) { transaction.Rollback(); response.AddError(new Error { Code = ErrorCodes.DatabaseError, UserMessage = "Something went wrong while deleting your account. Please try again later.", TechnicalMessage = $"The following exception was thrown: {exception.Message}" }); } } return(response); }
public async Task <IActionResult> DeleteUser(DeleteUserViewModel model, [FromHeader] string authorization) { if (!ModelState.IsValid) { return(BadRequest(model)); } HttpParameters httpParameters = HttpParametersService .GetHttpParameters( model, ConfigHelper.AppSetting(Constants.ServerUrls, Constants.DeleteUser), HttpMethod.Delete, string.Empty, authorization ); DeleteUserResponse deleteUserResult = await _gWService.PostTo <DeleteUserResponse>(httpParameters); if (deleteUserResult.StatusCode == 404) { return(await ResponseService.GetResponse <NotFoundObjectResult, DeleteUserResponse>(deleteUserResult, ModelState)); } else if (deleteUserResult.StatusCode == 422) { return(await ResponseService.GetResponse <UnprocessableEntityObjectResult, DeleteUserResponse>(deleteUserResult, ModelState)); } else if (deleteUserResult.StatusCode != 200) { return(await ResponseService.GetResponse <BadRequestObjectResult, DeleteUserResponse>(deleteUserResult, ModelState)); } return(new OkObjectResult(deleteUserResult)); }
public void TestDeleteUser() { DeleteUserResponse response = new DeleteUserResponse(); Expect.Once.On(service).Method("DeleteUser").Will(Return.Value(response)); serviceFacade.DeleteUser(1); }
public DeleteUserResponse Delete(DeleteUserRequest request) { DeleteUserResponse response = new DeleteUserResponse(); User user = _userRepository.Get(request.Id); if (user == null) { response.HasError = true; response.Message = "User not found"; return(response); } if (user.Id == request.CurrentUserID) { throw new InvalidOperationException("You cannot delete yourself!"); } // must remove all role memberships before deleting user.RemoveFromAllRoles(); _userRepository.Delete(user); _unitOfWork.Commit(); return(response); }
public void DeleteUserNotFound() { UsersFacade usersFacade = new UsersFacade(); DeleteUserResponse deleteResponse = usersFacade.DeleteUser(-1, "Admin"); Assert.AreEqual(HttpStatusCode.NotFound, deleteResponse.Status); }
public static DeleteUserResponse Unmarshall(UnmarshallerContext context) { DeleteUserResponse deleteUserResponse = new DeleteUserResponse(); deleteUserResponse.HttpResponse = context.HttpResponse; deleteUserResponse.RequestId = context.StringValue("DeleteUser.RequestId"); return(deleteUserResponse); }
public void Delete() { System.Console.WriteLine("---Delete user---"); System.Console.Write("Id:"); int id = int.Parse(System.Console.ReadLine()); GetUserRequest requestGet = new GetUserRequest { UserId = id }; GetUserResponse responseGet = _client.GetUser(requestGet); if (responseGet == null) { System.Console.WriteLine("Error: response is null"); return; } if (!responseGet.Success) { System.Console.WriteLine($"Error: {responseGet.Message}"); return; } System.Console.WriteLine("Success: User found"); System.Console.WriteLine("Do you want to delete the user?[Y/n]"); if (System.Console.ReadKey(true).Key == System.ConsoleKey.Y) { DeleteUserRequest requestDelete = new DeleteUserRequest { UserId = id }; DeleteUserResponse responseDelete = _client.DeleteUser(requestDelete); if (responseDelete == null) { System.Console.WriteLine("Error: response is null"); } else if (!responseDelete.Success) { System.Console.WriteLine($"Error: {responseDelete.Message}"); } else { System.Console.WriteLine($"Success: User deleted"); } } System.Console.WriteLine("------------------"); }
public bool DeleteUser(string userName) { DeleteUserRequest inValue = new DeleteUserRequest(); inValue.Body = new DeleteUserRequestBody(); inValue.Body.userName = userName; DeleteUserResponse retVal = ((AutoTestsHelperServiceSoap)(this)).DeleteUser(inValue); return(retVal.Body.DeleteUserResult); }
public static DeleteUserResponse Unmarshall(UnmarshallerContext _ctx) { DeleteUserResponse deleteUserResponse = new DeleteUserResponse(); deleteUserResponse.HttpResponse = _ctx.HttpResponse; deleteUserResponse.RequestId = _ctx.StringValue("DeleteUser.RequestId"); deleteUserResponse.Success = _ctx.BooleanValue("DeleteUser.Success"); deleteUserResponse.Code = _ctx.StringValue("DeleteUser.Code"); deleteUserResponse.Message = _ctx.StringValue("DeleteUser.Message"); return(deleteUserResponse); }
public ActionResult Delete(Guid id) { DeleteUserResponse response = _userService.Delete(new DeleteUserRequest { Id = id }); if (response.HasError) { return(HttpNotFound()); } return(RedirectToAction("index").AndAlert(AlertType.Warning, "Deleted.", "The user was deleted successfully.")); }
public static DeleteUserResponse WrapDeleteUserResponse(string id, string email) { DeleteUserResponse responseMessage = new DeleteUserResponse() { Email = email, Id = id, Code = "user_deleted", StatusCode = 200, Description = "User has successfully been deleted and all realted roles has been unlinked.", Error = "no_error" }; return(responseMessage); }
public async Task CanDeleteUserWithValidAccountDetails() { AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>(); Assert.NotNull(client); DeleteUserResponse response = await client.DeleteAsync(new StringInputParameter() { Value = "deleteme" }); Assert.NotNull(response); Assert.NotNull(response.Response); Assert.True(response.Response.Success); Assert.Empty(response.Response.Errors); Assert.False(string.IsNullOrEmpty(response.Id)); }
public DeleteUserResponse DeleteUser(DeleteUserRequest request) { DeleteUserResponse response = new DeleteUserResponse(); try { userRepository.Delete(request.UserId); response.Success = true; } catch (Exception ex) { response.Message = ex.Message; response.Success = false; } return(response); }
public void Handle_GivenSuccessfulUseCaseResponse_SetsId() { // arrange var presenter = new DeleteUserPresenter(); // act presenter.Handle(new UseCaseResponseMessage("1234", true)); // assert DeleteUserResponse response = Serialization.JsonSerializer.DeSerializeObject <DeleteUserResponse>(presenter.ContentResult.Content); Assert.Equal((int)HttpStatusCode.NoContent, presenter.ContentResult.StatusCode); Assert.NotNull(response); Assert.True(response.Success); Assert.Null(response.Errors); }
public void DeleteUser(int userId) { try { DeleteUserRequest request = new DeleteUserRequest(); request.Id = userId; DeleteUserResponse response = Service.DeleteUser(request); } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "PL Policy")) { throw; } } }
public HttpResponseMessage Delete(Guid id) { var request = new DeleteUserRequest(id); var response = new DeleteUserResponse(); try { response = _userService.DeleteUser(request); } catch (Exception ex) { response.Exception = ex; } return(_responseBuilder.BuildResponse(Request, response)); }
protected void Delete_Click(object sender, EventArgs e) { using (Service1Client client = new Service1Client()) { DeleteUserResponse response = client.DeleteUser(new DeleteUserRequest() { _id = ((LinkButton)sender).CommandArgument, }); if (response.Errored) { Response.Redirect("~/UsersManagement"); } else { Response.Redirect("~/UsersManagement"); } } }
public DeleteUserResponse DeleteUser(DeleteUserRequest request) { DeleteUserResponse response = new DeleteUserResponse(); SecurityBusinessComponent bc = DependencyInjectionHelper.GetSecurityBusinessComponent(); bc.DeleteUser(request.Id); return response; }