public async Task <ActionResult <PastryFilling> > PostPastryFilling(PastryFilling pastryFilling)
        {
            PastryFillingRepository.Create(pastryFilling);
            await PastryFillingRepository.SaveChangesAsync();

            return(CreatedAtAction("GetPastryFilling", new { id = pastryFilling.Id }, pastryFilling));
        }
        public async Task <IActionResult> PutPastryFilling(int id, PastryFilling pastryFilling)
        {
            if (id != pastryFilling.Id)
            {
                return(BadRequest());
            }

            PastryFillingRepository.Update(pastryFilling);

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

            return(NoContent());
        }
Ejemplo n.º 3
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();
        }
        public async Task <ActionResult <PastryFilling> > GetPastryFilling(int id)
        {
            PastryFilling pastryFilling = await PastryFillingRepository.GetPastryFillingsByIdAsync(id);

            if (pastryFilling == null)
            {
                return(NotFound());
            }

            return(pastryFilling);
        }
        public async Task <ActionResult <PastryFilling> > DeletePastryFilling(int id)
        {
            PastryFilling pastryFilling = await PastryFillingRepository.GetPastryFillingsByIdAsync(id);

            if (pastryFilling == null)
            {
                return(NotFound());
            }

            PastryFillingRepository.Delete(pastryFilling);
            await PastryFillingRepository.SaveChangesAsync();

            return(pastryFilling);
        }
Ejemplo n.º 6
0
 public async ValueTask <IEnumerable <PastryWithStock> > GetPastriesByPastryFillingGroupForStockAsync(PastryFilling pastryFilling)
 {
     return(await Get(p => p.PastryFilling.Id == pastryFilling.Id).IncludeFillingAndType().GroupPastriesByPastryStockCompositeKeyAsync(Ctx.PastryType));
 }
Ejemplo n.º 7
0
 public async ValueTask <IEnumerable <Pastry> > GetPastriesByPastryFillingAsync(PastryFilling pastryFilling)
 {
     return(await Get(p => p.PastryFilling.Id == pastryFilling.Id).IncludeFillingAndType().ToListAsync());
 }