Skip to content

Commit

Permalink
fixing post api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Swapna Guddanti committed Jul 24, 2018
1 parent e919cba commit cd46bbd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
33 changes: 12 additions & 21 deletions MirysList/Controllers/ShopController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShoppingListItem>();
// listObj.listItems = listItems;

_dbContext.ShoppingLists.Add(listObj);
foreach(ShoppingListItem item in listObj.listItems)
{
_dbContext.ShoppingListItems.Add(item);
}

//EntityEntry<ShoppingList> 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
Expand Down
7 changes: 2 additions & 5 deletions MirysList/Models/ShoppingListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
4 changes: 2 additions & 2 deletions MirysList/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit cd46bbd

Please sign in to comment.