Exemplo n.º 1
0
        //public async Task<RoleDTO> Create(RoleDTO role)
        //{
        //    RoleMaster roleMaster = new RoleMaster();
        //    roleMaster.Id = Guid.NewGuid();
        //    roleMaster.IsVisible = role.IsVisible;
        //    db.RoleMasters.Add(roleMaster);
        //    await db.SaveChangesAsync();
        //    return role;
        //}

        //public async Task<int> Edit(RoleDTO role)
        //{
        //    RoleMaster rm = new RoleMaster();
        //    rm.Id = role.Id;
        //    rm.IsVisible = role.IsVisible;
        //    rm.Name = role.Name;
        //    db.RoleMasters.Add(rm);
        //    db.Entry(rm).State = EntityState.Modified;
        //    int result = await db.SaveChangesAsync();
        //    return result;
        //}


        public async Task <bool> SaveSitePermission(SiteRolePermissionsDTO _dto)
        {
            try
            {
                GroupMaster groupMaster = new GroupMaster();
                if (_dto != null)
                {
                    if (_dto.SiteRolePermissions.ToList().Count > 0)
                    {
                        var SiteMapRolePermission = db.SiteMapRolePermissions.Where(o => o.RoleId == _dto.RoleId).ToList();
                        if (SiteMapRolePermission.ToList().Count > 0)
                        {
                            db.SiteMapRolePermissions.RemoveRange(SiteMapRolePermission);
                        }

                        List <SiteMapRolePermission> _SiteMapRolePermissionList = new List <SiteMapRolePermission>();
                        foreach (SiteRolePermissionDetailDTO item in _dto.SiteRolePermissions)
                        {
                            SiteMapRolePermission _SiteMapRolePermission = new SiteMapRolePermission();
                            _SiteMapRolePermission.Id           = Guid.NewGuid();
                            _SiteMapRolePermission.RoleId       = _dto.RoleId ?? Guid.Empty;
                            _SiteMapRolePermission.SiteMapId    = item.SiteMapId ?? Guid.Empty;
                            _SiteMapRolePermission.PermissionId = item.PermissionId ?? Guid.Empty;
                            _SiteMapRolePermissionList.Add(_SiteMapRolePermission);
                        }

                        db.SiteMapRolePermissions.AddRange(_SiteMapRolePermissionList);
                    }

                    await db.SaveChangesAsync();

                    db.Dispose();

                    return(true);
                }

                return(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is used to Save the screen permission details
        /// </summary>
        /// <param name="ScreenPermissions"></param>
        /// <param name="RoleID"></param>
        /// <param name="CreatedBy"></param>
        /// <returns></returns>
        public string SaveScreenPermissionDetails(Guid RoleID, Guid CreatedBy, FormCollection fCollection)
        {
            try
            {
                SiteMapRolePermission SiteMapRolePermissionModel;
                using (var DatabaseEntities = new DatabaseEntities())
                {
                    var sitemapRolePermissions = DatabaseEntities.SiteMapRolePermissions.Where(y => y.RoleId == RoleID);
                    foreach (var item in sitemapRolePermissions)
                    {
                        DatabaseEntities.SiteMapRolePermissions.Remove(item);
                    }
                    DatabaseEntities.SaveChanges();

                    foreach (var item in fCollection.Keys)
                    {
                        if (item.ToString() != "hdnRoleID")
                        {
                            if (fCollection[item.ToString()] == "on")
                            {
                                string[] sitemapRolePermission = item.ToString().Split('_');
                                if (sitemapRolePermission != null)
                                {
                                    SiteMapRolePermissionModel = new SiteMapRolePermission();
                                    Guid Id = Guid.NewGuid();
                                    SiteMapRolePermissionModel.Id = Id;
                                    if (sitemapRolePermission.Count() > 0)
                                    {
                                        if (!string.IsNullOrWhiteSpace(sitemapRolePermission[0]))
                                        {
                                            SiteMapRolePermissionModel.SiteMapId = Guid.Parse(sitemapRolePermission[0]);
                                        }
                                    }
                                    if (sitemapRolePermission.Count() > 1)
                                    {
                                        if (!string.IsNullOrWhiteSpace(sitemapRolePermission[1]))
                                        {
                                            SiteMapRolePermissionModel.RoleId = Guid.Parse(sitemapRolePermission[1]);
                                        }
                                    }
                                    if (sitemapRolePermission.Count() > 2)
                                    {
                                        if (!string.IsNullOrWhiteSpace(sitemapRolePermission[2]))
                                        {
                                            SiteMapRolePermissionModel.PermissionId = Guid.Parse(sitemapRolePermission[2]);
                                        }
                                    }
                                    // SiteMapRolePermissionAPI.PutSiteMapRolePermission(Id, SiteMapRolePermissionModel);
                                    DatabaseEntities.SiteMapRolePermissions.Add(SiteMapRolePermissionModel);
                                    DatabaseEntities.SaveChanges();
                                }
                            }
                        }
                    }
                }
                return("Permissions assigned successfully");
            }
            catch (Exception ex)
            {
                // ExceptionTrans.SaveException(ex.ToString(), 1, ex.Message, "SaveScreenPermissionDetails");
                return(ex.Message);
            }
        }