Esempio n. 1
0
        public bool SaveGroupRole(GroupRoleDTO groupRole, string connectionString)
        {
            int savedCount = 0;

            try
            {
                if (!string.IsNullOrEmpty(groupRole.pGroupRoleName))
                {
                    savedCount = NPGSqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, "insert into tblmstgrouprolesconfig(rolename,statusid,createdby,createddate) values('" + ManageQuote(groupRole.pGroupRoleName) + "'," + Convert.ToInt32(Status.Active) + "," + groupRole.pCreatedby + ",current_timestamp);");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Dispose();
                    con.Close();
                    con.ClearPool();
                }
            }
            return(savedCount > 0 ? true : false);
        }
Esempio n. 2
0
        public async Task <List <GroupRoleDTO> > getGroupRoles(string connectionString)
        {
            await Task.Run(() =>
            {
                GroupRoleslist = new List <GroupRoleDTO>();
                try
                {
                    using (NpgsqlDataReader dr = NPGSqlHelper.ExecuteReader(connectionString, CommandType.Text, "select grouproleid,rolename from tblmstgrouprolesconfig where statusid=" + Convert.ToInt32(Status.Active) + " order by rolename desc;"))
                    {
                        while (dr.Read())
                        {
                            GroupRoleDTO objGroupRolesDetails   = new GroupRoleDTO();
                            objGroupRolesDetails.pGroupRoleId   = Convert.ToInt64(dr["grouproleid"]);
                            objGroupRolesDetails.pGroupRoleName = Convert.ToString(dr["rolename"]);
                            GroupRoleslist.Add(objGroupRolesDetails);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            });

            return(GroupRoleslist);
        }
Esempio n. 3
0
        public IActionResult SaveGroupRole([FromBody] GroupRoleDTO groupRole)
        {
            try
            {
                if (!string.IsNullOrEmpty(groupRole.pGroupRoleName))
                {
                    if (_groupcreationDAL.SaveGroupRole(groupRole, Con))
                    {
                        return(Ok(true));
                    }
                    else
                    {
                        return(StatusCode((int)HttpStatusCode.NotModified));
                    }
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.NotAcceptable));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));

                throw ex;
            }
        }
        public async Task <IHttpActionResult> PostGroupRoleMap(GroupRoleDTO groupRoleDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            Guid id            = groupRoleDto.Id;
            int  EntityStateId = 0;

            if (id == Guid.Empty)
            {
                id = Guid.NewGuid();
                // user.Id = id;
                EntityStateId = (int)EntityState.Added;
            }
            else
            {
                EntityStateId = (int)EntityState.Modified;
            }

            int result = await groupRoleService.Save(groupRoleDto, id, EntityStateId);

            groupRoleDto.Id = id;
            if (result == -1)
            {
                return(StatusCode(HttpStatusCode.NotModified));
            }
            else if (result == 0)
            {
                return(StatusCode(HttpStatusCode.NotAcceptable));
            }
            return(Ok(id));
        }
Esempio n. 5
0
        public async Task <UserRolesDTO> GetRolesAsync(string userId)
        {
            var entity = await _userManager.FindByIdAsync(userId);

            if (entity == null)
            {
                throw new ArgumentException("User not exists");
            }

            var claims = await _userManager.GetClaimsAsync(entity);

            var givenName  = claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.GivenName)?.Value;
            var familyName = claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.FamilyName)?.Value;
            var result     = new UserRolesDTO
            {
                UserName = entity.UserName,
                Name     = $"{familyName}{givenName}",
                Email    = entity.Email,
                Groups   = new List <GroupRoleDTO>()
            };
            var roles = await _dbContext.Roles.ToListAsync();

            var dict = await _dbContext.UserRoles.Where(x => x.UserId == userId)
                       .ToDictionaryAsync(x => x.RoleId, x => x);

            var groups = roles.GroupBy(x => x.Type);

            foreach (var group in groups)
            {
                var dto = new GroupRoleDTO {
                    Roles = new List <GrantRoleDTO>(), Type = group.Key
                };
                foreach (var permission in group)
                {
                    dto.Roles.Add(new GrantRoleDTO
                    {
                        Name = permission.Name, Id = permission.Id, InRole = dict.ContainsKey(permission.Id)
                    });
                }

                result.Groups.Add(dto);
            }

            return(result);
        }
Esempio n. 6
0
        public async Task <int> Save(GroupRoleDTO _dto, Guid Id, int EntityState)
        {
            try
            {
                GroupMaster groupMaster = new GroupMaster();
                if (_dto != null)
                {
                    groupMaster.Id         = Id;
                    groupMaster.Name       = _dto.GroupName;
                    groupMaster.StatusCode = EMPConstants.Active;
                }

                if (EntityState == (int)System.Data.Entity.EntityState.Modified)
                {
                    var ExistGroup = db.GroupMasters.Where(o => o.Id != Id && o.Name == _dto.GroupName).Any();
                    if (ExistGroup)
                    {
                        return(-1);
                    }

                    groupMaster.LastUpdatedBy   = _dto.UserId;
                    groupMaster.LastUpdatedDate = DateTime.Now;
                    db.Entry(groupMaster).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    var ExistGroup = db.GroupMasters.Where(o => o.Name == _dto.GroupName).Any();
                    if (ExistGroup)
                    {
                        return(-1);
                    }

                    groupMaster.CreatedBy       = _dto.UserId;
                    groupMaster.CreatedDate     = DateTime.Now;
                    groupMaster.LastUpdatedBy   = _dto.UserId;
                    groupMaster.LastUpdatedDate = DateTime.Now;
                    db.GroupMasters.Add(groupMaster);
                }

                if (_dto.Roles.ToList().Count > 0)
                {
                    if (EntityState == (int)System.Data.Entity.EntityState.Modified)
                    {
                        var GroupRoleMapDel = db.GroupRoleMaps.Where(o => o.GroupId == Id).DefaultIfEmpty();
                        if (GroupRoleMapDel != null)
                        {
                            db.GroupRoleMaps.RemoveRange(GroupRoleMapDel);
                        }
                    }

                    List <GroupRoleMap> _GroupRoleMapList = new List <GroupRoleMap>();
                    foreach (RoleDTO item in _dto.Roles)
                    {
                        GroupRoleMap _GroupRoleMap = new GroupRoleMap();
                        _GroupRoleMap.Id      = Guid.NewGuid();
                        _GroupRoleMap.GroupId = groupMaster.Id;
                        _GroupRoleMap.RoleId  = item.Id;
                        _GroupRoleMapList.Add(_GroupRoleMap);
                    }

                    db.GroupRoleMaps.AddRange(_GroupRoleMapList);
                }

                await db.SaveChangesAsync();

                db.Dispose();

                return(1);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(0);
            }
        }