diff --git a/MirysList/Controllers/ShopController.cs b/MirysList/Controllers/ShopController.cs index f2933e7..18e3b1a 100644 --- a/MirysList/Controllers/ShopController.cs +++ b/MirysList/Controllers/ShopController.cs @@ -79,34 +79,25 @@ public IActionResult ShoppingListItems(int shoppinglistId) // POST: api/Shop/CreateList [HttpPost] - [Route("api/Shop/CreateList")] - public IActionResult CreateList() - //public IActionResult CreateList([FromBody]ShoppingList listObj) - { - // ShoppingList listObj = new ShoppingList(); + [Route("api/Shop/CreateList")] + public IActionResult CreateList([FromBody]ShoppingList listObj) + { try { - // Family family = _dbContext.Families.Where(x => x.Id == familyId).FirstOrDefault(); - // if(family != null) - // { - // listObj.Family = family; - // listObj.listItems = new List(); - // listObj.listItems = listItems; - + _dbContext.ShoppingLists.Add(listObj); + foreach(ShoppingListItem item in listObj.listItems) + { + _dbContext.ShoppingListItems.Add(item); + } - //EntityEntry listentity = _dbContext.ShoppingLists.Add(listObj); - // _dbContext.SaveChanges(); - Console.WriteLine("hellow world"); - - //} + _dbContext.SaveChanges(); } catch { - return NotFound("could not create a list for this family "); + return NotFound("could not create a list"); } - - return Ok("post completed "); - // return Ok(listObj); + + return Ok(listObj); } // POST: api/Shop/UpdateList diff --git a/MirysList/Models/ShoppingListItem.cs b/MirysList/Models/ShoppingListItem.cs index ba5ba50..2d60bb9 100644 --- a/MirysList/Models/ShoppingListItem.cs +++ b/MirysList/Models/ShoppingListItem.cs @@ -15,10 +15,7 @@ public class ShoppingListItem [Required] public int Quantity { get; set; } public ShoppingList ShoppingList { get; set; } - //[Required] - // public int UserId { get; set; } - - //[Required] - //public User User { get; set; } + [Required] + public User User { get; set; } } } diff --git a/MirysList/appsettings.json b/MirysList/appsettings.json index 0c42e0f..c5ba93b 100644 --- a/MirysList/appsettings.json +++ b/MirysList/appsettings.json @@ -13,7 +13,7 @@ } }, "ConnectionStrings": { - //"DbContextConnectionString": "Data Source=tcp:miryslistserver.database.windows.net,1433;Initial Catalog=MirysListDb;User ID=miryslistserver;Password=Hackathon123" - "DbContextConnectionString": "Data Source=swapnag1;Initial Catalog=Miryslist1;Integrated Security=True" + "DbContextConnectionString": "Data Source=tcp:miryslistserver.database.windows.net,1433;Initial Catalog=MirysListDb;User ID=miryslistserver;Password=Hackathon123" + //"DbContextConnectionString": "Data Source=swapnag1;Initial Catalog=Miryslist1;Integrated Security=True" } }