Let the source code speak: (This is from a real application not "Demoware")
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using CBSI.GL.Application;
using CBSI.NHibernate.DomainServices;
using CBSI.GL.Domain;
using CBSI.GL.DA;
using CBSI.TAE.Dashboard.RIAServices.Web.Properties;
namespace CBSI.TAE.Dashboard.RIAServices.Web.Services
{
[EnableClientAccess()]
public class AccountCategoryDomainService : GLDomainService<AccountCategoryRepository, AccountCategory, long>
{
IAccountCategoryService _AccountCategoryService;
public AccountCategoryDomainService(IAccountCategoryService accountCategoryService) : base(accountCategoryService.Repository)
{
_AccountCategoryService = accountCategoryService;
}
public IEnumerable<AccountCategoryModel> Categories()
{
return from c in this.Repository.All where (c.GLSetup.ID==this.GLSetup.ID)
orderby c.Name
select new AccountCategoryModel(c);
}
public void Insert(AccountCategoryModel model)
{
if (this.Exists(model.Name))
throw new ApplicationException(string.Format(Resources.AlreadyExistEntityWithName, Resources.Entity_Name_Category, model.Name));
AccountCategory accountCategory = new AccountCategory(this.GLSetup);
accountCategory = model.ToDomain(accountCategory);
SaveTransaction(accountCategory);
this.ChangeSet.Associate(model, accountCategory, MapToModel);
}
public void Update(AccountCategoryModel model)
{
AccountCategory accountCategory = this.Repository.Get(c => c.ID == model.ID);
if (accountCategory==null)
throw new ApplicationException(string.Format(Resources.UpdatingNonExistingEntity, Resources.Entity_Name_Category));
accountCategory = model.ToDomain(accountCategory);
SaveTransaction(accountCategory);
this.ChangeSet.Associate(model, accountCategory, MapToModel);
}
public void Delete(AccountCategoryModel model)
{
AccountCategory accountCategory = this.Repository.Get(c => c.ID == model.ID);
if (accountCategory == null)
throw new ApplicationException(string.Format(Resources.DeletingNonExistingEntity, Resources.Entity_Name_Category));
DeleteTransaction(accountCategory);
}
bool Exists(string name)
{
var ac = this.Repository.Get( c => c.Name == name);
return (ac != null);
}
void MapToModel(AccountCategoryModel acm, AccountCategory ac )
{
acm = new AccountCategoryModel(ac);
}
}
}