public IHttpActionResult AddReview(ReviewRequest reviewRequest) { try { ControllerHelper.CalidateAndSetUserInReviewRequest(Request, reviewRequest); reviewService.AddReview(reviewRequest); List <PendingReviewDTO> pendingReviews = cartService.GetPendingReviewsForUser(reviewRequest.UserId); UserContextDTO userContext = GetUserContextFromRequest(Request); userContext.PendingsReviewDTO = pendingReviews; LoginContext.GetInstance().SaveContext(userContext); ControllerResponse response = ControllerHelper.CreateSuccessResponse("La review se dió de alta satisfactoriamente"); response.Data = userContext; return(Ok(response)); } catch (BadRequestException e) { return(CreateBadResponse(e.Message)); } catch (RepositoryException e) { return(CreateBadResponse(e.Message)); } catch (OperationException e) { return(CreateBadResponse(e.Message)); } catch (Exception) { return(CreateBadResponse("Ocurrió un error al agregar review")); } }
public void TestAddRoleWithLogin() { string token = LoginContext.GetInstance().GenerateNewToken("1"); UserContextDTO contextDTO = new UserContextDTO(); contextDTO.UserDTO = new UserDTO(); contextDTO.UserDTO.Roles.Add(new RoleDTO() { RoleId = ESportUtils.ADMIN_ROLE }); contextDTO.Token = token; LoginContext.GetInstance().SaveContext(contextDTO); var mockRoleService = new Mock <IRoleService>(); mockRoleService.Setup(x => x.AddRole(new RoleRequest { RoleId = "Admin", Description = "Administrador" })); var controller = new RoleController(mockRoleService.Object); var controllerContext = new HttpControllerContext(); var httpRequest = new HttpRequestMessage(); httpRequest.Headers.Add(ControllerHelper.TOKEN_NAME, token); controllerContext.Request = httpRequest; controller.ControllerContext = controllerContext; IHttpActionResult response = controller.AddRole(roleRequest); var contentResult = response as OkNegotiatedContentResult <ControllerResponse>; Assert.IsTrue(contentResult.Content.Success); }
public IHttpActionResult RemoveItem(CartRequest cartRequest) { try { ControllerHelper.ValidateAndSetUserInCartRequest(Request, cartRequest); CartDTO cartResult = cartService.RemoveProduct(cartRequest); UserContextDTO userContext = GetUserContextFromRequest(Request); userContext.PendingCart = cartResult; LoginContext.GetInstance().SaveContext(userContext); ControllerResponse response = ControllerHelper.CreateSuccessResponse("El producto se eliminó del carrito satisfactoriamente"); response.Data = userContext; return(Ok(response)); } catch (BadRequestException e) { return(CreateBadResponse(e.Message)); } catch (RepositoryException e) { return(CreateBadResponse(e.Message)); } catch (OperationException e) { return(CreateBadResponse(e.Message)); } catch (Exception) { return(CreateBadResponse("Ocurrió un error al eliminar producto del carrito")); } }
public IHttpActionResult CancelCart() { try { ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.CLIENT_ROLE }); string token = ControllerHelper.GetTokenFromRequest(Request); CartRequest cartRequest = new CartRequest( ) { UserId = ControllerHelper.GetUserIdFromToken(token) }; cartService.CancelCart(cartRequest); UserContextDTO userContext = GetUserContextFromRequest(Request); userContext.PendingCart = null; LoginContext.GetInstance().SaveContext(userContext); ControllerResponse response = ControllerHelper.CreateSuccessResponse("El carrito se cancelo satisfactoriamente"); response.Data = userContext; return(Ok(response)); } catch (BadRequestException e) { return(CreateBadResponse(e.Message)); } catch (RepositoryException e) { return(CreateBadResponse(e.Message)); } catch (OperationException e) { return(CreateBadResponse(e.Message)); } catch (Exception) { return(CreateBadResponse("Ocurrió un error al cancelar carrito")); } }
public IHttpActionResult GetAllCartsByUser() { try { string token = ControllerHelper.GetTokenFromRequest(Request); ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.CLIENT_ROLE }); UserContextDTO userContext = LoginContext.GetInstance().GetUserContextByToken(token); CartRequest cartRequest = new CartRequest { UserId = userContext.UserDTO.UserId }; List <CartDTO> cartsDTOResult = cartService.GetAllCartsByUser(cartRequest); ControllerResponse response = ControllerHelper.CreateSuccessResponse("Carritos"); response.Data = cartsDTOResult; return(Ok(response)); } catch (BadRequestException e) { return(CreateBadResponse(e.Message)); } catch (RepositoryException e) { return(CreateBadResponse(e.Message)); } catch (OperationException e) { return(CreateBadResponse(e.Message)); } catch (Exception) { return(CreateBadResponse("Ocurrió un error al obtener carritos")); } }
private void FillContext(UserContextDTO context, User user) { UserDTO userDTO = GetUserDTO(user); context.UserDTO = userDTO; context.Token = LoginContext.GetInstance().GenerateNewToken(userDTO.UserId); }
public IHttpActionResult LoginUser(LoginUserRequest loginRequest) { try { UserContextDTO contextDTO = loginService.LoginUser(loginRequest); ControllerResponse response = ControllerHelper.CreateSuccessResponse("Login"); response.Data = contextDTO; return(Ok(response)); } catch (BadRequestException e) { return(CreateBadResponse(e.Message)); } catch (RepositoryException e) { return(CreateBadResponse(e.Message)); } catch (OperationException e) { return(CreateBadResponse(e.Message)); } catch (Exception e) { return(CreateBadResponse("Ocurrió un error al realizar login")); } }
private void ShowMainPanel(UserContextDTO userContext) { MainPanel window = new MainPanel(userContext, serviceFactory); window.Show(); Hide(); }
public void TestGetAllFullActiveProductWithLogin() { string token = LoginContext.GetInstance().GenerateNewToken("1"); UserContextDTO contextDTO = new UserContextDTO(); contextDTO.UserDTO = new UserDTO(); contextDTO.UserDTO.Roles.Add(new RoleDTO() { RoleId = ESportUtils.CLIENT_ROLE }); contextDTO.Token = token; LoginContext.GetInstance().SaveContext(contextDTO); var mockProductService = new Mock <IProductService>(); mockProductService.Setup(x => x.GetAllActiveFullProducts()); var controller = new ProductController(mockProductService.Object); var controllerContext = new HttpControllerContext(); var request = new HttpRequestMessage(); request.Headers.Add(ControllerHelper.TOKEN_NAME, token); controllerContext.Request = request; controller.ControllerContext = controllerContext; IHttpActionResult response = controller.GetAllActiveFullProducts(); var contentResult = response as OkNegotiatedContentResult <ControllerResponse>; Assert.IsTrue(contentResult.Content.Success); }
public MainPanel(UserContextDTO userContext, ServiceFactory serviceFactory) { this.userContext = userContext; this.serviceFactory = serviceFactory; loginService = serviceFactory.CreateLoginService(); InitializeComponent(); LoadMainPanel(); }
public ProductImporter(IProductImporterService productImporterService, UserContextDTO userContextDTO) { this.userContextDTO = userContextDTO; this.productImporterService = productImporterService; this.productImporterService.AddObserver(this); InitializeComponent(); LoadComboBox(); }
private UserContextDTO BuildResponseDTO(List <PendingReviewDTO> pendingReviews, CartDTO pendingCart) { UserContextDTO response = new UserContextDTO(); response.PendingsReviewDTO = pendingReviews; response.PendingCart = pendingCart; return(response); }
private static void ValidateTokenInLoginContext(string token) { UserContextDTO context = LoginContext.GetInstance().GetUserContextByToken(token); if (context == null) { throw new BadRequestException("Debe estar logueado para esta operación"); } }
internal static void ValidateIsTheSameUser(HttpRequestMessage request, string userId) { UserContextDTO userContextDTO = GetUserContext(request); if (!userId.Equals(userContextDTO.UserDTO.UserId) && !ValidateUserRole(userContextDTO.UserDTO, new string[] { ESportUtils.ADMIN_ROLE })) { throw new BadRequestException("Esta operación no se permite realizar sobre otro usuario"); } }
private static UserContextDTO GetUserContext(HttpRequestMessage request) { string token = GetTokenFromRequest(request); ValidateToken(token); UserContextDTO userContext = LoginContext.GetInstance().GetUserContextByToken(token); return(userContext); }
public void TestLoginToken() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); Assert.IsNotNull(response.Token); }
public void TestLoginResponseUserLastName() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); Assert.AreEqual(USER_LASTNAME, response.UserDTO.UserLastName); }
public void TestLoginResponsePendingReviews() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); Assert.AreEqual(ESportUtils.EMPTY_LIST, response.PendingsReviewDTO.Count); }
public void TestLoginResponsePendingCart() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); Assert.IsNull(response.PendingCart); }
public UserContextDTO LoginUser(LoginUserRequest request) { ValidateRequest(request); User user = GetAndValidateUser(request); UserContextDTO context = GetUserContext(request); FillContext(context, user); LoginContext.GetInstance().SaveContext(context); LoggerManager.AddLog(ESportLoggerUtils.LOGIN_ACTION, user.UserId, user.UserName); return(context); }
private UserContextDTO GetUserContextDTO(string token) { UserContextDTO contextDTO = new UserContextDTO(); contextDTO.UserDTO = new UserDTO(); contextDTO.UserDTO.Roles.Add(new RoleDTO() { RoleId = ESportUtils.CLIENT_ROLE }); contextDTO.Token = token; return(contextDTO); }
public void TestLoginTokenTwo() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); string fisrtToken = response.Token; response = loginService.LoginUser(request); Assert.AreEqual(fisrtToken, response.Token); }
public void TestLogoutException() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); string token = response.Token; loginService.Logout(token); loginService.Logout(token); }
public void TestLoginTokenThree() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); UserContextDTO contextInMemory = LoginContext.GetInstance().GetUserContextByToken(response.Token); UserDTO userInContext = contextInMemory.UserDTO; Assert.AreEqual(USER_ID, userInContext.UserId); }
public void TestLogout() { var mockLoginService = new Mock <ILoginService>(); UserContextDTO userContextDTO = new UserContextDTO(); mockLoginService.Setup(x => x.Logout("")); var mockUserService = new Mock <IUserService>(); var controller = new LoginController(mockLoginService.Object, mockUserService.Object); IHttpActionResult response = controller.LogoutUser(); var contentResult = response as OkNegotiatedContentResult <ControllerResponse>; Assert.IsNotNull(contentResult.Content.Message); }
public void SaveContext(UserContextDTO userContext) { try { UserContext context = userContextRepository.GetUserContextByToken(Guid.Parse(userContext.Token)); context.SerializedContext = SerializeUserContext(userContext); userContextRepository.UpdateEntity(context); } catch (RepositoryException) { AddNewUserContext(userContext); } }
private void AddNewUserContext(UserContextDTO userContext) { try { UserContext context = new UserContext(); context.SerializedContext = SerializeUserContext(userContext); context.Token = Guid.Parse(userContext.Token); context.UserId = userContext.UserDTO.UserId; userContextRepository.AddEntity(context); } catch (RepositoryException e) { throw new OperationException(e.Message, e); } }
public void TestLogout() { LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); string token = response.Token; loginService.Logout(token); UserContextDTO context = LoginContext.GetInstance().GetUserContextByToken(token); if (context == null) { throw new BadRequestException("Debe estar logueado para esta operación"); } }
public void TestLoginResponsePendingCartNotNull() { int QUANTITY = 2; CartRequest productRequest = new CartRequest(); productRequest.UserId = USER_ID; productRequest.ProductId = PRODUCT_ID; productRequest.Quantity = QUANTITY; cartManager.AddProduct(productRequest); LoginUserRequest request = new LoginUserRequest(); request.UserId = USER_ID; request.UserPassword = USER_PASSWORD; UserContextDTO response = loginService.LoginUser(request); Assert.IsNotNull(response.PendingCart); }
public void TestLoginUserData() { LoginUserRequest userRequest = new LoginUserRequest { UserId = "1", UserPassword = "******" }; var mockLoginService = new Mock <ILoginService>(); UserContextDTO userContextDTO = new UserContextDTO(); mockLoginService.Setup(x => x.LoginUser(userRequest)).Returns(new UserContextDTO()); var mockUserService = new Mock <IUserService>(); var controller = new LoginController(mockLoginService.Object, mockUserService.Object); IHttpActionResult response = controller.LoginUser(userRequest); var contentResult = response as OkNegotiatedContentResult <ControllerResponse>; Assert.IsNotNull(contentResult.Content.Data); //TODO }