Added RedirectUsingNamedRoute
[castle.git] / Samples / Castle / PetStore.Model / Product.cs
blobca64d9a881a14dfb64d58bb5dcaa0d16e32145fe
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace PetStore.Model
17 using System;
19 using Castle.ActiveRecord;
20 using NHibernate.Expression;
22 [ActiveRecord]
23 public class Product : ActiveRecordBase
25 private int id;
26 private String name;
27 private String description;
28 private String pictureFile;
29 private decimal price;
30 private Category category;
32 [PrimaryKey]
33 public int Id
35 get { return id; }
36 set { id = value; }
39 [Property]
40 public string Name
42 get { return name; }
43 set { name = value; }
46 [Property]
47 public string Description
49 get { return description; }
50 set { description = value; }
53 [Property]
54 public string PictureFile
56 get { return pictureFile; }
57 set { pictureFile = value; }
60 [Property]
61 public decimal Price
63 get { return price; }
64 set { price = value; }
67 [BelongsTo("category_id")]
68 public Category Category
70 get { return category; }
71 set { category = value; }
74 public static Product Find(int id)
76 return (Product) FindByPrimaryKey( typeof(Product), id );
79 public static Product[] FindAll()
81 return (Product[]) FindAll(
82 typeof(Product), new Order[] { Order.Asc("Name") } );
85 public static Product[] FindByCategory(int category)
87 return (Product[]) FindAll(
88 typeof(Product), new Order[] { Order.Asc("Name") }, Expression.Eq("Category.Id", category) );