public void an_adult_has_everything_a_person_has_plus_walking_and_talking()
        {
            Adult adult = new Adult();

            Baby baby = new Baby();

            IList<Person> people = new List<Person>
            {
                adult,
                baby
            };

            // note: both the baby and adult can eat
            foreach (var person in people)
            {
                person.Eat();
            }

            // note: only the adult can walk which will set has walked to true
            adult.Walk();

            adult.HasWalked.ShouldBe(_);

            // note: because the baby inherits person we can still access HasWalked
            baby.HasWalked.ShouldBe(_);

            // note: both the baby and adult have eaten
            adult.HasEaten.ShouldBe(_);
            baby.HasEaten.ShouldBe(_);
        }
 public void RemoveAdult(Adult adult)
 {
     if (adults.Contains(adult))
     {
         adults.Remove(adult);
         familyFileHandler.SaveChanges();
     }
 }
        public async Task <Adult> AddAdult(Adult todo)
        {
            EntityEntry <Adult> newlyAdded = await ctx.Adults.AddAsync(todo);

            await ctx.SaveChangesAsync();

            return(newlyAdded.Entity);
        }
        public async Task <Adult> AddAdultAsync(Adult adult)
        {
            EntityEntry <Adult> newlyAdded = await ctx.Adult.AddAsync(adult);

            await ctx.SaveChangesAsync();

            return(newlyAdded.Entity);
        }
Exemple #5
0
        public void addData(Adult adult)
        {
            adult.Id = Adults.Max(t => t.Id) + 1;
            Adults.Add(adult);
            string adultJson = JsonSerializer.Serialize(Adults);

            File.WriteAllText(adultsFile, adultJson);
        }
Exemple #6
0
        public async Task <Adult> GetById(int Id)
        {
            Task <string> stringAsync = client.GetStringAsync(uri1 + $"/Adults/{Id}");
            string        message     = await stringAsync;
            Adult         result      = JsonSerializer.Deserialize <Adult>(message);

            return(result);
        }
Exemple #7
0
        public async Task addNewAdultAsync(Adult adult)
        {
            EntityEntry <Adult> newlyAdded = await ctx.Adults.AddAsync(adult);

            await ctx.SaveChangesAsync();

            //return newlyAdded.Entity;
        }
Exemple #8
0
        public async Task RemoveAdultAsync(int cprNumber, string address)
        {
            Family fam   = file.Families.FirstOrDefault(t => t.Address().Equals(address));
            Adult  adult = fam.Adults.FirstOrDefault(a => a.CPRNumber == cprNumber);

            fam.Adults.Remove(adult);
            file.SaveChanges();
        }
Exemple #9
0
        public void RemoveAdult(int adultId)
        {
            Adult toRemove = adults.First(a => a.Id == adultId);

            Console.WriteLine("Deleteee  " + toRemove.FirstName);
            fileContext.Adults.Remove(toRemove);
            fileContext.SaveChanges();
        }
        public async Task UpdateAsync(Adult person)
        {
            Adult toUpdate = adults.First(t => t.Id == person.Id);

            toUpdate          = person;
            toUpdate.JobTitle = person.JobTitle;
            WriteAdultsToFile();
        }
        public void Update(Adult adult)
        {
            Adult adultToUpdate = fileContext.Adults.First(a => a.Id == adult.Id);

            adults.Remove(adultToUpdate);
            adults.Add(adultToUpdate);
            fileContext.SaveChanges();
        }
        public async Task AddAdultAsync(Adult adultToAdd)
        {
            int max = _adults.Max(adultToAdd => adultToAdd.Id);

            adultToAdd.Id = ++max;
            _adults.Add(adultToAdd);
            WriteToFile();
        }
Exemple #13
0
 public override void Die()
 {
     if (!IsGrown)
     {
         Adult.Delete();
     }
     base.Die();
 }
        public void Logout()
        {
            cachedUser = null;
            var user = new ClaimsPrincipal(new ClaimsIdentity());

            jsRuntime.InvokeVoidAsync("sessionStorage.setItem", "currentUser", "");
            NotifyAuthenticationStateChanged(Task.FromResult <AuthenticationState>(new AuthenticationState(user)));
        }
Exemple #15
0
        public async Task <Adult> AddAdultAsync(Adult adult)
        {
            EntityEntry <Adult> newAdult = await cxt.Adults.AddAsync(adult);

            await cxt.SaveChangesAsync();

            return(newAdult.Entity);
        }
Exemple #16
0
        public async Task <ActionResult <Adult> > PutAdult(Adult adult)
        {
            _context.Adults.Add(adult);
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetAdult", new { id = adult.Id }, adult);
            return(CreatedAtAction(nameof(GetAdult), new { id = adult.Id }, adult));
        }
Exemple #17
0
        public async Task <Adult> AddAdultAsync(Adult adult, string address)
        {
            Family fam = file.Families.FirstOrDefault(t => t.Address().Equals(address));

            fam.Adults.Add(adult);
            file.SaveChanges();
            return(adult);
        }
Exemple #18
0
        public async Task RemoveAdultsAsync(int personId)
        {
            Adult toRemove = adults.First(t => t.Id == personId);

            adults.Remove(toRemove);
            WriteToFile();
            SaveChanges();
        }
Exemple #19
0
        public void addAdult(Adult adult)
        {
            int id = addId();

            adult.Id = id;
            _fileContext.Adults.Insert(id, adult);
            _fileContext.SaveChanges();
        }
        public void AddAdult(Adult adult)
        {
            var max = adults.Max(adult => adult.Id);

            adult.Id = ++max;
            adults.Add(adult);
            WritePersonsToFile();
        }
Exemple #21
0
 public async Task AddAdultAsync(Adult adult)
 {
     string      adultAsJson = JsonSerializer.Serialize(adult);
     HttpContent content     = new StringContent(adultAsJson,
                                                 Encoding.UTF8,
                                                 "application/json");
     await client.PutAsync(uri1 + "/Adults", content);
 }
Exemple #22
0
        public async Task UpdateAsync(Adult person)
        {
            string              personSerialized = JsonSerializer.Serialize(person);
            StringContent       content          = new StringContent(personSerialized, Encoding.UTF8, "application/json");
            HttpResponseMessage response         = await client.PutAsync("https://localhost:5004/adults", content);

            Console.WriteLine(response.ToString());
        }
Exemple #23
0
 public async Task UpdateAdultAsync(Adult adult)
 {
     string      adultAsJson = JsonSerializer.Serialize(adult);
     HttpContent content     = new StringContent(adultAsJson,
                                                 Encoding.UTF8,
                                                 "application/json");
     await client.PostAsync($"{uri1}/Adults/{adult.Id}", content);
 }
Exemple #24
0
        public void AddAdult(Adult adult)
        {
            int max = adults.Max(adult => adult.Id);

            adult.Id = (++max);
            adults.Add(adult);
            SaveChanges();
        }
Exemple #25
0
        public void Update(Adult adult)
        {
            Adult toUpdate = Adults.First(t => t.Id == adult.Id);

            toUpdate.IsCompleted = adult.IsCompleted;
            toUpdate.Id          = adult.Id;
            SaveChanges(adult);
        }
Exemple #26
0
        public async Task RemoveAdultAsync(Adult adult, string address)
        {
            /*Family fam = file.Families.FirstOrDefault(t => t.Address().Equals(address));
             * fam.Adults.Remove(adult);
             * file.SaveChanges();*/

            await client.DeleteAsync($"{uri}/adults/{address}/{adult.CPRNumber}");
        }
Exemple #27
0
        public async Task <Job> AddJobAsync(Job job, string address, int id)
        {
            Adult adu = await GetAdultAsync(id, address);

            adu.JobTitle = job;
            file.SaveChanges();
            return(job);
        }
        public void RemoveAdult(int adultId)
        {
            Adult adultToRemove = adults.First(a => a.Id == adultId);

            adults.Remove(adultToRemove);
            fileContext.Adults.Remove(adultToRemove);
            WriteAdultsToFile();
        }
        public void AddAdult(Adult adult)
        {
            int max = Adults.Max(adult => adult.Id);

            adult.Id = (++max);
            Adults.Add(adult);
            WriteAdultsToFile();
        }
Exemple #30
0
 public async Task UpdateAdultsAsync(Adult adult)
 {
     string      todoAsJson = JsonSerializer.Serialize(adult);
     HttpContent content    = new StringContent(todoAsJson,
                                                Encoding.UTF8,
                                                "application/json");
     await client.PatchAsync($"http://dnp.metamate.me/Adults", content);
 }
Exemple #31
0
        public async Task AddAdultAsync(Adult adult)
        {
            string              adultJson = JsonSerializer.Serialize(adult);
            HttpContent         content   = new StringContent(adultJson, Encoding.UTF8, "application/json");
            HttpResponseMessage response  = await client.PutAsync(uri + "/Adults", content);

            Console.WriteLine(response.ToString());
        }
        public ActionResult Create(Adult adult)
        {
            if (ModelState.IsValid)
            {
                adult.Id = Guid.NewGuid();
                db.Adults.Add(adult);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(adult);
        }
 public ActionResult AdultSignup(string adultMode)
 {
     // Set defaults
     Adult newAdult = new Adult();
     if (adultMode == "Mentor")
     {
         newAdult.IsMentor = true;
     }
     else
     {
         newAdult.IsParent = true;
     }
     ViewBag.AdultMode = adultMode;
     return View("Adult", newAdult);
 }
Exemple #34
0
        public static void Main()
        {
            List<Person> persons = new List<Person>();
            persons.Add(new Adult("Ivan",Gender.male));
            persons.Add(new Children("IvanJunior", Gender.male));

            foreach (var person in persons)
            {
                Console.WriteLine(person.ToString());
            }
            Console.WriteLine();
            var Pesho = new Adult("Pesho", Gender.male);
            var PeshoJunior = new Children("PeshoJunior", Gender.male);
            var PeshoToy = new Toy() { Color = "Green", Size = 10 };
            Console.WriteLine(PeshoToy.ToString());
            Console.WriteLine();
            Console.WriteLine(Pesho.ToString());
            Console.WriteLine();
            Console.WriteLine(PeshoJunior.ToString());
            Console.WriteLine();

            Pesho.Childrens.Add(PeshoJunior);
            PeshoJunior.Toys.Add(PeshoToy);
            Pesho.isBooring = true;

            Console.WriteLine(Pesho.ToString());
            foreach (var child in Pesho.Childrens)
            {
                Console.WriteLine(child.ToString());
                foreach (var toy in child.Toys)
                {
                    Console.WriteLine(toy.ToString());
                }
            }
            Console.WriteLine();
            if (Pesho.isBooring)
            {
                Console.WriteLine("Golqma skukaa brat..!");
            }
        }
 public ActionResult Edit(Adult adult)
 {
     if (ModelState.IsValid)
     {
         db.Entry(adult).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(adult);
 }
 public ActionResult ParentSave(Adult adultChanges)
 {
     return AdultSave(adultChanges, "Parent");
 }
 public ActionResult MentorSave(Adult adultChanges)
 {
     return AdultSave(adultChanges, "Mentor");
 }
 public ActionResult AdultSave(Adult adultChanges)
 {
     return AdultSave(adultChanges, "Adult");
 }
        private ActionResult AdultSave(Adult adultChanges, string adultMode)
        {
            bool newAdult = false;
            if (ModelState.IsValid)
            {
                Adult adult = null;

                if (adultChanges.Id != null)
                {
                    adult = db.Adults.Find(adultChanges.Id);
                }

                // New Adult
                if (adult == null)
                {
                    adult = new Adult();
                    adult.Id = Guid.NewGuid();
                    db.Adults.Add(adult);
                    newAdult = true;
                }

                // Save changes
                adult.FirstName = TrimNullableString(adultChanges.FirstName);
                adult.LastName = TrimNullableString(adultChanges.LastName);
                adult.Email = TrimNullableString(adultChanges.Email);
                adult.Phone = TrimNullableString(adultChanges.Phone);
                adult.IsParent = adultChanges.IsParent;
                adult.IsMentor = adultChanges.IsMentor;
                adult.GithubLogin = TrimNullableString(adultChanges.GithubLogin);
                adult.XboxGamertag = TrimNullableString(adultChanges.XboxGamertag);
                adult.ScratchName = TrimNullableString(adultChanges.ScratchName);
                adult.Login = TrimNullableString(adultChanges.Login);

                // Password change
                if (string.IsNullOrEmpty(adultChanges.NewPassword) == false)
                {
                    adult.PasswordHash = db.GeneratePasswordHash(adultChanges.NewPassword);
                }
                db.SaveChanges();
                if (adultMode == "Parent" && newAdult)
                {
                    return RedirectClient("/Mentor/ParentKids/" + adult.Id.ToString("N"));
                }
            }
            return RedirectClient("/Mentor/" + adultMode + "s");
        }