Example #1
0
        public async Task <ActionResult <User> > CreateUser(User user)
        {
            var newUser = new User {
                Email = user.Email, PhoneNumber = user.PhoneNumber, UserName = user.UserName, Role = user.Role
            };

            _context.Users.Add(newUser);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetUser), new { id = newUser.Id }, newUser));
        }
Example #2
0
        public async Task <Product> CreateProduct(Product product)
        {
            var newProduct = new Product
            {
                Name     = product.Name, Brand = product.Brand, Price = product.Price,
                Quantity = product.Quantity, Type = product.Type
            };

            _dbContext.Products.Add(newProduct);
            await _dbContext.SaveChangesAsync();

            return(newProduct);
        }