示例#1
0
        public async Task <IActionResult> AddLeaf([FromBody] AddLeafModel model)
        {
            var leaf = await _leafService.AddLeafAsync(model);

            if (leaf == null)
            {
                return(NotFound());
            }

            var mapperModel = _mapper.Map <LeafModel>(leaf);

            return(Ok(mapperModel));
        }
示例#2
0
        public async Task <Leaf> AddLeafAsync(AddLeafModel model)
        {
            var parent = await _context.Nodes.SingleOrDefaultAsync(x => x.NodeId == model.ParentNodeId);

            if (parent == null)
            {
                return(null);
            }

            Leaf leaf = new Leaf()
            {
                Name = model.Name, ParentNode = parent
            };

            parent.SubLeaves.Add(leaf);

            await _context.SaveChangesAsync();

            return(leaf);
        }