public async Task <ApiResult <bool> > Delete(int Id) { var product = await _mockProjectDbContext.Products.FindAsync(Id); _mockProjectDbContext.Products.Remove(product); await _mockProjectDbContext.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <bool> > Create(CategoryCreateRequest request) { var query = _mockProjectDbContext.Categories.Any(x => x.Name == request.CategoryName); if (query) { //throw new MockProjectException("Danh mục này đã tồn tại"); return(new ApiErrorResult <bool>()); } Category category = new Category { Name = request.CategoryName }; _mockProjectDbContext.Add(category); await _mockProjectDbContext.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <int> Create(ProductCreateRequest request) { string uniqueImageName = NewImage(request); Product product = new Product { Name = request.Name, Account = request.Account, Password = request.Password, Price = request.Price, Description = request.Description, Image = uniqueImageName, CategoryId = request.CategoryId, DateCreated = DateTime.Now }; _mockProjectDbContext.Add(product); await _mockProjectDbContext.SaveChangesAsync(); return(product.Id); }