public async Task <bool> ChangesCheckedAndSavedSuccessfully()
        {
            ModelChecker.Check(this.ModelState);

            TempData.CorrectEmptyArrays <int>();

            if (CategoryTypeSelection != null)
            {
                Category.CategoryType = _context.CategoryTypes.FirstOrDefault(x => x.Id == CategoryTypeSelection);
            }
            else
            {
                Category.CategoryType = null;
            }


            TempData.Clear();

            return(await SaveChanges.SavedSuccessfully(this._context, this._context.Categories, this.Category));
        }
Exemple #2
0
        public async Task <bool> ChangesCheckedAndSavedSuccessfully()
        {
            ModelChecker.Check(this.ModelState);

            TempData.CorrectEmptyArrays <int>();

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

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

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

            TempData.Clear();

            return(await SaveChanges.SavedSuccessfully(this._context, this._context.Bricks, this.Brick));

            /*
             * _context.Attach(Brick).State = EntityState.Modified;
             *
             * try
             * {
             *  await _context.SaveChangesAsync();
             * }
             * catch (DbUpdateConcurrencyException)
             * {
             *  if (!_context.Bricks.Any(e => e.Id == Brick.Id))
             *  {
             *      return false;
             *  }
             *  else
             *  {
             *      throw;
             *  }
             *
             * }
             * return true;*/
        }