Beispiel #1
0
        // Method for creating product
        public virtual async Task <Product> CreateProduct(Product product)
        {
            await dbContext.AddAsync(product);

            dbContext.SaveChanges();
            return(product);
        }
Beispiel #2
0
        // Method for creating new user
        public User CreateUser(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Indtast password.");
            }

            if (dbContext.Users.Any(x => x.Email == user.Email))
            {
                throw new AppException("En bruger med email \"" + user.Email + "\" er allerede registreret!");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            return(user);
        }