Пример #1
0
        public async Task <Adult> AddAdultAsync(Adult adult)
        {
            int max = adults.Max(adult => adult.Id);

            adult.Id = ++max;
            adults.Add(adult);
            WriteAdultsToFile();
            return(adult);
        }
Пример #2
0
        public async Task RemoveAdultAsync(int adultId)
        {
            Adult toDelete = ctx.Adults.FirstOrDefault(t => t.Id == adultId);

            if (toDelete != null)
            {
                ctx.Adults.Remove(toDelete);
                await ctx.SaveChangesAsync();
            }
        }
Пример #3
0
        public async Task <Adult> UpdateAdultAsync(Adult adult)
        {
            Adult toUpdate = adults.FirstOrDefault(t => t.Id == adult.Id);

            if (toUpdate == null)
            {
                throw new Exception($"Did not find adult with id: {adult.Id}");
            }
            WriteAdultsToFile();
            return(toUpdate);
        }
Пример #4
0
        public async Task <Adult> UpdateAdultAsync(Adult adult)
        {
            try {
                Adult toUpdate = await ctx.Adults.FirstAsync(t => t.Id == adult.Id);

                ctx.Update(toUpdate);
                await ctx.SaveChangesAsync();

                return(toUpdate);
            }
            catch (Exception e) {
                throw new Exception($"Did not find adult with given id: {adult.Id}");
            }
        }
Пример #5
0
        public async Task <Adult> UpdateAdultAsync(Adult adult)
        {
            Adult toUpdate = adults.First(t => t.Id == adult.Id);

            toUpdate.JobTitle  = adult.JobTitle;
            toUpdate.Id        = adult.Id;
            toUpdate.FirstName = adult.FirstName;
            toUpdate.LastName  = adult.LastName;
            toUpdate.HairColor = adult.HairColor;
            toUpdate.EyeColor  = adult.EyeColor;
            toUpdate.Age       = adult.Age;
            toUpdate.Weight    = adult.Weight;
            toUpdate.Height    = adult.Height;
            toUpdate.Sex       = adult.Sex;
            WriteAdultsToFile();
            return(toUpdate);
        }
Пример #6
0
 public void Update(Adult toUpdate)
 {
     JobTitle = toUpdate.JobTitle;
     base.Update(toUpdate);
 }