public async Task <IActionResult> Login([FromBody] LoginDataDto loginData)
        {
            var userDtoResult = await QueryProcessor.GetQueryHandler <LoginUserCommand, UserDto>(new LoginUserCommand(loginData));

            if (userDtoResult.Failure)
            {
                return(BadRequest(userDtoResult.ErrorMessages));
            }

            return(Ok(true));
        }
        public async Task <IActionResult> Logout()
        {
            var userDtoResult = await QueryProcessor.GetQueryHandler <LogoutUserCommand, UserDto>(new LogoutUserCommand());

            if (userDtoResult.Failure)
            {
                return(BadRequest(userDtoResult.ErrorMessages));
            }

            return(Ok(true));
        }
        public async Task <IActionResult> DeleteProduct([FromBody] int id)
        {
            var productDtoResult = await QueryProcessor.GetQueryHandler <DeleteProductCommand, ProductDto>(new DeleteProductCommand(id));

            if (productDtoResult.Failure)
            {
                return(BadRequest(productDtoResult.ErrorMessages));
            }

            return(Ok(productDtoResult.Success));
        }
        public async Task <IActionResult> SaveUser([FromBody] SaveUserCommand command)
        {
            var userDtoResult = await QueryProcessor.GetQueryHandler <SaveUserCommand, UserDto>(command);

            if (userDtoResult.Failure)
            {
                return(BadRequest(userDtoResult.ErrorMessages));
            }

            return(Ok(true));
        }
        public async Task <IActionResult> SaveCategory([FromBody] SaveCategoryDto saveCategory)
        {
            var categoryDtoResult = await QueryProcessor.GetQueryHandler <SaveCategoryCommand, CategoryDto>(new SaveCategoryCommand(saveCategory, 1));

            if (categoryDtoResult.Failure)
            {
                return(BadRequest(categoryDtoResult.ErrorMessages));
            }

            return(Ok(categoryDtoResult.Object));
        }
        public async Task <IActionResult> SaveProduct([FromBody] SaveProductDto saveProduct)
        {
            var productDtoResult = await QueryProcessor.GetQueryHandler <SaveProductCommand, ProductDto>(new SaveProductCommand(saveProduct, 1));

            if (productDtoResult.Failure)
            {
                return(BadRequest(productDtoResult.ErrorMessages));
            }

            return(Ok(productDtoResult.Object));
        }
        public async Task <IActionResult> DeleteCategory([FromBody] int id)
        {
            var categoryDtoResult = await QueryProcessor.GetQueryHandler <DeleteCategoryCommand, CategoryDto>(new DeleteCategoryCommand(id));

            if (categoryDtoResult.Failure)
            {
                return(BadRequest(categoryDtoResult.ErrorMessages));
            }

            return(Ok(categoryDtoResult.Success));
        }
        public async Task <IActionResult> Register([FromBody] RegistrationDataDto registrationData)
        {
            var userDtoResult = await QueryProcessor.GetQueryHandler <CreateUserCommand, UserDto>(new CreateUserCommand(registrationData));

            if (userDtoResult.Failure)
            {
                return(BadRequest(userDtoResult.ErrorMessages));
            }

            return(Ok(true));
        }
        public async Task <IActionResult> UploadFiles()
        {
            var files            = Request?.Form?.Files;
            var fileUploadResult = await QueryProcessor.GetQueryHandler <FileUploadCommand, NoneResult>(new FileUploadCommand(files));

            if (fileUploadResult.Failure)
            {
                return(BadRequest(fileUploadResult.ErrorMessages));
            }

            return(Ok(fileUploadResult.Success));
        }
Exemple #10
0
        public async Task <IActionResult> DeleteBasketItem([FromBody] DeleteBasketItemCommand command)
        {
            var basketItemDtoResult = await QueryProcessor.GetQueryHandler <DeleteBasketItemCommand, BasketItemDto>(command);

            if (basketItemDtoResult.Failure)
            {
                return(BadRequest(basketItemDtoResult.ErrorMessages));
            }

            var basketItemDto = basketItemDtoResult.Object;

            return(Ok(basketItemDto));
        }
Exemple #11
0
        private async Task <IActionResult> CreateProduct(GetProductCommand command)
        {
            var productDtoResult = await QueryProcessor.GetQueryHandler <GetProductCommand, ProductDto>(command);

            if (productDtoResult.Failure)
            {
                return(BadRequest(productDtoResult.ErrorMessages));
            }

            var productDto = productDtoResult.Object;

            return(Ok(productDto));
        }
        public async Task <IActionResult> GetPhrasesByTerm(string term, string characteristic)
        {
            var phrasesDtoResult = await QueryProcessor.GetQueryHandler <ListPhrasesByTermCommand, List <PhraseDto> >(new ListPhrasesByTermCommand(term, characteristic));

            if (phrasesDtoResult.Failure)
            {
                return(BadRequest(phrasesDtoResult.ErrorMessages));
            }

            var phrasesDto = phrasesDtoResult.Object;

            return(Ok(phrasesDto));
        }
Exemple #13
0
        public async Task <IActionResult> ListOrders(ListOrdersCommand listOrdersCommand)
        {
            var pagedOrdersDtoResult = await QueryProcessor.GetQueryHandler <ListOrdersCommand, PagedList <OrderDto> >(listOrdersCommand);

            if (pagedOrdersDtoResult.Failure)
            {
                return(BadRequest(pagedOrdersDtoResult.ErrorMessages));
            }

            var pagedOrdersDto = pagedOrdersDtoResult.Object;

            return(Ok(pagedOrdersDto));
        }
        public async Task <IActionResult> GetEditProductData(int id, int languageId)
        {
            var editProductDataDtoResult = await QueryProcessor.GetQueryHandler <EditProductCommand, EditProductDataDto>(new EditProductCommand(id, languageId));

            if (editProductDataDtoResult.Failure)
            {
                return(BadRequest(editProductDataDtoResult.ErrorMessages));
            }

            var editProductDataDto = editProductDataDtoResult.Object;

            return(Ok(editProductDataDto));
        }
Exemple #15
0
        public async Task <IActionResult> GetBasket()
        {
            var basketDtoResult = await QueryProcessor.GetQueryHandler <CreateOrGetUnconfirmedBasketCommand, BasketDto>(new CreateOrGetUnconfirmedBasketCommand());

            if (basketDtoResult.Failure)
            {
                return(BadRequest(basketDtoResult.ErrorMessages));
            }

            var basketDto = basketDtoResult.Object;

            return(Ok(basketDto));
        }
Exemple #16
0
        public async Task <IActionResult> SaveOrder([FromBody] SaveOrderCommand saveOrderCommand)
        {
            var orderDtoResult = await QueryProcessor.GetQueryHandler <SaveOrderCommand, OrderDto>(saveOrderCommand);

            if (orderDtoResult.Failure)
            {
                return(BadRequest(orderDtoResult.ErrorMessages));
            }

            var orderDto = orderDtoResult.Object;

            return(Ok(true));
        }
Exemple #17
0
        public async Task <IActionResult> AddProductToBasket([FromBody] AddProductToBasketCommand command)
        {
            var productDtoResult = await QueryProcessor.GetQueryHandler <AddProductToBasketCommand, ProductDto>(command);

            if (productDtoResult.Failure)
            {
                return(BadRequest(productDtoResult.ErrorMessages));
            }

            var productDto = productDtoResult.Object;

            return(Ok(productDto));
        }
Exemple #18
0
        public async Task <IActionResult> SubmitOrder([FromBody] SubmitOrderCommand submitOrderCommand)
        {
            var submitOrderDtoResult = await QueryProcessor.GetQueryHandler <SubmitOrderCommand, OrderDto>(submitOrderCommand);

            if (submitOrderDtoResult.Failure)
            {
                return(BadRequest(submitOrderDtoResult.ErrorMessages));
            }

            var submitOrderDto = submitOrderDtoResult.Object;

            return(Ok(submitOrderDto));
        }
Exemple #19
0
        private async Task <IActionResult> CreateCategory(GetCategoryCommand command)
        {
            var categoryDtoResult = await QueryProcessor.GetQueryHandler <GetCategoryCommand, CategoryDto>(command);

            if (categoryDtoResult.Failure)
            {
                return(BadRequest(categoryDtoResult));
            }

            var categoryDto = categoryDtoResult.Object;

            return(Ok(categoryDto));
        }
Exemple #20
0
        public async Task <IActionResult> GetProduct(int id)
        {
            var productDtoResult = await QueryProcessor.GetQueryHandler <GetProductCommand, ProductDto>(new GetProductCommand(id, 1));

            if (productDtoResult.Failure)
            {
                return(BadRequest(productDtoResult.ErrorMessages));
            }

            var productDto = productDtoResult.Object;

            return(Ok(productDto));
        }
Exemple #21
0
        public async Task <IActionResult> GetEditOrderData(int id)
        {
            var getEditOrderDataCommand = new GetEditOrderDataCommand(id);
            var editOrderDataDtoResult  = await QueryProcessor.GetQueryHandler <GetEditOrderDataCommand, EditOrderDataDto>(getEditOrderDataCommand);

            if (editOrderDataDtoResult.Failure)
            {
                return(BadRequest(editOrderDataDtoResult.ErrorMessages));
            }

            var editOrderDataDto = editOrderDataDtoResult.Object;

            return(Ok(editOrderDataDto));
        }
Exemple #22
0
        public async Task <IActionResult> GetCategoryNavigations()
        {
            var listCategoriesCommand     = new ListCategoriesCommand(2, WorkContext.WorkingLanguageId, true);
            var pagedNavigationsDtoResult = await QueryProcessor.GetQueryHandler <ListCategoriesCommand, PagedList <CategoryNavigationDto> >(listCategoriesCommand);

            if (pagedNavigationsDtoResult.Failure)
            {
                return(BadRequest(pagedNavigationsDtoResult.ErrorMessages));
            }

            var pagedNavigationsDto = pagedNavigationsDtoResult.Object;

            return(Ok(pagedNavigationsDto.Items));
        }
        public async Task <IActionResult> ListProducts(ListProductsCommand listProductsCommand)
        {
            // TODO: fix workingLanguageId
            listProductsCommand.LanguageId = 1;
            var pagedProductsDtoResult = await QueryProcessor.GetQueryHandler <ListProductsCommand, PagedList <ProductDto> >(listProductsCommand);

            if (pagedProductsDtoResult.Failure)
            {
                return(BadRequest(pagedProductsDtoResult.ErrorMessages));
            }

            var pagedProductsDto = pagedProductsDtoResult.Object;

            return(Ok(pagedProductsDto));
        }
        public async Task <IActionResult> ListCategories(ListCategoriesCommand listCategoriesCommand)
        {
            // TODO: fix workingLanguageId
            listCategoriesCommand.LanguageId  = 1;
            listCategoriesCommand.InputFormId = 2; listCategoriesCommand.IsDefaultCategoriesIncluded = true; listCategoriesCommand.IsDisabledIncluded = true;
            var pagedCategoriesDtoResult = await QueryProcessor.GetQueryHandler <ListCategoriesCommand, PagedList <CategoryDto> >(listCategoriesCommand);

            if (pagedCategoriesDtoResult.Failure)
            {
                return(BadRequest(pagedCategoriesDtoResult.ErrorMessages));
            }

            var pagedCategoriesDto = pagedCategoriesDtoResult.Object;

            return(Ok(pagedCategoriesDto));
        }
        public async Task <IActionResult> GetProfile()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(BadRequest());
            }

            var profileDtoResult = await QueryProcessor.GetQueryHandler <GetProfileCommand, ProfileDto>(new GetProfileCommand());

            if (profileDtoResult.Failure)
            {
                return(BadRequest(profileDtoResult.ErrorMessages));
            }

            var profileDto = profileDtoResult.Object;

            return(Ok(profileDto));
        }
        public async Task <IActionResult> Authenticate()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(BadRequest());
            }

            var userDtoResult = await QueryProcessor.GetQueryHandler <AuthenticateUserCommand, UserDto>(new AuthenticateUserCommand());

            if (userDtoResult.Failure)
            {
                return(BadRequest(userDtoResult.ErrorMessages));
            }

            var userDto = userDtoResult.Object;

            return(Ok(userDto));
        }
        public async Task <IActionResult> GetResources(string url)
        {
            url = url?.TrimStart('/') ?? "";

            var routesDtoResult = await QueryProcessor.GetQueryHandler <ListRoutesCommand, List <RouteDto> >(new ListRoutesCommand());

            if (routesDtoResult.Failure)
            {
                return(BadRequest(routesDtoResult.ErrorMessages));
            }

            var routesDto           = routesDtoResult.Object;
            var resourcesDictionary = new Dictionary <string, object>();

            addAdminResources();
            addClientResources();

            void addAdminResources()
            {
                if (WorkContext.WorkingInputFormName == InputFormCodes.Admin)
                {
                    var adminLoginRouteDto = routesDto.FirstOrDefault(o => o.AngularComponent == AngularComponents.LoginComponent && o.InputForm == InputFormCodes.Admin);
                    resourcesDictionary.Add("loginPath", adminLoginRouteDto.Url);
                    var adminDashboardRouteDto = routesDto.FirstOrDefault(o => o.AngularComponent == AngularComponents.DashboardAdminComponent && o.InputForm == InputFormCodes.Admin);
                    resourcesDictionary.Add("loginRedirect", adminDashboardRouteDto.Url);
                }
            }

            void addClientResources()
            {
                if (WorkContext.WorkingInputFormName != InputFormCodes.Admin)
                {
                    var clientLoginRouteDto = routesDto.FirstOrDefault(o => o.AngularComponent == AngularComponents.LoginComponent && o.InputForm != InputFormCodes.Admin);
                    resourcesDictionary.Add("loginPath", clientLoginRouteDto.Url);
                    var clientHomeRouteDto = routesDto.FirstOrDefault(o => o.AngularComponent == AngularComponents.ProfileComponent && o.InputForm != InputFormCodes.Admin);
                    resourcesDictionary.Add("loginRedirect", clientHomeRouteDto.Url);
                }
            }

            return(Ok(resourcesDictionary));
        }
Exemple #28
0
        public async Task <IActionResult> Create(string url)
        {
            url = url?.TrimStart('/') ?? "";
            var urlPath = url.Split('?').First();

            if (Regex.IsMatch(urlPath.Split('/').Last(), @"^\d+$"))
            {
                urlPath = urlPath.Substring(0, urlPath.LastIndexOf("/"));
            }

            var routeDtoResult = await QueryProcessor.GetQueryHandler <GetRouteByUrlCommand, RouteDto>(new GetRouteByUrlCommand(urlPath, WorkContext.WorkingLanguageId));

            if (routeDtoResult.Failure)
            {
                return(BadRequest(routeDtoResult.ErrorMessages));
            }

            var currentRouteDto = routeDtoResult.Object;

            if (currentRouteDto == null)
            {
                // TODO: 404
                return(NotFound());
            }

            if (currentRouteDto.AngularComponent != AngularComponents.ProductComponent)
            {
                var getCategoryCommand = new GetCategoryCommand(currentRouteDto.ItemId.Value, WorkContext.WorkingLanguageId);
                return(await CreateCategory(getCategoryCommand));
            }
            else
            {
                var getProductCommand = new GetProductCommand(currentRouteDto.ItemId.Value, WorkContext.WorkingLanguageId);
                return(await CreateProduct(getProductCommand));
            }
        }