Click here to Skip to main content
15,892,072 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 2 – Southwind Logic

Rate me:
Please Sign up or sign in to vote.
4.45/5 (6 votes)
15 Nov 2012LGPL325 min read 31.5K   1K   22  
In this part, we will focus on writing business logic, LINQ queries and explain inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Entities;
using System.Linq.Expressions;
using Signum.Utilities;

namespace Southwind.Entities
{
    [Serializable]
    public class ProductDN : Entity
    {
        [NotNullable, SqlDbType(Size = 40), UniqueIndex]
        string productName;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 40)]
        public string ProductName
        {
            get { return productName; }
            set { SetToStr(ref productName, value, () => ProductName); }
        }

        Lite<SupplierDN> supplier;
        [NotNullValidator]
        public Lite<SupplierDN> Supplier
        {
            get { return supplier; }
            set { Set(ref supplier, value, () => Supplier); }
        }

        Lite<CategoryDN> category;
        [NotNullValidator]
        public Lite<CategoryDN> Category
        {
            get { return category; }
            set { Set(ref category, value, () => Category); }
        }

        [NotNullable, SqlDbType(Size = 20)]
        string quantityPerUnit;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 20)]
        public string QuantityPerUnit
        {   
            get { return quantityPerUnit; }
            set { Set(ref quantityPerUnit, value, () => QuantityPerUnit); }
        }

        decimal unitPrice;
        [NumberIsValidator(ComparisonType.GreaterThan, 0)]
        public decimal UnitPrice
        {
            get { return unitPrice; }
            set { Set(ref unitPrice, value, () => UnitPrice); }
        }

        short unitsInStock;
        [NumberIsValidator(ComparisonType.GreaterThan, 0)]
        public short UnitsInStock
        {
            get { return unitsInStock; }
            set { Set(ref unitsInStock, value, () => UnitsInStock); }
        }

        int reorderLevel;
        public int ReorderLevel
        {
            get { return reorderLevel; }
            set { Set(ref reorderLevel, value, () => ReorderLevel); }
        }

        bool discontinued;
        public bool Discontinued
        {
            get { return discontinued; }
            set { Set(ref discontinued, value, () => Discontinued); }
        }

        static Expression<Func<ProductDN, decimal>> ValueInStockExpression =
            p => p.unitPrice * p.unitsInStock;
        public decimal ValueInStock
        {
            get {  return ValueInStockExpression.Invoke(this); }
        }

        public override string ToString()
        {
            return productName;
        }
    }

    [Serializable]
    public class SupplierDN : Entity
    {
        [NotNullable, SqlDbType(Size = 40), UniqueIndex]
        string companyName;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 40)]
        public string CompanyName
        {
            get { return companyName; }
            set { SetToStr(ref companyName, value, () => CompanyName); }
        }

        [SqlDbType(Size = 30)]
        string contactName;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = 30)]
        public string ContactName
        {
            get { return contactName; }
            set { Set(ref contactName, value, () => ContactName); }
        }

        [SqlDbType(Size = 30)]
        string contactTitle;
        [StringLengthValidator(AllowNulls = true, Min = 3, Max = 30)]
        public string ContactTitle
        {
            get { return contactTitle; }
            set { Set(ref contactTitle, value, () => ContactTitle); }
        }

        AddressDN address;
        public AddressDN Address
        {
            get { return address; }
            set { Set(ref address, value, () => Address); }
        }

        [NotNullable, SqlDbType(Size = 24)]
        string phone;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 24), TelephoneValidator]
        public string Phone
        {
            get { return phone; }
            set { Set(ref phone, value, () => Phone); }
        }

        [NotNullable, SqlDbType(Size = 24)]
        string fax;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 24), TelephoneValidator]
        public string Fax
        {
            get { return fax; }
            set { Set(ref fax, value, () => Fax); }
        }

        [NotNullable, SqlDbType(Size = int.MaxValue)]
        string homePage;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = int.MaxValue)]
        public string HomePage
        {
            get { return homePage; }
            set { Set(ref homePage, value, () => HomePage); }
        }

        public override string ToString()
        {
            return companyName;
        }
    }

    [Serializable]
    public class CategoryDN : Entity
    {
        [NotNullable, SqlDbType(Size = 100), UniqueIndex]
        string categoryName;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = 100)]
        public string CategoryName
        {
            get { return categoryName; }
            set { SetToStr(ref categoryName, value, () => CategoryName); }
        }

        [NotNullable, SqlDbType(Size = int.MaxValue)]
        string description;
        [StringLengthValidator(AllowNulls = false, Min = 3, Max = int.MaxValue)]
        public string Description
        {
            get { return description; }
            set { Set(ref description, value, () => Description); }
        }

        byte[] picture;
        public byte[] Picture
        {
            get { return picture; }
            set { Set(ref picture, value, () => Picture); }
        }

        public override string ToString()
        {
            return categoryName;
        }
    }

    public enum ProductQueries
    {
        Current
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) Signum Software
Spain Spain
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.

www.signumframework.com

I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...

Comments and Discussions