Exemple #1
0
        /// <summary>
        /// Updates or creates a shoplist owner record in the ShopListOwner table.
        /// </summary>
        /// <param name="shopList"></param>
        /// <param name="user"></param>
        /// <returns>
        /// Returns a Tuple<bool, string> with a processing message.
        /// </returns>
        public static Tuple <bool, string> UpdateShopListOwner(ShopList shopList, AppUser user)
        {
            Tuple <bool, string> result = new Tuple <bool, string>(false, "");

            using (SQLiteConnection connection = new SQLiteConnection(LoadConnectionString(), SQLiteOpenFlags.ReadWrite))
            {
                try
                {
                    if (SADatabaseReader.DoesShopListExist(shopList))
                    {
                        connection.Execute(
                            "INSERT OR REPLACE INTO ShopListOwner (AppUser_ID, ShopList_ID, DateTimeModified) " +
                            $"VALUES ({user.ID}, {shopList.SHOPLISTID}, '{DateTimeStamp.Stamp()}')"
                            );

                        result = new Tuple <bool, string>(false, $"De owner van shoplist {shopList.Name}({shopList.SHOPLISTID}) is bijgewerkt.");
                    }
                    else
                    {
                        result = new Tuple <bool, string>(false, $"ShopList {shopList.Name}({shopList.SHOPLISTID}) bestaat niet.");
                    }
                }
                catch (SQLiteException ex)
                {
                    // TODO : SADatabaseReader.UpdateShopListOwner: Error logging naar log.db
                    throw;
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Adds a record to the ShopListMember table, with a foreign keys to the AppUser and ShopList tables.
        /// </summary>
        /// <param name="shopList"></param>
        /// <param name="user"></param>
        /// <returns>
        /// Returns a Tuple<bool, string>, with a processing message.
        /// </returns>
        public static Tuple <bool, string> AddShopListMember(ShopList shopList, AppUser user)
        {
            var result = new Tuple <bool, string>(false, "");

            using (var connection = new SQLiteConnection(LoadConnectionString()))
            {
                try
                {
                    if (SADatabaseReader.DoesShopListExist(shopList))
                    {
                        var AppUserExists = connection.Query <AppUser>($"SELECT * FROM AppUser WHERE ID = {user.ID}").Count;

                        if (AppUserExists > 0)
                        {
                            if (!(SADatabaseReader.DoesShopListMemberExist(shopList, user)))
                            {
                                connection.Execute(
                                    "INSERT OR REPLACE INTO ShopListMember (AppUser_ID, ShopList_ID, DateTimeAdded) " +
                                    $"VALUES ({user.ID}, {shopList.SHOPLISTID}, '{DateTimeStamp.Stamp()}')"
                                    );

                                result = new Tuple <bool, string>(false, $"Member {user.UserName}({user.ID}) is toegevoegd aan shoplist {shopList.Name}({shopList.SHOPLISTID}).");
                            }
                            else
                            {
                                result = new Tuple <bool, string>(false, $"Gebruiker {user.UserName}({user.ID}) bestaat al.");
                            }
                        }
                        else
                        {
                            result = new Tuple <bool, string>(false, $"Gebruiker {user.UserName}({user.ID}) bestaat niet of is nog niet opgeslagen.");
                        }
                    }
                    else
                    {
                        result = new Tuple <bool, string>(false, $"ShopList {shopList.Name}({shopList.SHOPLISTID}) bestaat niet of is nog niet opgeslagen.");
                    }
                }
                catch (SQLiteException ex)
                {
                    // TODO : SADatabaseReader.AddShopListMember: Error logging naar log.db
                    throw;
                }
            }

            return(result);
        }