Esempio n. 1
0
        public ActionResult <List <view_node> > PatchNodes([FromRoute] Int32 boardId, [FromBody] dynamic requestBody)
        {
            string authorization = Request.Headers["Authorization"];
            string token         = authorization.Substring("Bearer ".Length).Trim();

            Int16 userId = _userService.GetUserId(token);
            board board  = _context.board.FirstOrDefault(x => x.id == boardId && x.owner_id == userId && x.deleted_at == null);

            if (board == null)
            {
                throw new MindnoteException("嗚喔! 分類已經被刪除,無法瀏覽", HttpStatusCode.NotFound);
            }
            var          nodes   = ((JArray)requestBody.nodes).ToList();
            List <Int32> nodeIds = new List <Int32>();

            for (int i = 0; i < nodes.Count; i++)
            {
                dynamic nodeFromRequest = nodes[i];
                node    existedNode     = new node {
                    id = nodeFromRequest.id
                };
                _context.Attach <node>(existedNode);
                existedNode.x          = nodeFromRequest.x;
                existedNode.y          = nodeFromRequest.y;
                existedNode.updated_at = DateTime.Now;
                nodeIds.Add((Int32)nodeFromRequest.id);
            }
            _context.SaveChanges();
            return(_contextForView.view_node.Where(x => x.board_id == board.id && x.deleted_at == null && nodeIds.Contains(x.id)).ToList());
        }
Esempio n. 2
0
        public ActionResult <board> PatchBoard([FromRoute] Int32 boardId, [FromBody] dynamic requestBody)
        {
            string authorization = Request.Headers["Authorization"];
            string token         = authorization.Substring("Bearer ".Length).Trim();
            Int16  userId        = _userService.GetUserId(token);

            board board = _context.board.FirstOrDefault(x => x.id == boardId && x.owner_id == userId && x.deleted_at == null);

            if (board == null)
            {
                throw new MindnoteException("嗚喔! 分類已經被刪除,無法瀏覽", HttpStatusCode.NotFound);
            }

            if (requestBody.is_public != null)
            {
                board.is_public = requestBody.is_public;
            }

            if (requestBody.title != null)
            {
                board.title = requestBody.title;
            }
            if (requestBody.uniquename != null)
            {
                board.uniquename = requestBody.uniquename;
            }
            if (requestBody.image_id != null && board.image_id != (int)requestBody.image_id)
            {
                if (board.image_id != null)
                {
                    image existedImage = new image {
                        id = (board.image_id ?? -1)
                    };
                    _context.Attach <image>(existedImage);
                    existedImage.deleted_at = DateTime.Now;
                }
                board.image_id = requestBody.image_id;
            }
            board.updated_at = DateTime.Now;
            _context.SaveChanges();
            return(board);
        }