Example #1
0
        public async Task <bool> RemoveFamilyAsync(Family toRemove)
        {
            var fam = await _familyApiContext.Families
                      .Include(f => f.Adults)
                      .FirstOrDefaultAsync(f
                                           => f.StreetName == toRemove.StreetName && f.HouseNumber == toRemove.HouseNumber);

            var removed = _familyApiContext.Families.Remove(fam);
            await _familyApiContext.SaveChangesAsync();

            return(removed.State == EntityState.Deleted);
        }
Example #2
0
        public async Task RegisterUserAsync(string username, string password)
        {
            var user = await _familyApiContext.Users
                       .FirstOrDefaultAsync(u => u.Username == username);

            if (user == null)
            {
                var newUser = new User
                {
                    Username = username,
                    Password = HashAndSalt(password)
                };
                await _familyApiContext.Users.AddAsync(newUser);

                await _familyApiContext.SaveChangesAsync();
            }
        }