public ActionResult AddToUserRole(string Username, int RoleID) { User user = _userRepository.First(item => item.UsernameLower == Username.ToLower()); if (user != null) { InRole inRole = _inRoleRepository.First(item => item.UserID == user.UserID && item.RoleID == RoleID); if (inRole == null) { _inRoleRepository.Add(new InRole() { UserID = user.UserID, RoleID = RoleID }); SetSuccess(Username + " was added to role"); } else { SetError(Username + " is already in role"); } } else { SetError(Username + " is not a valid username"); } return(RedirectToAction("RoleDetails", new { RoleID = RoleID })); }
public ActionResult RemoveFromRole(int UserID, int RoleID) { InRole inRole = _inRoleRepository.First(item => item.UserID.Equals(UserID) && item.RoleID.Equals(RoleID)); if (inRole.UserID == _currentUser.UserID && inRole.Role.SpecialPermissions == (byte)SpecialPermissionValue.Administrator) { SetError("You can't remove your self from an administrator role"); } else { _inRoleRepository.Delete(inRole); SetSuccess("User removed from role"); } return(RedirectToAction("RoleDetails", new { RoleID = RoleID })); }
public User Register(string username, string password, string email) { string activationType = SiteConfig.AccountActivation.Value; string salt = Randoms.CreateSalt() + DateTime.UtcNow.ToString(); string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password + salt, "MD5"); var user = new User() { Password = hashedPassword, PasswordSalt = salt, RegisterDate = DateTime.UtcNow, RegisterIP = HttpContext.Current.Request.UserHostAddress, ActivationCode = activationType == "None" ? string.Empty : Randoms.CleanGUID(), Status = false, LastLoginIP = null, Username = username, UsernameLower = username.ToLower(), LastLoginDate = DateTime.UtcNow, LastLogoutDate = DateTime.UtcNow, LastPostDate = DateTime.UtcNow, Email = email }; user.UserProfile = new UserProfile() { AlwaysShowSignature = true, AlwaysSubscribeToThread = true, AvatarType = "None", ThemeID = SiteConfig.BoardTheme.ToInt() }; var inRole = new InRole() { UserID = user.UserID, RoleID = SiteConfig.RegistrationRole.IntValue() }; user.InRoles.Add(inRole); _userRepository.Add(user); _unitOfWork.Commit(); return(user); }
public ProductDetails GetProductDetailsById(int id) { var p = GetProductById(id); if (p == null) { return(null); } var pd = new ProductDetails(); pd.Id = p.Id; pd.Name = p.Name; pd.Description = p.Description; List <string> names = null; pd.Rate = p.Rate; pd.AvatarURI = p.AvatarURI; pd.Confirmed = p.Confirmed; if (p.Who != null) { try { pd.UserName = p.Who.FirstName + " " + p.Who.SecondName; } catch { pd.UserName = p.Who.Email; } } List <string> genre = null; List <string> InRole = null; foreach (var meta in p.MetaData) { switch (meta.Type) { case TypeOfMetaProduct.Name: if (names == null) { names = new List <string>(); } names.Add(meta.String); break; case TypeOfMetaProduct.Begin: pd.Begin = meta.Date; break; case TypeOfMetaProduct.End: pd.End = meta.Date; break; case TypeOfMetaProduct.Ended: pd.Ended = meta.Bool; break; case TypeOfMetaProduct.NumberOfEpisode: pd.NumOfEpisode = meta.Int; break; case TypeOfMetaProduct.PosterFromURI: pd.PosterFromURI = meta.String; break; case TypeOfMetaProduct.FromURI: pd.FromURI = meta.String; break; case TypeOfMetaProduct.Country: pd.Country = meta.String; break; case TypeOfMetaProduct.Genre: if (genre == null) { genre = new List <string>(); } genre.Add(meta.String); break; case TypeOfMetaProduct.Type: pd.Type = meta.String; break; case TypeOfMetaProduct.View: pd.View = meta.String; break; case TypeOfMetaProduct.Director: pd.Director = meta.String; break; case TypeOfMetaProduct.Author: pd.Author = meta.String; break; case TypeOfMetaProduct.InRole: if (InRole == null) { InRole = new List <string>(); } InRole.Add(meta.String); break; } } pd.Names = names; pd.Genre = genre; pd.InRole = InRole; return(pd); }