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);
        }
Example #3
0
        public async Task <ApiResult <bool> > Create(ProductCreateRequest request)
        {
            var     category        = _mockProjectDbContext.Categories.First(x => x.Name == request.CategoryName);
            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  = category.Id,
                DateCreated = DateTime.Now
            };

            _mockProjectDbContext.Add(product);
            await _mockProjectDbContext.SaveChangesAsync();

            return(new ApiSuccessResult <bool>());
        }