/// <summary> /// Return accouts that have a given role /// </summary> /// <param name="role"></param> /// <returns></returns> public static List<AccountViewModel> GetAccounts(Role role) { List<Account> accounts; if (!Account.GetAccounts(out accounts, (int) role)) throw new DataAccessException("Kunde inte komma åt användare"); List<AccountViewModel> models = new List<AccountViewModel>(); foreach (var account in accounts) models.Add(Mapper.Map<AccountViewModel>(account)); return models; }
/// <summary> /// Creates a new <see cref="Role"/> with the given name /// </summary> /// <param name="name">The name of the role</param> /// <returns>An http response</returns> public async Task<HttpResponseMessage> Post(string name) { var role = new Role { Name = name }; var created = await roleRepository.Create(role, _ => Task.FromResult(true)); return created.Match(r => Request.CreateResponse(HttpStatusCode.Created), () => Request.CreateResponse(HttpStatusCode.InternalServerError)); }