Esempio n. 1
0
        public User AddUser(string name, string surname, string emailAddress, string cellphoneNumber, string password)
        {
            if (_recipeManagementContext.Users.AsEnumerable().Any(u => u.EmailAddress == emailAddress))
            {
                throw new RecipeManagementException("User with specified email address already exists");
            }

            var user = new User
            {
                UserId = Guid.NewGuid(),
                Name = name,
                Surname = surname,
                CellphoneNumber = cellphoneNumber,
                EmailAddress = emailAddress,
                PasswordSalt = _cryptographyService.CreateSalt()
            };
            user.Password = _cryptographyService.CreatePasswordHash(password, user.PasswordSalt);
            DateTime now = DateTime.Now;
            user.DateCreated = now;
            user.DateUpdated = now;

            _recipeManagementContext.Users.Add(user);

            _recipeManagementContext.SaveChanges();

            return user;
        }
 public static void PrepareTestData(this RecipeManagementContext recipeManagementContext, Action <RecipeManagementContext> action)
 {
     Assert.That(recipeManagementContext.IsDirty, Is.EqualTo(false));
     action.Invoke(recipeManagementContext);
     Assert.That(recipeManagementContext.IsDirty, Is.EqualTo(true));
     recipeManagementContext.SaveChanges();
     Assert.That(recipeManagementContext.IsDirty, Is.EqualTo(false));
 }
        public Recipe AddRecipe(string title, string description, List <RecipeStep> steps, string notes, Guid userId)
        {
            DateTime now = DateTime.Now;

            var recipe = new Recipe
            {
                RecipeId    = Guid.NewGuid(),
                Title       = title,
                Description = description,
                Steps       = OrderSteps(steps),
                Notes       = notes,
                CreatedById = userId,
                DateCreated = now,
                DateUpdated = now
            };

            _recipeManagementContext.Recipes.Add(recipe);

            _recipeManagementContext.SaveChanges();

            return(recipe);
        }