コード例 #1
0
 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"));
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
 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"));
     }
 }
コード例 #4
0
 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"));
     }
 }
コード例 #5
0
 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"));
     }
 }
コード例 #6
0
        private void FillContext(UserContextDTO context, User user)
        {
            UserDTO userDTO = GetUserDTO(user);

            context.UserDTO = userDTO;
            context.Token   = LoginContext.GetInstance().GenerateNewToken(userDTO.UserId);
        }
コード例 #7
0
 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"));
     }
 }
コード例 #8
0
ファイル: Login.cs プロジェクト: vsseoane/esport-ecommerce
        private void ShowMainPanel(UserContextDTO userContext)
        {
            MainPanel window = new MainPanel(userContext, serviceFactory);

            window.Show();
            Hide();
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 public MainPanel(UserContextDTO userContext, ServiceFactory serviceFactory)
 {
     this.userContext    = userContext;
     this.serviceFactory = serviceFactory;
     loginService        = serviceFactory.CreateLoginService();
     InitializeComponent();
     LoadMainPanel();
 }
コード例 #11
0
 public ProductImporter(IProductImporterService productImporterService, UserContextDTO userContextDTO)
 {
     this.userContextDTO         = userContextDTO;
     this.productImporterService = productImporterService;
     this.productImporterService.AddObserver(this);
     InitializeComponent();
     LoadComboBox();
 }
コード例 #12
0
        private UserContextDTO BuildResponseDTO(List <PendingReviewDTO> pendingReviews, CartDTO pendingCart)
        {
            UserContextDTO response = new UserContextDTO();

            response.PendingsReviewDTO = pendingReviews;
            response.PendingCart       = pendingCart;
            return(response);
        }
コード例 #13
0
        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");
            }
        }
コード例 #14
0
        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");
            }
        }
コード例 #15
0
        private static UserContextDTO GetUserContext(HttpRequestMessage request)
        {
            string token = GetTokenFromRequest(request);

            ValidateToken(token);
            UserContextDTO userContext = LoginContext.GetInstance().GetUserContextByToken(token);

            return(userContext);
        }
コード例 #16
0
        public void TestLoginToken()
        {
            LoginUserRequest request = new LoginUserRequest();

            request.UserId       = USER_ID;
            request.UserPassword = USER_PASSWORD;
            UserContextDTO response = loginService.LoginUser(request);

            Assert.IsNotNull(response.Token);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        public void TestLoginResponsePendingCart()
        {
            LoginUserRequest request = new LoginUserRequest();

            request.UserId       = USER_ID;
            request.UserPassword = USER_PASSWORD;
            UserContextDTO response = loginService.LoginUser(request);

            Assert.IsNull(response.PendingCart);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
 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);
     }
 }
コード例 #27
0
 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);
     }
 }
コード例 #28
0
        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");
            }
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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
        }