public async Task <int> Create(CategoryCreateRequest request) { var category = new Category() { Name = request.Name, SortOrder = request.SortOrder, ParentId = request.ParentId }; _context.Categories.Add(category); await _context.SaveChangesAsync(); return(category.Id); }
///////////// Đơn hàng//////////////////////// public async Task <int> CreateOrder(OrderCreateRequest request) { var order = new Order() { name = request.name, Address = request.Address, mail = request.mail, Phone = request.Phone, Status = OrderStatus.InProgress, OrderDate = DateTime.Now }; _context.Orders.Add(order); await _context.SaveChangesAsync(); return(order.Id); }
//Thêm ảnh mới vào sản phẩm public async Task <int> AddImage(int productId, ProductImageCreateRequest request) { var productImage = new ProductImage() { DateCreated = DateTime.Now, IsDefault = request.IsDefault, ProductId = productId }; if (request.ImageFile != null) { productImage.ImagePath = await this.SaveFile(request.ImageFile); productImage.FileSize = request.ImageFile.Length; productImage.IsDefault = request.IsDefault; } _context.ProductImages.Add(productImage); await _context.SaveChangesAsync(); return(productImage.Id); }