Ejemplo n.º 1
0
        public UserProfileViewModel(Guid id)
        {
            using (App_Data.DataLayerEF.maxcriticEntities context = new App_Data.DataLayerEF.maxcriticEntities())
            {
                App_Data.DataLayerEF.UserCritic[] users = (from u in context.UserCritics.AsParallel()
                                                           where u.UserId == id
                                                           select u).ToArray();
                if (users.Length == 1)
                {
                    User = users[0];
                }

                Reviews = Review.GetReviewByUser(UserCritic.GetById(User.UserId))?.Where(rev => rev.CheckedByAdmin == true)?.OrderByDescending(rev => rev.Time)?.ToArray();

                PaginationId = Guid.NewGuid();
            }
        }
Ejemplo n.º 2
0
        public void ChangeRole(Guid id, string role)
        {
            UserCritic userFromMySchema = UserCritic.GetById(id);

            ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationUser        user        = userManager.FindByEmail(userFromMySchema.Email);

            IList <string> roles = userManager.GetRoles(user.Id);

            foreach (var rol in roles)
            {
                userManager.RemoveFromRole(user.Id, rol);
            }
            userManager.AddToRole(user.Id, role);

            UserCritic.Role userRole = (UserCritic.Role)Enum.Parse(typeof(UserCritic.Role), role);

            userFromMySchema.UserRole = userRole;
            userFromMySchema.Save();
        }