public async Task <IActionResult> PutPointsTypeAll(Guid id, PointsTypeAll pointsTypeAll)
        {
            if (id != pointsTypeAll.PtId)
            {
                return(NotFound());
            }

            _context.Entry(pointsTypeAll.PointsType).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PointsTypeExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
        public async Task <ActionResult <PointsTypeAll> > GetPointsTypeAllDetail(Guid id)
        {
            PointsType pt = await _context.PointsType.FindAsync(id);

            PointsTypeAll ptAll = new PointsTypeAll();

            ptAll.PtId       = pt.PtId;
            ptAll.PointsType = pt;
            ptAll.PtAttr     = await _context.PointsTypeAttr.Where(p => p.PtId == pt.PtId).ToListAsync();

            return(ptAll);
        }
        public async Task <ActionResult <PointsTypeAll> > DeletePointsTypeAll(Guid id)
        {
            PointsType pt = await _context.PointsType.FindAsync(id);

            PointsTypeAll ptAll = new PointsTypeAll();

            ptAll.PtId       = pt.PtId;
            ptAll.PointsType = pt;
            ptAll.PtAttr     = await _context.PointsTypeAttr.Where(p => p.PtId == pt.PtId).ToListAsync();

            if (ptAll.PtId == null)
            {
                return(NotFound());
            }
            return(ptAll);
        }
        public async Task <ActionResult <PointsTypeAll> > PostPointsTypeAll([FromBody] PointsTypeAll pointsTypeAll)
        {
            pointsTypeAll.PtId            = Guid.NewGuid();
            pointsTypeAll.PointsType.PtId = pointsTypeAll.PtId;

            if (pointsTypeAll.PointsType.PtId != pointsTypeAll.PtId)
            {
                return(BadRequest());
            }

            _context.PointsType.Add(pointsTypeAll.PointsType);
            await _context.SaveChangesAsync();

            foreach (PointsTypeAttr item in pointsTypeAll.PtAttr)
            {
                item.PtId = pointsTypeAll.PtId;
                _context.PointsTypeAttr.Add(item);
                await _context.SaveChangesAsync();
            }
            return(CreatedAtAction("GetPointsTypeAllDetail", new { id = pointsTypeAll.PtId }, pointsTypeAll));
        }
        public async Task <ActionResult <IEnumerable <PointsTypeAll> > > GetPointsTypeAll(int skip, int take)
        {
            List <PointsType> pt = await _context.PointsType.Skip(skip).Take(take).ToListAsync();

            List <PointsTypeAll> ptAll = new List <PointsTypeAll>();

            foreach (PointsType data in pt)
            {
                PointsTypeAll ptAllElement = new PointsTypeAll();
                ptAllElement.PtId       = data.PtId;
                ptAllElement.PointsType = data;

                List <PointsTypeAttr> ptAttrList = new List <PointsTypeAttr>();
                ptAttrList = await _context.PointsTypeAttr.Where(pt => pt.PtId == data.PtId).ToListAsync();

                //data.po
                ptAllElement.PtAttr = ptAttrList;

                ptAll.Add(ptAllElement);
            }
            return(ptAll);
        }