예제 #1
0
        /// <summary>  
        ///   
        /// </summary>  
        /// <param name="username"></param>  
        /// <returns></returns>  
        public override string[] GetRolesForUser(string username)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return null;
            }

            ServicesConnections.AccessWcfService service = new ServicesConnections.AccessWcfService("GetUserByName", "GET", username);
            string json = service.GetJsonFromService();
            UserContract user = Newtonsoft.Json.JsonConvert.DeserializeObject<UserContract>(json);

            string[] userRoles = null;

            if (user.Username != null && user.Rank == "admin" )
            {
                userRoles = new string[2];
                userRoles[0] = "User";
                userRoles[1] = "Admin";
            }
            else if (user.Username != null && user.Rank == "user")
            {
                userRoles = new string[1];
                userRoles[0] = "User";
            }

            return userRoles;

            /*using (ServiceReference.MusicServiceClient client = new ServiceReference.MusicServiceClient())
            {
                var user = client.GetUserByName(username);
                string[] userRoles = null;

                if (user.Username != null && user.Rank == "admin")
                {
                    userRoles = new string[2];
                    userRoles[0] = "User";
                    userRoles[1] = "Admin";
                }
                else if (user.Username != null && user.Rank == "user")
                {
                    userRoles = new string[1];
                    userRoles[0] = "User";
                }

                return userRoles;
            }*/

        }
예제 #2
0
        private RatingModel[] GetRatings()
        {
            try
            {
                ServicesConnections.AccessWcfService service = new ServicesConnections.AccessWcfService("GetRatings", "GET");
                var jsonData           = service.GetJsonFromService();
                RatingContract[] array = Newtonsoft.Json.JsonConvert.DeserializeObject <RatingContract[]>(jsonData);

                var dictionary = new Dictionary <int, RatingModel>();

                foreach (var a in array)
                {
                    if (dictionary.ContainsKey(a.IdAlbum))
                    {
                        dictionary[a.IdAlbum].Add(a.Rating);
                    }
                    else
                    {
                        dictionary.Add(a.IdAlbum, new RatingModel
                        {
                            ArtisName = a.ArtistName, AlbumName = a.AlbumName, Rating = (int)a.Rating
                        });
                    }
                }

                RatingModel[] output = new RatingModel[dictionary.Count];

                int i = 0;
                foreach (KeyValuePair <int, RatingModel> entry in dictionary)
                {
                    output[i] = entry.Value;
                    i++;
                }

                return(output);
            }
            catch (Exception e)
            {
                return(null);
            }
        }