Exemple #1
0
        public static Dessert ReadValues(DataGridView gridView, TextBox tbDessetName, bool saveInDB)
        {
            if (gridView == null || gridView.RowCount - 1 <= 0)
            {
                return(null);
            }

            Dessert dessert = new Dessert();

            using (var db = new PastryShopDbContext())
            {
                string dessertName = tbDessetName.Text;
                if (dessertName == null || dessertName.Trim().Length == 0)
                {
                    return(null);
                }
                dessert.Name = dessertName.Trim();

                int rowCount = gridView.RowCount - 1;
                for (int i = 0; i < rowCount; i++)
                {
                    var productDetailId = gridView.Rows[i].Cells["Product"].Value;
                    var quantity        = gridView.Rows[i].Cells["Quantity"].Value;

                    bool areAllRequiredFieldsFilled = productDetailId != null && quantity != null;

                    if (areAllRequiredFieldsFilled)
                    {
                        RecipeLine line = new RecipeLine();
                        line.Dessert       = dessert;
                        line.Quantity      = Convert.ToDouble(quantity);
                        line.ProductDetail = db.ProductDetails.First(p => p.Id == (int)productDetailId);
                        dessert.RecipeLines.Add(line);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (saveInDB)
                {
                    db.Desserts.Add(dessert);
                    db.SaveChanges();
                }
            }
            return(dessert);
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RecipeLine = await _context.RecipeLines.FindAsync(id);

            if (RecipeLine != null)
            {
                _context.RecipeLines.Remove(RecipeLine);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/AssemblyRecipes/Details", new { id = RecipeLine.AssemblyRecipeId }));
        }
Exemple #3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RecipeLine = await _context.RecipeLines
                         .Include(r => r.AssemblyRecipe)
                         .Include(r => r.Item).FirstOrDefaultAsync(m => m.RecipeLineId == id);

            if (RecipeLine == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RecipeLine = await _context.RecipeLines
                         .Include(r => r.AssemblyRecipe)
                         .Include(r => r.Item).FirstOrDefaultAsync(m => m.RecipeLineId == id);

            if (RecipeLine == null)
            {
                return(NotFound());
            }
            ViewData["AssemblyRecipeId"] = new SelectList(_context.AssemblyRecipes, "AssemblyRecipeId", "AssemblyRecipeId");
            ViewData["ItemId"]           = new SelectList(_context.Items, "ItemId", "ItemName");
            return(Page());
        }