- Service layer for the Roles module.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4039510
This commit is contained in:
suhacan
2009-11-11 01:53:22 +00:00
parent 0fd277ed42
commit 3a951297fa

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Data;
using Orchard.Logging;
using Orchard.Roles.Models;
namespace Orchard.Roles.Services {
public interface IRoleService : IDependency {
IEnumerable<RoleRecord> GetRoles();
RoleRecord GetRole(int id);
void CreateRole(string roleName);
void UpdateRole(int id, string roleName);
void DeleteRole(int id);
}
public class RoleService : IRoleService {
private readonly IRepository<RoleRecord> _roleRepository;
public RoleService(IRepository<RoleRecord> roleRepository) {
_roleRepository = roleRepository;
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
#region Implementation of IRoleService
public IEnumerable<RoleRecord> GetRoles() {
var roles = from role in _roleRepository.Table select role;
return roles.ToList();
}
public RoleRecord GetRole(int id) {
return _roleRepository.Get(id);
}
public void CreateRole(string roleName) {
_roleRepository.Create(new RoleRecord { Name = roleName });
}
public void UpdateRole(int id, string roleName) {
_roleRepository.Update(new RoleRecord { Id = id, Name = roleName });
}
public void DeleteRole(int id) {
_roleRepository.Delete(new RoleRecord { Id = id });
}
#endregion
}
}