Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CategoryType = await _context.CategoryTypes.FindAsync(id);

            if (CategoryType != null)
            {
                var categoriesToClean = _context.Categories.Where(cat => cat.CategoryType.Equals(this.CategoryType)).AsEnumerable();


                foreach (var category in categoriesToClean)
                {
                    category.CategoryType = null;
                }

                _context.CategoryTypes.Remove(CategoryType);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Brick = await _context.Bricks.FindAsync(id);

            if (Brick != null)
            {
                foreach (var joinTable in _context.BrickToBrick)
                {
                    if (joinTable.BrickId == this.Brick.Id || joinTable.ChildId == this.Brick.Id)
                    {
                        _context.BrickToBrick.Remove(joinTable);
                    }
                }


                foreach (var joinTable in _context.BrickCategories)
                {
                    if (joinTable.BrickId == this.Brick.Id)
                    {
                        _context.BrickCategories.Remove(joinTable);
                    }
                }


                _context.Bricks.Remove(Brick);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Category = await _context.Categories.FindAsync(id);

            if (Category != null)
            {
                foreach (var categoryType in _context.CategoryTypes.Include(x => x.Categories))
                {
                    if (categoryType.Categories.Contains(this.Category))
                    {
                        categoryType.Categories.Remove(this.Category);
                    }
                }


                foreach (var brickCategory in _context.BrickCategories)
                {
                    if (brickCategory.CategoryId.Equals(this.Category.Id))
                    {
                        _context.BrickCategories.Remove(brickCategory);
                    }
                }

                _context.Categories.Remove(Category);

                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 4
0
        public async Task <bool> CheckAndSave()
        {
            if (!ModelState.IsValid)
            {
                return(false);
            }

            _context.Bricks.Add(Brick);
            await _context.SaveChangesAsync();

            return(true);
        }