Beispiel #1
0
        // GET: /Users/Edit/1
        //Edit the information abpout a user including the role
        public async Task <ActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ApplicationUser user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            System.Collections.Generic.IList <string> userRoles = await UserManager.GetRolesAsync(user.Id);

            return(View(new EditUserViewModel()
            {
                Id = user.Id,
                Email = user.Email,
                RolesList = RoleManager.Roles.ToList().Select(x => new SelectListItem()
                {
                    Selected = userRoles.Contains(x.Name),
                    Text = x.Name,
                    Value = x.Name
                })
            }));
        }
Beispiel #2
0
        /// <summary>
        /// Adds an item to an <see cref="System.Collections.Generic.IList{T}"/> if it isn't already present.
        /// </summary>
        /// <typeparam name="T">
        /// The type of object to add.
        /// </typeparam>
        /// <param name="list">
        /// The list to add the item to.
        /// </param>
        /// <param name="item">
        /// The item to add to the collection.
        /// </param>
        public static void UniqueAdd <T>(this System.Collections.Generic.IList <T> list, T item)
        {
            if (list == null)
            {
                throw new System.ArgumentNullException(nameof(list));
            }

            if (!list.Contains(item))
            {
                list.Add(item);
            }
        }
 public virtual void SetCurrentSession(Net.Vpc.Upa.Session session) /* throws Net.Vpc.Upa.Exceptions.UPAException */
 {
     lock (sessions) {
         if (!sessions.Contains(session))
         {
             throw new System.Exception("Session not found");
         }
     }
     CheckManagedSession(session);
     log.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 60, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Session Changed {0} for PersistenceGroup {1}", null, new object[] { session, GetName() }));
     GetSessionContextProvider().SetSession(this, session);
 }
Beispiel #4
0
        public async Task TestAddBook()
        {
            var target   = new BookService(statefulServiceContext, new MockReliableStateManager());
            var expected = new Book {
                BookName = "Azure", ID = Guid.NewGuid(), Price = "34.95", IconName = "Azure"
            };

            //add book
            await target.AddBookAsync(expected);

            //verify book exists
            System.Collections.Generic.IList <Book> books = await target.GetBooksAsync(CancellationToken.None);

            bool resultTrue = books.Contains(expected);

            Assert.IsTrue(resultTrue);
        }
        public bool Init(ApplicationDbContext db, string adminUserEmail, string adminPassword)
        {
            try
            {
                dbInit.InitializeDatabase(db);

                ApplicationUserManager userManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();

                RoleStore <IdentityRole>   roleStore   = new RoleStore <IdentityRole>(db);
                RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(roleStore);

                string name     = adminUserEmail;
                string password = adminPassword;
                string roleName = "Admin";

                //Create Role Admin if it does not exist
                IdentityRole role = roleManager.FindByName(roleName);
                if (role == null)
                {
                    role = new IdentityRole(roleName);
                    IdentityResult roleresult = roleManager.Create(role);
                }

                ApplicationUser user = userManager.FindByName(name);
                if (user == null)
                {
                    user = new ApplicationUser {
                        UserName = name, Email = name
                    };
                    IdentityResult result = userManager.Create(user, password);
                    result = userManager.SetLockoutEnabled(user.Id, false);
                }

                // Add user admin to Role Admin if not already added
                System.Collections.Generic.IList <string> rolesForUser = userManager.GetRoles(user.Id);
                if (!rolesForUser.Contains(role.Name))
                {
                    IdentityResult result = userManager.AddToRole(user.Id, role.Name);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public int EnviarPeticionAmistad(int pe_emisor, int pe_receptor, string pe_asunto, string pe_cuerpo)
        {
            /*PROTECTED REGION ID(NuevoInmueblateGenNHibernate.CEN.RedSocial_Usuario_enviarPeticionAmistad) ENABLED START*/
            /*Codigos de error                          */
            /* 0 --> Existe peticion                    */
            /* -1 --> Ya esta en mi lista de amigos     */
            /* -2 --> Ya esta en mi lista de bloqueados */
            /* n --> Id de la peticion creada           */
            UsuarioCEN         usuCEN = new UsuarioCEN();
            PeticionAmistadCEN petCEN = new PeticionAmistadCEN();
            PeticionAmistadEN  petEN  = petCEN.DamePeticionDePara(pe_emisor, pe_receptor);
            UsuarioEN          emiEN  = usuCEN.DameUsuarioPorOID(pe_emisor);

            System.Collections.Generic.IList <UsuarioEN> l_amigos = usuCEN.ObtenerAmigos(pe_receptor, 0, -1);
            System.Collections.Generic.IList <UsuarioEN> l_bloque = usuCEN.ObtenerBloqueadosSP(pe_receptor);

            if (petEN != null)
            {
                return(0);
            }

            if (l_amigos.Contains(emiEN))
            {
                return(-1);
            }

            if (l_bloque.Contains(emiEN))
            {
                return(-2);
            }

            return(petCEN.CrearPeticionAmistad(pe_asunto, pe_cuerpo, Enumerated.RedSocial.EstadoSolicitudAmistadEnum.pendiente, pe_emisor, pe_receptor));


            /*PROTECTED REGION END*/
        }
Beispiel #7
0
 public bool HasPrivilege(int privilegeCode)
 {
     System.Collections.Generic.IList <int> userPrivileges = RoleHelper.GetUserPrivileges(this.Username);
     return(userPrivileges != null && userPrivileges.Count != 0 && userPrivileges.Contains(privilegeCode));
 }
Beispiel #8
0
 public bool contains(object value)
 {
     return(value is T && _list.Contains((T)value));
 }
        public byte FindRfAddress(System.Collections.Generic.IList <byte> exisitingRfAddresses)
        {
            if (!exisitingRfAddresses.Any())
            {
                return(1);
            }
            var maxExisting = exisitingRfAddresses.Max();
            var holes       = Enumerable.Range(1, maxExisting).Select(i => (byte)i).Where(i => !exisitingRfAddresses.Contains(i)).ToList();

            if (holes.Count >= MaxSupportedConcurrentRequest)
            {
                return(holes [_rnd.Next(holes.Count - 1)]);
            }
            return((byte)(_rnd.Next(maxExisting + 1, Math.Min(maxExisting + 1 + MaxSupportedConcurrentRequest, 250))));
        }
 public virtual bool Contains(ENTITY value)
 {
     return(_selectedList.Contains(value));
 }