Exemplo n.º 1
0
        public async Task <IActionResult> PutZooInfo(int id, ZooInfo zooInfo)
        {
            if (id != zooInfo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(zooInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ZooInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Details")] ZooInfo zooInfo)
        {
            if (id != zooInfo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(zooInfo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ZooInfoExists(zooInfo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(zooInfo));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Details")] ZooInfo zooInfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(zooInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(zooInfo));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Dispaly the animals at each zoo location
 /// </summary>
 public void DisplayZooInfo()
 {
     foreach (var item in ZooInfo.OrderBy(i => i.Key))
     {
         Console.WriteLine($"{item.Key} Zoo has the following animal:");
         for (int i = 0; i < item.Value.Count; i++)
         {
             Animal a = new Animal();
             a.DisplayZooInfo(item.Value[i]);
         }
         Console.WriteLine();
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Calculate the average height of the zoo location
 /// </summary>
 public void AverageWeights()
 {
     foreach (var item in ZooInfo.OrderBy(i => i.Key))
     {
         double avg   = 0;
         int    count = 0;
         AverageWeight = 0;
         for (int i = 0; i < item.Value.Count; i++)
         {
             Animal a = new Animal();
             avg            = a.CalculateAverageWeight(item.Value[i]);
             AverageWeight += avg;
             count++;
         }
         AverageWeight = AverageWeight / count;
         Console.WriteLine($"{item.Key} Zoo has an average weight of {AverageWeight.ToString("N2")} pounds.");
         Console.WriteLine();
     }
 }
Exemplo n.º 6
0
        public async Task <ActionResult <ZooInfo> > PostZooInfo(ZooInfo zooInfo)
        {
            _context.ZooInfo.Add(zooInfo);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ZooInfoExists(zooInfo.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetZooInfo", new { id = zooInfo.Id }, zooInfo));
        }