Example #1
0
        public async Task <IActionResult> Create([Bind("DadDailyItemId,TodaysDate,UpOnTime,GetEarlyTrain,CallPhilip550,CallChrista550,WorkAtFinsburyPark,HitTheGym")] DadDailyItem dadDailyItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dadDailyItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dadDailyItem));
        }
        public async Task DeleteMemberFromFamilyAsync(string streetName, int houseNumber, string memberType, int memberId)
        {
            Console.WriteLine("\tDeleting member from family");
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                Family family = await GetFamilyByAddress(streetName, houseNumber);

                switch (memberType)
                {
                case "adults":
                    Adult adult = family.Adults.First(a => a.Id == memberId);
                    dbContext.Remove(adult);
                    break;

                case "children":
                    Child child = family.Children.First(c => c.Id == memberId);
                    dbContext.Remove(child);
                    break;

                case "pets":
                    Pet pet = family.Pets.First(p => p.Id == memberId);
                    dbContext.Remove(pet);
                    break;
                }

                dbContext.Update(family);
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task RegisterAsync(APIUser user)
        {
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                await dbContext.Users.AddAsync(user);

                await dbContext.SaveChangesAsync();
            }
        }
 public async Task UpdateFamilyAsync(Family family)
 {
     Console.WriteLine("\tUpdating");
     using (FamilyDbContext dbContext = new FamilyDbContext())
     {
         dbContext.Update(family);
         await dbContext.SaveChangesAsync();
     }
 }
        public async Task CreateFamilyAsync(Family family)
        {
            Console.WriteLine("\tCreating family");
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                await dbContext.Families.AddAsync(family);

                await dbContext.SaveChangesAsync();
            }
        }
        public async Task DeleteFamilyAsync(string streetName, int?houseNumber)
        {
            Console.WriteLine("\tDeleting family");
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                Family family = await GetFamilyByAddress(streetName, houseNumber);

                dbContext.Remove(family);
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task AddChildToFamilyAsync(string streetName, int houseNumber, Child child)
        {
            Console.WriteLine("\tAdding child to family " + child.Id);
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                Family family = await GetFamilyByAddress(streetName, houseNumber);

                family.Children.Add(child);
                dbContext.Add(child);
                dbContext.Update(family);
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task AddAdultToFamilyAsync(string streetName, int houseNumber, Adult adult)
        {
            Console.WriteLine("\tAdding adult to family " + adult.Id);
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                Family family = await GetFamilyByAddress(streetName, houseNumber);

                family.Adults.Add(adult);
                dbContext.Add(adult);
                dbContext.Update(family);
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task UpdatePetInFamilyAsync(string streetName, int houseNumber, Pet pet)
        {
            Console.WriteLine("\tUpdating pet in family");
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                Family family = await GetFamilyByAddress(streetName, houseNumber);

                family.EditPet(pet);
                dbContext.Update(pet);
                //dbContext.Update(family);
                await dbContext.SaveChangesAsync();
            }
        }
        public async Task UpdateAdultInFamilyAsync(string streetName, int houseNumber, Adult adult)
        {
            Console.WriteLine("\tUpdating adult in family");
            using (FamilyDbContext dbContext = new FamilyDbContext())
            {
                Family family = await GetFamilyByAddress(streetName, houseNumber);

                family.EditAdult(adult);
                dbContext.Update(adult);
                // dbContext.Update(family);
                Console.WriteLine("Before saving changes");
                await dbContext.SaveChangesAsync();

                Console.WriteLine("Saved changes to update adult");
            }
        }