Esempio n. 1
0
        public SubscriberAndPrefs FetchSubscriberAndPreferences()
        {
            lastcallContext c = new LastCallDatabase.lastcallContext();

            Subscribers person = c.Subscribers.Where(x => x.Id == 1).FirstOrDefault();

            if (person == null)
            {
                return(null);
            }

            Foodpreferences[] prefs = (from x in c.Foodpreferences where x.Subscriberid == person.Id select x).Include(x => x.Preference).ToArray();

            SubscriberAndPrefs result = new SubscriberAndPrefs(person);

            result.Preferences = new Preference[prefs.Length];

            for (int i = 0; i < prefs.Length; i++)
            {
                result.Preferences[i] = new Preference()
                {
                    Id = prefs[i].Id, Preftype = prefs[i].Preferenceid, Prefname = prefs[i].Preference.Foodtype
                }
            }
            ;

            return(result);
        }
Esempio n. 2
0
        // https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core-scaffold-example.html
        private bool CheckUserRegistered(string email)
        {
            lastcallContext c          = new LastCallDatabase.lastcallContext();
            Subscribers     subscriber = c.Subscribers.Where((x) => x.Email == email).FirstOrDefault();

            return(subscriber != null);
        }
Esempio n. 3
0
        // https://docs.microsoft.com/en-us/ef/ef6/fundamentals/relationships
        // https://docs.microsoft.com/en-us/ef/ef6/querying/related-data
        // http://foreverframe.net/when-use-include-with-entity-framework/
        private void DBCheck()
        {
            lastcallContext c = new LastCallDatabase.lastcallContext();

            // Explicit loading
            //Foodpreferences[] prefs = (from x in c.Foodpreferences where x.Subscriberid == 1 select x).ToArray<Foodpreferences>();
            //c.Entry(prefs[0]).Reference(x => x.Preference).Load();

            // Eager loading
            // Requires "using Microsoft.EntityFrameworkCore;"
            // See also .ThenInclude()
            Foodpreferences[] prefs = c.Foodpreferences.Where(x => x.Subscriberid == 1).Include(x => x.Preference).ToArray <Foodpreferences>();

            string s = prefs[0].Preference.Foodtype;

            s = s.ToUpper();
        }
Esempio n. 4
0
        private (bool, string) CreateNewSubscriber(string email, string password)
        {
            try
            {
                lastcallContext c = new LastCallDatabase.lastcallContext();

                Subscribers subscriber = new Subscribers()
                {
                    Email = email
                };
                c.Add(subscriber);
                c.SaveChanges();

                return(true, "Success");
            }
            catch (Exception X)
            {
                return(false, X.Message);
            }
        }