Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(CategoryType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryTypeExists(CategoryType.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Categories.Add(Category);
            await _context.SaveChangesAsync();

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

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

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

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

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

            if (CategoryType != null)
            {
                _context.CategoryTypes.Remove(CategoryType);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 5
0
        public async Task <bool> CheckAndSave()
        {
            if (!ModelState.IsValid)
            {
                var err = ModelState.Select(x => x.Value.Errors)
                          .Where(y => y.Count > 0)
                          .ToList();
                throw new Exception($"Model is invalid, ModelState has {err.Count} errors. Try turning the page off and on again.");
            }



            TempData.CorrectEmptyArrays <int>();

            await _context.BrickCategories.UpdateFromSelectList
                (Brick, TempData[nameof(categorySelectionOrig)] as int[], CategorySelect);

            await _context.BrickToBrick.UpdateFromSelectList
                (Brick, TempData[nameof(childrenSelectOrig)] as int[], ChildrenSelect);

            await _context.BrickToBrick.UpdateFromSelectList
                (Brick, TempData[nameof(parentsSelectOrig)] as int[], ParentsSelect, Relationship.Reversed);

            TempData.Clear();

            _context.Attach(Brick).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrickExists(Brick.Id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }