/// <summary>
        /// Creates a new shopping list for the current user.
        /// </summary>
        /// <param name="list">A ShoppingList object containing a normalized shopping list.</param>
        /// <returns>A result indicating the ID assigned to the newly created list.</returns>
        public ShoppingListResult CreateShoppingList(ShoppingList list)
        {
            var ret = new ShoppingListResult();
             var dbList = new Data.DTO.ShoppingLists
             {
            ShoppingListId = Guid.NewGuid(),
            Title = list.Title.Trim(),
            UserId = Identity.UserId
             };

             store.ShoppingLists.Add(dbList);

             if (list.Any()) // Create ShoppingListItems
             {
            list.ToList().ForEach(i => store.ShoppingListItems.Add(new ShoppingListItems
            {
               ItemId = Guid.NewGuid(),
               UserId = Identity.UserId,
               ShoppingListId = dbList.ShoppingListId,
               CrossedOut = i.CrossedOut,
               IngredientId = i.Ingredient != null ? (Guid?) i.Ingredient.Id : null,
               RecipeId = i.Recipe != null ? (Guid?) i.Recipe.Id : null,
               Raw = i.Raw,
               Qty = i.Amount != null ? (float?) i.Amount.SizeHigh : null,
               Unit = i.Amount != null ? (Units?) i.Amount.Unit : null
            }));
             }

             ret.NewShoppingListId = dbList.ShoppingListId;
             ret.List = list;
             return ret;
        }
Exemple #2
0
        public ShoppingListResult CreateShoppingList(AuthIdentity identity, ShoppingList list)
        {
            using (var session = GetSession())
             {
            var ret = new ShoppingListResult();

            using (var transaction = session.BeginTransaction())
            {
               var dbList = new Models.ShoppingLists();
               dbList.Title = list.Title.Trim();
               dbList.UserId = identity.UserId;
               session.Save(dbList);

               if (list.Any()) // Create ShoppingListItems
               {
                  list.ToList().ForEach(i =>
                  {
                     var dbItem = ShoppingListItems.FromShoppingListItem(i);
                     dbItem.ShoppingList = dbList;
                     dbItem.UserId = dbList.UserId;
                     session.Save(dbItem);
                  });
               }

               transaction.Commit();

               ret.NewShoppingListId = dbList.ShoppingListId;
            }

            ret.List = list;
            return ret;
             }
        }
        public ShoppingListResult CreateShoppingList(AuthorIdentity identity, ShoppingList list)
        {
            using (var session = this.GetSession())
            {
                var shopingList = new ShoppingListResult();

                using (var transaction = session.BeginTransaction())
                {
                    var databaseList = new ShoppingLists();
                    databaseList.Title = list.Title.Trim();
                    databaseList.UserId = identity.UserId;
                    session.Save(databaseList);

                    CreateShopingList(list, databaseList, session);

                    transaction.Commit();

                    shopingList.NewShoppingListId = databaseList.ShoppingListId;
                }

                shopingList.List = list;
                return shopingList;
            }
        }