public async Task <ShopListElement> AddListElement(ShopListElement shopListElement) { context.ShopListElements.Add(shopListElement); await context.SaveChangesAsync(); return(shopListElement); }
public bool DeleteListElement(ShopListElement shopListElement) { ShopListElement dbEntity = context.ShopListElements.FirstOrDefault(p => p.ID == shopListElement.ID); if (dbEntity != null) { context.ShopListElements.Remove(dbEntity); context.SaveChanges(); return(true); } return(false); }
public async Task <IActionResult> DeleteShopingListElement([FromBody] ShopListElementViewModel shopListElementViewModel) { User user = await userManager.GetUserAsync(HttpContext.User); ShopListElement shopListElement = new ShopListElement { Content = shopListElementViewModel.Content, ID = shopListElementViewModel.ID, IsChecked = shopListElementViewModel.IsChecked, PositionInList = shopListElementViewModel.PositionInList, User = user }; return(Json(new { succeed = shopingListRepository.DeleteListElement(shopListElement) })); }
public async Task <IActionResult> AddShopingListElement([FromBody] ShopListElementViewModel shopListElementViewModel) { User user = await userManager.GetUserAsync(HttpContext.User); var shopinglistElement = new ShopListElement { User = user, IsChecked = shopListElementViewModel.IsChecked, Content = shopListElementViewModel.Content, PositionInList = shopingListRepository.ShopListElements(user).Result.Last().PositionInList + 1 }; var tmp = shopingListRepository.AddListElement(shopinglistElement).Result; return(Json(new ShopListElementViewModel { ID = tmp.ID, Content = tmp.Content, PositionInList = tmp.PositionInList, IsChecked = tmp.IsChecked })); }
public async Task SaveListElement(ShopListElement shopListElement) { context.ShopListElements.Add(shopListElement); await context.SaveChangesAsync(); }