public async Task <ApiResult <bool> > DisLike(int blogId)
        {
            var blog = await _context.Blogs.FindAsync(blogId);

            blog.LikeCount--;
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #2
0
        public async Task <ApiResult <bool> > Create(CategoryCreateRequest request)
        {
            var category = new Category()
            {
                IsShowOnHome         = request.IsShowOnHome,
                Created_At           = DateTime.Now,
                CategoryTranslations = new List <CategoryTranslation>()
                {
                    new CategoryTranslation()
                    {
                        Name        = request.Name,
                        CategoryUrl = GetUrlByName.Converts(request.Name),
                        LanguageId  = request.LanguageId
                    }
                },
            };

            //Save Image
            if (request.ThumbnailImage != null)
            {
                category.ImagePath = await this.SaveFile(request.ThumbnailImage);
            }
            _context.Categories.Add(category);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > DeleteAll(int cartId)
        {
            var cartItems = _context.CartProducts.Where(x => x.CartID == cartId);

            _context.CartProducts.RemoveRange(cartItems);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #4
0
        public async Task <ApiResult <bool> > Update(CategoryUpdateRequest request, int categoryId)
        {
            var category = await _context.Categories.FindAsync(categoryId);

            var categoryTranslation = await _context.CategoryTranslations.FirstOrDefaultAsync(x => x.CategoryId == categoryId &&
                                                                                              x.LanguageId == request.LanguageId);

            if (category == null || categoryTranslation == null)
            {
                return(new ApiResultErrors <bool>($"Cannot find a category with id: {categoryId}"));
            }

            categoryTranslation.Name        = request.Name;
            categoryTranslation.CategoryUrl = GetUrlByName.Converts(request.Name);
            category.IsShowOnHome           = request.IsShowOnHome;

            //Save Image
            if (request.ThumbnailImage != null)
            {
                var OldImagePath = category.ImagePath;
                category.ImagePath = await this.SaveFile(request.ThumbnailImage);

                if (OldImagePath != null)
                {
                    await _storageService.DeleteFileAsync(OldImagePath);
                }
            }
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #5
0
        public async Task <ApiResult <bool> > Update(CommentUpdateRequest request, int commentId)
        {
            var comment = await _context.Comments.FindAsync(commentId);

            comment.Content    = request.Content;
            comment.Created_At = DateTime.Now;
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #6
0
        public async Task <ApiResult <bool> > RemoveImage(int ImageId)
        {
            var image = await _context.ProductImages.FindAsync(ImageId);

            if (image == null)
            {
                return(new ApiResultErrors <bool>($"Can not find image with id: {ImageId}"));
            }
            _context.ProductImages.Remove(image);
            return(await SaveChangeService.SaveChangeAsyncImage(_context, image.ImagePath, _storageService));
        }
        public async Task <ApiResult <bool> > Delete(int reviewId)
        {
            var review = await _context.ReViews.FindAsync(reviewId);

            if (review == null)
            {
                return(new ApiResultErrors <bool>($"Can not find review with id: {reviewId}"));
            }
            _context.ReViews.Remove(review);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Delete(int blogId)
        {
            var blog = await _context.Blogs.FindAsync(blogId);

            if (blog == null)
            {
                return(new ApiResultErrors <bool>($"Can not find blog with id: {blogId}"));
            }
            _context.Blogs.Remove(blog);
            return(await SaveChangeService.SaveChangeAsyncImage(_context, blog.ImagePath, _storageService));
        }
Example #9
0
        public async Task <ApiResult <bool> > Delete(int commentId)
        {
            var comment = await _context.Comments.FindAsync(commentId);

            if (comment == null)
            {
                return(new ApiResultErrors <bool>($"Can not find comment with id: {commentId}"));
            }
            _context.Comments.Remove(comment);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #10
0
        public async Task <ApiResult <bool> > Delete(int categorytId)
        {
            var category = await _context.Categories.FindAsync(categorytId);

            if (category == null)
            {
                return(new ApiResultErrors <bool>($"Can not find Category with id: {categorytId}"));
            }
            _context.Categories.Remove(category);
            return(await SaveChangeService.SaveChangeAsyncImage(_context, category.ImagePath, _storageService));
        }
Example #11
0
        public async Task <ApiResult <bool> > Delete(int orderId)
        {
            var order = await _context.Orders.FindAsync(orderId);

            if (order == null)
            {
                return(new ApiResultErrors <bool>($"Can not find order with id: {orderId}"));
            }
            _context.Orders.Remove(order);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Delete(int promotionId)
        {
            var promotion = await _context.Promotions.FindAsync(promotionId);

            if (promotion == null)
            {
                return(new ApiResultErrors <bool>($"Can not find promotion with id: {promotionId}"));
            }
            _context.Promotions.Remove(promotion);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #13
0
        public async Task <ApiResult <bool> > Delete(string languageId)
        {
            var language = await _context.Languages.FindAsync(languageId);

            if (language == null)
            {
                return(new ApiResultErrors <bool>($"Can not find language with Id: {languageId}"));
            }
            _context.Remove(language);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > DeleteItem(int cartId, int productId)
        {
            var cartItem = await _context.CartProducts.FirstOrDefaultAsync(x => x.CartID == cartId &&
                                                                           x.ProductID == productId);

            if (cartItem == null)
            {
                return(new ApiResultErrors <bool>($"Can not find cartItem"));
            }
            _context.CartProducts.Remove(cartItem);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #15
0
        public async Task <ApiResult <bool> > Create(ContactViewModel request)
        {
            var contact = new Contact()
            {
                Name    = request.FullName,
                Email   = request.Email,
                Message = request.Messmage,
            };

            _context.Contacts.Add(contact);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #16
0
        public async Task <ApiResult <bool> > Update(LanguageUpdateRequest request, string languageId)
        {
            var language = await _context.Languages.FindAsync(languageId);

            if (language == null)
            {
                return(new ApiResultErrors <bool>($"Can not find language with Id: {languageId}"));
            }
            language.Name      = request.Name;
            language.IsDefault = request.IsDefault;
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #17
0
        public async Task <ApiResult <bool> > Create(LanguageCreateRequest request)
        {
            var language = new Language()
            {
                Id        = request.Id,
                Name      = request.Name,
                IsDefault = request.IsDefault
            };

            _context.Languages.Add(language);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Update(PromotionUpdateRequest request, int promotionId)
        {
            var promotion = await _context.Promotions.FindAsync(promotionId);

            if (promotion == null)
            {
                return(new ApiResultErrors <bool>($"Can not find promotion with id: {promotionId}"));
            }
            promotion.DiscountAmount = request.DiscountAmount;
            promotion.FromDate       = request.FromDate;
            promotion.ToDate         = request.ToDate;
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #19
0
        public async Task <ApiResult <bool> > Create(CommentCreateRequest request)
        {
            var comment = new Comment()
            {
                Created_At = DateTime.Now,
                Content    = request.Content,
                UserId     = request.UserId,
                BlogId     = request.BlogId
            };

            _context.Comments.Add(comment);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Create(PromotionCreateRequest request)
        {
            var promotion = new Promotion()
            {
                Code            = request.Code,
                DiscountPercent = request.DiscountPercent,
                DiscountAmount  = request.DiscountAmount,
                FromDate        = request.FromDate,
                ToDate          = request.ToDate
            };

            _context.Promotions.Add(promotion);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #21
0
        public async Task <ApiResult <bool> > Update(ProductUpdateRequest request)
        {
            var product = await _context.Products.FindAsync(request.Id);

            var productTranslation = await _context.ProductTranslations.FirstOrDefaultAsync(x => x.ProductId == request.Id &&
                                                                                            x.LanguageId == request.LanguageId);

            if (product == null || productTranslation == null)
            {
                return(new ApiResultErrors <bool>($"Cannot find a product with id: {request.Id}"));
            }

            productTranslation.Name        = request.Name;
            productTranslation.ProductUrl  = GetUrlByName.Converts(request.Name);
            productTranslation.Description = request.Description;
            //Save Image
            if (request.ThumbnailImage != null)
            {
                var thumbnailImage = await _context.ProductImages.FirstOrDefaultAsync(i => i.IsDefault == true && i.ProductId == request.Id);

                if (thumbnailImage != null)
                {
                    var OldImagePath = thumbnailImage.ImagePath;
                    thumbnailImage.FileSize  = request.ThumbnailImage.Length;
                    thumbnailImage.ImagePath = await this.SaveFile(request.ThumbnailImage);

                    if (OldImagePath != null)
                    {
                        await _storageService.DeleteFileAsync(OldImagePath);
                    }
                    _context.ProductImages.Update(thumbnailImage);
                }
                else
                {
                    var image = new ProductImage()
                    {
                        ProductId = request.Id,
                        IsDefault = false,
                        Caption   = "ThumbanailImage",
                    };
                    image.FileSize  = request.ThumbnailImage.Length;
                    image.ImagePath = await this.SaveFile(request.ThumbnailImage);

                    _context.ProductImages.Add(image);
                }
            }

            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Create(ReviewCreateRequest request)
        {
            var review = new Review()
            {
                Created_At = DateTime.Now,
                Content    = request.Content,
                Email      = request.Email,
                Rating     = request.Rating,
                ProductId  = request.ProductId,
                Name       = request.Name
            };

            _context.ReViews.Add(review);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Update(BlogUpdateRequest request, int blogId)
        {
            var blog = await _context.Blogs.FindAsync(blogId);

            blog.Content    = request.Content;
            blog.Title      = request.Title;
            blog.CategoryId = request.CategoryId;
            //Save Image
            if (request.ThumbnailImage != null)
            {
                var OldImagePath = blog.ImagePath;
                blog.ImagePath = await this.SaveFile(request.ThumbnailImage);

                await _storageService.DeleteFileAsync(OldImagePath);
            }
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #24
0
        public async Task <ApiResult <bool> > AddImage(int ProductId, ProductImageCreateRequest request)
        {
            var image = new ProductImage()
            {
                ProductId = ProductId,
                IsDefault = request.IsDefault,
                Caption   = request.Caption
            };

            if (request.ThumbnailImage != null)
            {
                image.FileSize  = request.ThumbnailImage.Length;
                image.ImagePath = await this.SaveFile(request.ThumbnailImage);
            }
            _context.ProductImages.Add(image);

            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #25
0
        public async Task <ApiResult <bool> > UpdateStatus(int status, int orderId)
        {
            var order = await _context.Orders.FindAsync(orderId);

            if (order == null)
            {
                return(new ApiResultErrors <bool>($"Can not find order with id: {orderId}"));
            }
            switch (status)
            {
            case 0: order.Status = Data.Enums.OrderStatus.InProgress; break;

            case 1: order.Status = Data.Enums.OrderStatus.Shipping; break;

            case 2: order.Status = Data.Enums.OrderStatus.Delivered; break;
            }
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #26
0
        public async Task <ApiResult <bool> > Delete(int ProductId)
        {
            var product = await _context.Products.FindAsync(ProductId);

            if (product == null)
            {
                new ApiResultErrors <bool>($"Cannot find  a product:{ProductId}");
            }

            var images = _context.ProductImages.Where(i => i.ProductId == ProductId);

            foreach (var image in images)
            {
                await _storageService.DeleteFileAsync(image.ImagePath);
            }
            _context.Products.Remove(product);

            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > UpdateQuantity(CartItemUpdateRequest request)
        {
            var cartItem = await _context.CartProducts.FirstOrDefaultAsync(x => x.CartID == request.CartID &&
                                                                           x.ProductID == request.ProductID);

            if (cartItem == null)
            {
                var newCartItem = new CartProduct
                {
                    CartID    = request.CartID,
                    ProductID = request.ProductID,
                    Quantity  = request.Quantity
                };
                _context.CartProducts.Add(newCartItem);
                return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
            }
            cartItem.Quantity = request.Quantity;
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Create(BlogCreateRequest request)
        {
            var blog = new Blog()
            {
                Title      = request.Title,
                Created_At = DateTime.Now,
                Content    = request.Content,
                UserId     = request.UserId,
                LikeCount  = 0,
                CategoryId = request.CategoryId
            };

            //Save Image
            if (request.ThumbnailImage != null)
            {
                blog.ImagePath = await this.SaveFile(request.ThumbnailImage);
            }
            _context.Blogs.Add(blog);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
        public async Task <ApiResult <bool> > Create(CartCreateRequest request)
        {
            var cart = new Cart
            {
                Created_At = DateTime.Now,
                UserId     = request.UserId,
                Price      = request.Price,
            };

            foreach (var item in request.Items)
            {
                var cartProduct = new CartProduct
                {
                    ProductID = item.Product.Id,
                    Quantity  = item.Quantity
                };
                cart.CartProducts.Add(cartProduct);
            }
            _context.Carts.Add(cart);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }
Example #30
0
        public async Task <ApiResult <bool> > Create(ProductCreateRequest request)
        {
            var product = new Product()
            {
                Price               = request.Price,
                OriginalPrice       = request.OriginalPrice,
                CategoryId          = request.CategoryId,
                Stock               = request.Stock,
                Created_At          = DateTime.Now,
                ProductTranslations = new List <ProductTranslation>()
                {
                    new ProductTranslation()
                    {
                        Name        = request.Name,
                        Description = request.Description,
                        ProductUrl  = GetUrlByName.Converts(request.Name),
                        LanguageId  = request.LanguageId,
                    }
                },
            };

            //Save Image
            if (request.ThumbnailImage != null)
            {
                product.ProductImages = new List <ProductImage>()
                {
                    new ProductImage()
                    {
                        Caption   = "Thumbnail image",
                        FileSize  = request.ThumbnailImage.Length,
                        ImagePath = await this.SaveFile(request.ThumbnailImage),
                        IsDefault = true,
                    }
                };
            }
            _context.Products.Add(product);
            return(await SaveChangeService.SaveChangeAsyncNotImage(_context));
        }