public async Task <OperationResult> Remove(List <ProductCategory_Dto> model)
        {
            List <ProductCategory> productCates = new List <ProductCategory>();
            List <Product>         products     = new List <Product>();

            foreach (var item in model)
            {
                productCates.Add(await _productCategoryRepository.FindAll(x => x.Product_Cate_ID == item.Product_Cate_ID).FirstOrDefaultAsync());
                products.AddRange(await _productRepository.FindAll(x => x.Product_Cate_ID == item.Product_Cate_ID).ToListAsync());
            }

            if (productCates != null && productCates.Count > 0)
            {
                try
                {
                    if (products != null && products.Count > 0)
                    {
                        foreach (var product in products)
                        {
                            var images = await _productRepository.FindAll(x => x.Product_Cate_ID == product.Product_Cate_ID &&
                                                                          x.Product_ID == product.Product_ID &&
                                                                          x.Product_Name == product.Product_Name).Select(x => x.FileImages).Distinct().FirstOrDefaultAsync();

                            var videos = await _productRepository.FindAll(x => x.Product_Cate_ID == product.Product_Cate_ID &&
                                                                          x.Product_ID == product.Product_ID &&
                                                                          x.Product_Name == product.Product_Name).Select(x => x.FileVideos).Distinct().FirstOrDefaultAsync();

                            if (!string.IsNullOrEmpty(images))
                            {
                                _dropzoneService.DeleteFileUpload(images, "\\uploaded\\images\\product");
                            }
                            if (!string.IsNullOrEmpty(videos))
                            {
                                _dropzoneService.DeleteFileUpload(videos, "\\uploaded\\video\\product");
                            }
                        }
                        _productRepository.RemoveMultiple(products);
                    }
                    _productCategoryRepository.RemoveMultiple(productCates);
                    await _productCategoryRepository.Save();

                    return(operationResult = new OperationResult {
                        Success = true, Message = "Product Category was delete successfully."
                    });
                }
                catch (Exception)
                {
                    return(operationResult = new OperationResult {
                        Success = false, Message = "Product Category was delete failes."
                    });
                }
            }
            else
            {
                return(operationResult = new OperationResult {
                    Success = false, Message = "Product Category was delete failes."
                });
            }
        }
Пример #2
0
        public async Task <IActionResult> Update([FromForm] Product_Dto model)
        {
            model.Content = model.Content == "null" ? null : model.Content;

            // Delete images, videos old
            var images = await _productRepository.FindAll(x => x.Product_Cate_ID == model.Product_Cate_ID &&
                                                          x.Product_ID == model.Product_ID &&
                                                          x.Product_Name == model.Product_Name).Select(x => x.FileImages).Distinct().FirstOrDefaultAsync();

            var videos = await _productRepository.FindAll(x => x.Product_Cate_ID == model.Product_Cate_ID &&
                                                          x.Product_ID == model.Product_ID &&
                                                          x.Product_Name == model.Product_Name).Select(x => x.FileVideos).Distinct().FirstOrDefaultAsync();

            if (!string.IsNullOrEmpty(images))
            {
                _dropzoneService.DeleteFileUpload(images, "\\uploaded\\images\\product");
            }
            if (!string.IsNullOrEmpty(videos))
            {
                _dropzoneService.DeleteFileUpload(videos, "\\uploaded\\video\\product");
            }

            // Add images, videos
            model.FileImages = null;
            model.FileVideos = null;

            if (model.Images != null)
            {
                model.FileImages = await _dropzoneService.UploadFiles(model.Images, model.Product_Cate_ID + "_" + model.Product_ID + "_", "\\uploaded\\images\\product");
            }
            if (model.Videos != null)
            {
                model.FileVideos = await _dropzoneService.UploadFiles(model.Videos, model.Product_Cate_ID + "_" + model.Product_ID + "_", "\\uploaded\\video\\product");
            }

            model.Update_By   = User.FindFirst(ClaimTypes.Name).Value;
            model.Update_Time = DateTime.Now;
            var result = await _productService.Update(model);

            if (result.Success)
            {
                await _hubContext.Clients.All.LoadDataProduct();
            }
            return(Ok(result));
        }
Пример #3
0
        public async Task <IActionResult> UpdateUser([FromForm] User_Dto model)
        {
            if (model.File != null)
            {
                var image = await _userRepository.FindAll(x => x.Factory_ID == model.Factory_ID && x.User_Account == model.User_Account)
                            .Select(x => x.Image)
                            .FirstOrDefaultAsync();

                if (!string.IsNullOrEmpty(image))
                {
                    _dropzoneService.DeleteFileUpload(image, "\\uploaded\\images\\user");
                }
                model.Image = await _dropzoneService.UploadFile(model.File, model.User_Account.Trim() + "_", "\\uploaded\\images\\user");
            }
            model.Update_By = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var result = await _userService.UpdateUser(model);

            return(Ok(result));
        }
        public async Task <OperationResult> Remove(List <ArticleCategory_Dto> model)
        {
            List <ArticleCategory> articleCategorys = new List <ArticleCategory>();
            List <Article>         articles         = new List <Article>();

            foreach (var item in model)
            {
                articleCategorys.Add(await _articleCategoryRepository.FindAll(x => x.Article_Cate_ID == item.Article_Cate_ID).FirstOrDefaultAsync());
                articles.AddRange(await _articleRepository.FindAll(x => x.Article_Cate_ID == item.Article_Cate_ID).ToListAsync());
            }

            if (articleCategorys != null && articleCategorys.Count > 0)
            {
                try
                {
                    if (articles != null && articles.Count > 0)
                    {
                        foreach (var article in articles)
                        {
                            var images = await _articleRepository.FindAll(x => x.Article_Cate_ID == article.Article_Cate_ID &&
                                                                          x.Article_ID == article.Article_ID &&
                                                                          x.Article_Name == article.Article_Name).Select(x => x.FileImages).Distinct().FirstOrDefaultAsync();

                            var videos = await _articleRepository.FindAll(x => x.Article_Cate_ID == article.Article_Cate_ID &&
                                                                          x.Article_ID == article.Article_ID &&
                                                                          x.Article_Name == article.Article_Name).Select(x => x.FileVideos).Distinct().FirstOrDefaultAsync();

                            if (!string.IsNullOrEmpty(images))
                            {
                                _dropzoneService.DeleteFileUpload(images, "\\uploaded\\images\\article");
                            }
                            if (!string.IsNullOrEmpty(videos))
                            {
                                _dropzoneService.DeleteFileUpload(videos, "\\uploaded\\video\\article");
                            }
                        }
                        _articleRepository.RemoveMultiple(articles);
                    }
                    _articleCategoryRepository.RemoveMultiple(articleCategorys);
                    await _articleCategoryRepository.Save();

                    operationResult = new OperationResult {
                        Success = true, Message = "Article Category was delete successfully."
                    };
                }
                catch (System.Exception)
                {
                    operationResult = new OperationResult {
                        Success = false, Message = "Article Category was delete failes."
                    };
                }
            }
            else
            {
                operationResult = new OperationResult {
                    Success = false, Message = "Article Category was delete failes."
                };
            }

            return(operationResult);
        }