private int GetRankRole(Sys_Dm_GroupRole sys_Dm_GroupRole)
 {
     if (sys_Dm_GroupRole.IsAdminCom == true)
     {
         return(1);
     }
     else if (sys_Dm_GroupRole.IsAdminDep == true)
     {
         return(2);
     }
     else if (sys_Dm_GroupRole.IsAdminNest == true)
     {
         return(3);
     }
     else
     {
         return(4);
     }
 }
        public async Task <IActionResult> PutSys_Dm_GroupRole(int id, Sys_Dm_GroupRole sys_Dm_Group)
        {
            if (id != sys_Dm_Group.Id)
            {
                return(new ObjectResult(new { error = 1 }));
            }
            sys_Dm_Group.RankRole = GetRankRole(sys_Dm_Group);
            _context.Entry(sys_Dm_Group).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(new ObjectResult(new { error = 1 }));
            }

            return(new ObjectResult(new { error = 0 }));
        }
        public async Task <ActionResult <IEnumerable <Sys_Dm_GroupRole> > > r1AddDataGroupRole(Sys_Dm_GroupRole sys_Dm_Group)
        {
            try
            {
                RequestToken token = CommonData.GetDataFromToken(User);
                sys_Dm_Group.UserCreateId = token.UserID;
                sys_Dm_Group.CreateDate   = DateTime.Now;
                sys_Dm_Group.RankRole     = GetRankRole(sys_Dm_Group);
                _context.Sys_Dm_GroupRole.Add(sys_Dm_Group);
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0 }));
            }
            catch (Exception)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }
        public async Task <ActionResult <IEnumerable <Sys_Dm_GroupRole> > > r1AddDataGroupRole(Sys_Dm_GroupRole sys_Dm_Group)
        {
            try
            {
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                sys_Dm_Group.UserCreateId = userId;
                sys_Dm_Group.CreateDate   = DateTime.Now;
                sys_Dm_Group.RankRole     = GetRankRole(sys_Dm_Group);
                _context.Sys_Dm_GroupRole.Add(sys_Dm_Group);
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0 }));
            }
            catch (Exception)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }