Exemple #1
0
        /// <summary>
        /// Deletes a ShopList member from the ShopListMember 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> DeleteShopListMember(ShopList shopList, AppUser user)
        {
            var result = new Tuple <bool, string>(false, "");

            using (var connection = new SQLiteConnection(LoadConnectionString()))
            {
                try
                {
                    connection.Execute($"DELETE FROM ShopListMember WHERE AppUser_ID = {user.ID} AND ShopList_ID = {shopList.SHOPLISTID}");

                    if (!(SADatabaseReader.DoesShopListMemberExist(shopList, user)))
                    {
                        result = new Tuple <bool, string>(true, $"ShopListMember {user.UserName}({user.ID}) is verwijderd.");
                    }
                    else
                    {
                        result = new Tuple <bool, string>(false, $"ShopListMember {user.UserName}({user.ID}) bestaat nog.");
                    }
                }
                catch (SQLiteException ex)
                {
                    // TODO : SADatabaseReader.DeleteShopListMember: 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);
        }