Esempio n. 1
0
 public IHttpActionResult CategoryReport([FromUri] string startDate = "", [FromUri] string finishDate = "")
 {
     try
     {
         ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.ADMIN_ROLE });
         AbstractReportDTO  reportDTO = cartService.GetCategoryReport(startDate, finishDate);
         ControllerResponse response  = ControllerHelper.CreateSuccessResponse("Reporte solicitado");
         response.Data = reportDTO;
         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 emitir reporte de categorias"));
     }
 }
 public IHttpActionResult AddCategory()
 {
     try
     {
         CategoryRequest categoryRequest = CreateCategoryRequest(MAN_CATEGORY_ID, "Vestimenta Hombre");
         categoryService.AddCategory(categoryRequest);
         categoryRequest = CreateCategoryRequest(WOMAN_CATEGORY_ID, "Vestimenta Mujer");
         categoryService.AddCategory(categoryRequest);
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Categorías agregadas correctamente");
         response.Data = categoryService.GetAllActiveCategories();
         return(Ok(response));
     }
     catch (BadRequestException e)
     {
         return(BadRequest(e.Message));
     }
     catch (RepositoryException e)
     {
         return(CreateBadResponse(e.Message));
     }
     catch (OperationException e)
     {
         return(InternalServerError(e));
     }
     catch (Exception)
     {
         return(CreateBadResponse("Ocurrió un error al realizar operación"));
     }
 }
Esempio n. 3
0
 public IHttpActionResult ProductReport(int quantity)
 {
     try
     {
         ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.ADMIN_ROLE });
         AbstractReportDTO  reportDTO = cartService.GetMaxProductSaled(quantity);
         ControllerResponse response  = ControllerHelper.CreateSuccessResponse("Reporte solicitado");
         response.Data = reportDTO;
         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 emitir reporte de productos"));
     }
 }
 public IHttpActionResult GetAllActiveCategories()
 {
     try
     {
         List <CategoryDTO> result   = categoryService.GetAllActiveCategories();
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Lista de Categorías");
         response.Data = result;
         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 categorías"));
     }
 }
 public IHttpActionResult GetAllActiveRoles()
 {
     try
     {
         ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.ADMIN_ROLE });
         List <RoleDTO>     roles    = roleService.GetAllActiveRoles();
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Roles");
         response.Data = roles;
         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 rol"));
     }
 }
 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 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 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"));
     }
 }
Esempio n. 10
0
 public IHttpActionResult GetSimpleProductsByFilters(ProductRequest productRequest)
 {
     try
     {
         List <FullProductDTO> result   = productService.GetProductsByFilters(productRequest);
         ControllerResponse    response = ControllerHelper.CreateSuccessResponse("Lista de Productos");
         response.Data = result;
         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 acutalizar campo"));
     }
 }
Esempio n. 11
0
 public IHttpActionResult GetAllSimpleProducts()
 {
     try
     {
         List <SimpleProductDTO> result   = productService.GetAllSimpleProducts();
         ControllerResponse      response = ControllerHelper.CreateSuccessResponse("Lista de Productos");
         response.Data = result;
         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 productos"));
     }
 }
Esempio n. 12
0
 public IHttpActionResult GetAllActiveFullProducts()
 {
     try
     {
         ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.CLIENT_ROLE, ESportUtils.ADMIN_ROLE });
         List <FullProductDTO> result   = productService.GetAllActiveFullProducts();
         ControllerResponse    response = ControllerHelper.CreateSuccessResponse("Lista de Productos");
         response.Data = result;
         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 productos"));
     }
 }
 public IHttpActionResult GetReviewsByProductId(string productId)
 {
     try
     {
         ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.CLIENT_ROLE });
         List <ReviewDTO>   result   = reviewService.GetReviewsByProductId(productId);
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Reviews");
         response.Data = result;
         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 acutalizar la categoría"));
     }
 }
 public IHttpActionResult GetProductsByCategoryId(string categoryId)
 {
     try
     {
         CategoryRequest request = new CategoryRequest();
         request.CategoryId = categoryId;
         List <FullProductDTO> result   = categoryService.GetProductsByCategoryId(request);
         ControllerResponse    response = ControllerHelper.CreateSuccessResponse("Productos para categoria");
         response.Data = result;
         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"));
     }
 }
Esempio n. 15
0
 public IHttpActionResult GetAllUsers()
 {
     try
     {
         ControllerHelper.ValidateUserRole(Request, new string[] { ESportUtils.ADMIN_ROLE });
         List <UserDTO>     usersResult = userService.GetAllUsers();
         ControllerResponse response    = ControllerHelper.CreateSuccessResponse("Usuarios");
         response.Data = usersResult;
         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 usuarios"));
     }
 }
Esempio n. 16
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"));
     }
 }
 public IHttpActionResult AddUsers()
 {
     try
     {
         UserRequest userRequest = CreateUserClientRequest();
         userService.AddUser(userRequest);
         userRequest = CreateUserAdminRequest();
         userService.AddUser(userRequest);
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Usuarios agregados correctamente");
         response.Data = userService.GetAllActiveUsers();
         return(Ok(response));
     }
     catch (BadRequestException e)
     {
         return(BadRequest(e.Message));
     }
     catch (RepositoryException e)
     {
         return(CreateBadResponse(e.Message));
     }
     catch (OperationException e)
     {
         return(InternalServerError(e));
     }
     catch (Exception)
     {
         return(CreateBadResponse("Ocurrió un error al realizar operación"));
     }
 }
 public IHttpActionResult AddRoles()
 {
     try
     {
         RoleRequest roleRequest = CreateRoleRequest(ESportUtils.ADMIN_ROLE, "Administrador de sistema");
         roleService.AddRole(roleRequest);
         roleRequest = CreateRoleRequest(ESportUtils.CLIENT_ROLE, "Cliente de ESport");
         roleService.AddRole(roleRequest);
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Roles agregados correctamente");
         response.Data = roleService.GetAllRoles();
         return(Ok(response));
     }
     catch (BadRequestException e)
     {
         return(BadRequest(e.Message));
     }
     catch (RepositoryException e)
     {
         return(CreateBadResponse(e.Message));
     }
     catch (OperationException e)
     {
         return(InternalServerError(e));
     }
     catch (Exception)
     {
         return(CreateBadResponse("Ocurrió un error al realizar operación"));
     }
 }
 public IHttpActionResult AddProduct()
 {
     try
     {
         ProductRequest productRequest = CreateProductRequest("1", "Campera", "Nike", 1000, "Campera hombre");
         productService.AddProduct(productRequest);
         productRequest = CreateProductRequest("2", "Remera", "Puma", 700, "Remera dama");
         productService.AddProduct(productRequest);
         CategoryRequest categoryRequest = new CategoryRequest()
         {
             CategoryId = MAN_CATEGORY_ID, ProductId = "1"
         };
         categoryService.AddProductOnCategory(categoryRequest);
         categoryRequest = new CategoryRequest()
         {
             CategoryId = WOMAN_CATEGORY_ID, ProductId = "2"
         };
         categoryService.AddProductOnCategory(categoryRequest);
         productRequest = CreateProductRequest("3", "Pantalon", "Nike", 475, "Pantalon");
         productService.AddProduct(productRequest);
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("Productos  agregados correctamente");
         response.Data = categoryService.GetAllActiveCategories();
         return(Ok(response));
     }
     catch (BadRequestException e)
     {
         return(BadRequest(e.Message));
     }
     catch (RepositoryException e)
     {
         return(CreateBadResponse(e.Message));
     }
     catch (OperationException e)
     {
         return(InternalServerError(e));
     }
     catch (Exception)
     {
         return(CreateBadResponse("Ocurrió un error al realizar operación"));
     }
 }
Esempio n. 20
0
 public IHttpActionResult ConfirmCart(CartRequest cartRequest)
 {
     try
     {
         ControllerHelper.ValidateAndSetUserInCartRequest(Request, cartRequest);
         cartService.ConfirmCart(cartRequest);
         List <PendingReviewDTO> pendingReviews = cartService.GetPendingReviewsForUser(cartRequest.UserId);
         UserContextDTO          userContext    = GetUserContextFromRequest(Request);
         userContext.PendingCart       = null;
         userContext.PendingsReviewDTO = pendingReviews;
         UserDTO userDTO = userService.GetUserById(new UserRequest()
         {
             UserId = cartRequest.UserId
         });
         userContext.UserDTO = userDTO;
         LoginContext.GetInstance().SaveContext(userContext);
         ControllerResponse response = ControllerHelper.CreateSuccessResponse("El carrito se confirmó 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 confirmar carrito"));
     }
 }