public async Task <bool> CreateAsync(Role role)
        {
            _dbContext.Add(role);
            await _dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> CreateAsync(Product product)
        {
            await _dbContext.Products.AddAsync(product);

            await _dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> CreateAsync(Category category)
        {
            await _dbContext.AddAsync(category);

            await _dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Create([Bind("Id,Type")] Role role)
        {
            if (ModelState.IsValid)
            {
                _context.Add(role);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(role));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("Name,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(product));
        }
        public async Task <bool> CreateAsync(User user)
        {
            var role = _dbContext.Roles.Where(r => r.Type == "User").FirstOrDefault();

            user.Role = role;

            var res = _dbContext.Users.Where(x => x.Username == user.Username).FirstOrDefault();

            if (res == null && user.Password != null)
            {
                user.Password = MD5Hash(user.Password);
                _dbContext.Users.Add(user);
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            return(false);
        }