Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] PastryDough pastryDough)
        {
            PastryDoughRepository.Create(pastryDough);
            await PastryDoughRepository.SaveChangesAsync();

            return(CreatedAtAction("GetPastryDoughById", new { id = pastryDough.Id }, pastryDough));
        }
Exemplo n.º 2
0
        //randomly generate 200 pastries
        private void CreatePastries()
        {
            Random        rnd      = new Random();
            List <Pastry> pastries = new List <Pastry>();

            for (int i = 0; i < 200; ++i)
            {
                //get a random filling
                PastryFilling pastryFilling = Ctx.PastryFilling.Skip(rnd.Next(0, Ctx.PastryFilling.Count())).Take(1).First();
                //get a random pastry type
                PastryDough pastryType = Ctx.PastryDough.Skip(rnd.Next(0, Ctx.PastryDough.Count())).Take(1).First();
                pastries.Add
                (
                    new Pastry
                {
                    Id            = 0,
                    Description   = $"A decadent pastry created with {pastryType.Name} dough, stuffed with {pastryFilling.Name}, and cooked to perfection!",
                    Name          = $"{pastryType.Name} {pastryFilling.Name} Pastry",
                    PastryFilling = pastryFilling,
                    PastryDough   = pastryType,
                }
                );
            }
            Ctx.Pastry.AddRange(pastries);
            Ctx.SaveChanges();
        }
Exemplo n.º 3
0
        public async Task <ActionResult <PastryDough> > GetPastryDoughById(int id)
        {
            PastryDough pastryDough = await PastryDoughRepository.GetPastryDoughByIdAsync(id);

            if (pastryDough == null)
            {
                return(NotFound());
            }
            return(pastryDough);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Delete(int id)
        {
            PastryDough pastryDough = await PastryDoughRepository.GetPastryDoughByIdAsync(id);

            if (pastryDough == null)
            {
                return(NotFound());
            }
            PastryDoughRepository.Delete(pastryDough);
            await PastryDoughRepository.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 5
0
 public async Task <ActionResult <PastryDough> > Put(int id, [FromBody] PastryDough pastryDough)
 {
     if (id != pastryDough.Id)
     {
         return(BadRequest());
     }
     PastryDoughRepository.Update(pastryDough);
     try
     {
         await PastryDoughRepository.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!await PastryDoughExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }
Exemplo n.º 6
0
 public async ValueTask <IEnumerable <PastryWithStock> > GetPastriesByPastryTypeGroupForStockAsync(PastryDough pastryType)
 {
     return(await Get(p => p.PastryDough.Id == pastryType.Id).IncludeFillingAndType().GroupPastriesByPastryStockCompositeKeyAsync(Ctx.PastryType));
 }
Exemplo n.º 7
0
 public async ValueTask <IEnumerable <Pastry> > GetPastriesByPastryTypeAsync(PastryDough pastryType)
 {
     return(await Get(p => p.PastryDough.Id == pastryType.Id).IncludeFillingAndType().ToListAsync());
 }