Click here to Skip to main content
15,885,546 members
Articles / Web Development / HTML

Signum Framework Tutorials Part 1 – Southwind Entities

Rate me:
Please Sign up or sign in to vote.
4.50/5 (12 votes)
14 Nov 2012LGPL315 min read 41.3K   2K   52  
Tutorial focused in writing the entities using Signum Framework, a Win/Web LINQ-enabled framework for writing data-centric applications.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Entities;
using Signum.Utilities;
using System.Reflection;
using Signum.Web.Properties;

namespace Signum.Web
{
    [Serializable]
    public class ValueLineBoxModel : ModelEntity
    {
        public ValueLineBoxModel()
        {
        }

        public ValueLineBoxModel(ModifiableEntity relatedEntity, ValueLineBoxType boxType, string fieldName, string topText)
        {
            related = relatedEntity;
            this.boxType = boxType;
            this.fieldName = fieldName;
            this.topText = topText;
        }

        ModifiableEntity related;
        [NotNullValidator]
        public ModifiableEntity Related
        {
            get { return related; }
            set { Set(ref related, value, () => Related); }
        }

        string topText;
        public string TopText
        {
            get { return topText; }
            set { Set(ref topText, value, () => TopText); }
        }

        string fieldName;
        public string FieldName
        {
            get { return fieldName; }
            set { Set(ref fieldName, value, () => FieldName); }
        }

        ValueLineBoxType boxType;
        public ValueLineBoxType BoxType
        {
            get { return boxType; }
            set { Set(ref boxType, value, () => BoxType); }
        }

        int? intValue;
        public int? IntValue
        {
            get { return intValue; }
            set { Set(ref intValue, value, () => IntValue); }
        }

        decimal? decimalValue;
        public decimal? DecimalValue
        {
            get { return decimalValue; }
            set { Set(ref decimalValue, value, () => DecimalValue); }
        }

        bool? boolValue;
        public bool? BoolValue
        {
            get { return boolValue; }
            set { Set(ref boolValue, value, () => BoolValue); }
        }

        string stringValue;
        public string StringValue
        {
            get { return stringValue; }
            set { Set(ref stringValue, value, () => StringValue); }
        }

        DateTime? dateValue;
        public DateTime? DateValue
        {
            get { return dateValue; }
            set { Set(ref dateValue, value, () => DateValue); }
        }

        protected override string PropertyValidation(PropertyInfo pi)
        {
            string error = Resources.ValueMustBeSpecifiedFor0.Formato(fieldName);
            switch (boxType)
            { 
                case ValueLineBoxType.Boolean:
                    if (boolValue == null)
                        return error;
                    break;
                case ValueLineBoxType.Integer:
                    if (intValue == null)
                        return error;
                    break;
                case ValueLineBoxType.Decimal:
                    if (decimalValue == null)
                        return error;
                    break;
                case ValueLineBoxType.DateTime:
                    if (dateValue == null)
                        return error;
                    break;
                case ValueLineBoxType.String:
                    if (stringValue == null)
                        return error;
                    break;
                default:
                    throw new ArgumentException("ValueLineBoxType {0} does not exist".Formato(boxType));
            }
            return null;
        }
    }

    public enum ValueLineBoxType
    { 
        String,
        Boolean,
        Integer,
        Decimal,
        DateTime,
    }
}

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