示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,AuthorId,Title,CreatedOn,IsShared")] BrainstormBoard brainstormBoard)
        {
            if (id != brainstormBoard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(brainstormBoard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrainstormBoardExists(brainstormBoard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(brainstormBoard));
        }
        public async Task <IActionResult> DeleteBoard(int id)
        {
            try
            {
                BrainstormBoard existingBoard = _context.BrainstormBoards.Find(id);
                if (existingBoard == null)
                {
                    return(Json(new { Success = false }));
                }

                //Delete sticky notes for the board
                var notes = _context.StickyNotes.Where(x => x.BoardId == id);
                foreach (StickyNote note in notes)
                {
                    _context.StickyNotes.Remove(note);
                }
                //await _context.SaveChangesAsync();
                _context.SaveChanges();

                //Delete the board
                _context.BrainstormBoards.Remove(existingBoard);
                _context.SaveChanges();
            }
            catch
            {
                return(Json(new { Success = false }));
            }
            return(Json(new { Success = true }));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Id,AuthorId,Title,CreatedOn,IsShared")] BrainstormBoard brainstormBoard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brainstormBoard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brainstormBoard));
        }
        public async Task <IActionResult> UpdateBoard(UpdateBrainstorm brainstorm)
        {
            try
            {
                BrainstormBoard existingBoard = _context.BrainstormBoards.Find(brainstorm.Id);
                existingBoard.Title = brainstorm.Title;
                var notes = _context.StickyNotes.Where(x => x.BoardId == brainstorm.Id);

                foreach (StickyNote note in notes)
                {
                    _context.StickyNotes.Remove(note);
                }


                if (brainstorm.StickyNotes != null)
                {
                    //create new notes
                    foreach (AddStickyNote stickyNote in brainstorm.StickyNotes)
                    {
                        StickyNote newnote = new StickyNote
                        {
                            BoardId      = brainstorm.Id,
                            Content      = stickyNote.Content,
                            Color        = stickyNote.Color,
                            PositionLeft = stickyNote.Positions.Left,
                            PositionTop  = stickyNote.Positions.Top
                        };
                        _context.StickyNotes.Add(newnote);
                        await _context.SaveChangesAsync();
                    }
                }

                _context.SaveChanges();
            }
            catch
            {
                return(Json(new { Success = false }));
            }
            return(Json(new { }));
        }
        public async Task <IActionResult> CreateBoard(AddBrainstorm brainstorm)
        {
            try
            {
                BrainstormBoard newboard = new BrainstormBoard
                {
                    AuthorId  = User.Identity.Name,
                    Title     = brainstorm.Title,
                    CreatedOn = DateTime.Now
                };
                await _context.BrainstormBoards.AddAsync(newboard);

                await _context.SaveChangesAsync();

                if (brainstorm.StickyNotes != null)
                {
                    //create new notes
                    foreach (AddStickyNote stickyNote in brainstorm.StickyNotes)
                    {
                        StickyNote newnote = new StickyNote
                        {
                            BoardId      = newboard.Id,
                            Content      = stickyNote.Content,
                            Color        = stickyNote.Color,
                            PositionLeft = stickyNote.Positions.Left,
                            PositionTop  = stickyNote.Positions.Top
                        };
                        _context.StickyNotes.Add(newnote);
                    }
                }

                _context.SaveChanges();
                return(Json(new { Success = true }));
            }
            catch
            {
                return(Json(new { Success = false }));
            }
        }