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)); }
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> > DisLike(int blogId) { var blog = await _context.Blogs.FindAsync(blogId); blog.LikeCount--; 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)); }
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)); }
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 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 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)); }
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)); }
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> > 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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
public async Task <ApiResult <bool> > UpdateImage(int imageId, ProductImageUpdateRequest request) { var image = await _context.ProductImages.FindAsync(imageId); if (image == null) { return(new ApiResultErrors <bool>($"can not find image with id: {imageId}")); } image.Caption = request.Caption; image.IsDefault = request.IsDefault; if (request.ThumbnailImage != null) { var OldImagePath = image.ImagePath; image.FileSize = request.ThumbnailImage.Length; image.ImagePath = await this.SaveFile(request.ThumbnailImage); if (OldImagePath != null) { await _storageService.DeleteFileAsync(OldImagePath); } } return(await SaveChangeService.SaveChangeAsyncNotImage(_context)); }
public async Task <ApiResult <string> > Create(OrderCreateRequest request) { try { var order = new Order() { Created_At = DateTime.Now, OrderNotes = request.OrderNotes, UserId = (request.UserId == null)?(Guid?)null:(new Guid(request.UserId)), PromotionId = (request.PromotionId != 0)?request.PromotionId: (int?)null, ShipName = request.ShipName, ShipAddress = request.Street + " " + request.ShipAddress, ShipEmail = request.ShipEmail, ShipPhone = request.ShipPhone, Total = request.Total, OrderDetails = new List <OrderDetail>() }; foreach (var item in request.OrderDetails) { var orderDetail = new OrderDetail { ProductId = item.ProductId, Quantity = item.Quantity, Price = item.Price }; order.OrderDetails.Add(orderDetail); } _context.Orders.Add(order); await SaveChangeService.SaveChangeAsyncNotImage(_context); return(new ApiResultSuccess <string>(order.Id.ToString())); } catch (Exception ex) { return(new ApiResultErrors <string>(ex.InnerException.Message)); } }