using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; using VideoGameQuotes.Api; namespace VideoGameQuotes.Web.Models { public class CreateAdminModel { [DisplayName("Use existing user")] public int UserId { get; set; } public string Username { get; set; } [Required] public string Password { get; set; } public IEnumerable Users { get; set; } public IEnumerable GetUserList() { return new[] { new SelectListItem { Text = "--none--", Value = "0" } } .Concat(Users .Where(user => user.Group != UserGroup.Admin) .OrderBy(user => user.Username) .ThenBy(user => user.IpAddress) .Select(user => new SelectListItem { Text = user.Username ?? user.IpAddress, Value = user.Id.ToString() }) ); } } }