public void SetupForTests() { _testCollector = new Collector(new DatabaseContext()); _testItem = new Item() { ItemId = 100, Name = "TestItem", IsBought = true }; _testIngredient = new Ingredient() { ItemId = 101, Name = "TestIngredient", Amount = 10 }; _testRecipe = new Recipe() { RecipeId = 100, RecipeName = "TestOpskrift", Ingredients = new List<Ingredient>() { _testIngredient, new Ingredient() }, AddedTime = DateTime.Now }; _testFoodplan = new Foodplan() { FoodPlanId = 100, CreatedDate = DateTime.Now, Recipies = new List<RecipesInFoodplan>() { new RecipesInFoodplan() {Recipe = _testRecipe, RecipeDate = DateTime.Now} }, FoodplanStartTime = DateTime.Now, FoodplanEndTime = DateTime.MaxValue, LastModified = DateTime.Now }; _testShoppinglist = new Shoppinglist() { ShoppingListId = 100, Items = new List<Item>() { _testItem } }; _testUser = new User() { UserId = 100, UserName = "******", UserPassword = "******", UserFoodplan = _testFoodplan, UserShoppingList = _testShoppinglist }; }
public IHttpActionResult PostNewUser(string newUsername, string newPassword) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Foodplan userFooplan = new Foodplan() {CreatedDate = DateTime.Now, FoodplanStartTime = DateTime.Now, FoodplanEndTime = DateTime.Now, LastModified = DateTime.Now}; Shoppinglist userShoppinglist = new Shoppinglist(); _collector.Foodplans.Add(userFooplan); _collector.Shoppinglists.Add(userShoppinglist); _collector.Save(); User user = new User() {UserName = newUsername, UserPassword = newPassword, UserShoppingList = _collector.Shoppinglists.GetWithId(userShoppinglist.ShoppingListId), UserFoodplan = _collector.Foodplans.GetWithId(userFooplan.FoodPlanId)}; _collector.Users.Add(user); _collector.Save(); return CreatedAtRoute("DefaultApi", new { id = user.UserId }, user); }
public IHttpActionResult PostFoodplan(Foodplan foodplan) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _collector.Foodplans.Add(foodplan); _collector.Save(); return CreatedAtRoute("DefaultApi", new { id = foodplan.FoodPlanId }, foodplan); }