Ejemplo n.º 1
0
        private static void InitUserCharity(CharityHubContext context)
        {
            if (context.Users_Charities.Any())
            {
                return;
            }

            var user_Charities = new User_Charity[] {
                new User_Charity()
                {
                    CharityId = 1, UserId = 2
                },
                new User_Charity()
                {
                    CharityId = 1, UserId = 4
                },
                new User_Charity()
                {
                    CharityId = 2, UserId = 2
                },
                new User_Charity()
                {
                    CharityId = 2, UserId = 3
                }
            };

            foreach (var s in user_Charities)
            {
                context.Users_Charities.Add(s);
            }

            context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void ObserveCharity(int userId, int charityId)
        {
            var exists = _context.Users_Charities.Any(x => x.UserId == userId && x.CharityId == charityId);

            if (exists)
            {
                return;
            }

            var observedCharity = new User_Charity()
            {
                CharityId = charityId,
                UserId    = userId
            };

            _context.Users_Charities.Add(observedCharity);
            _context.SaveChanges();
        }