protected void btSave_Click(object sender, EventArgs e)
    {
        lblMessage.Text = String.Empty;

        if (String.IsNullOrWhiteSpace(tbDisplayName.Text))
        {
            lblMessage.Text = "Please enter display name";

            mpeAddEdit.Show();
            return;
        }

        if (String.IsNullOrWhiteSpace(tbPair.Text))
        {
            lblMessage.Text = "Please enter pair";

            mpeAddEdit.Show();
            return;
        }

        using (var db = DcFactory.Create <CommonDataDataContext>())
        {
            CD_Language language;

            if (LangID == null)
            {
                language             = new CD_Language();
                language.ID          = Guid.NewGuid();
                language.DateCreated = DateTime.Now;

                db.CD_Languages.InsertOnSubmit(language);
            }
            else
            {
                language = (from n in db.CD_Languages
                            where n.ID == LangID
                            select n).FirstOrDefault();

                if (language == null)
                {
                    return;
                }
            }

            language.DisplayName = tbDisplayName.Text;
            language.EngName     = tbEngName.Text;
            language.NativeName  = tbNativeName.Text;
            language.Pair        = tbPair.Text;

            db.SubmitChanges();

            mpeAddEdit.Hide();
        }

        FillLanguagesGrid();
    }
        public static CD_Language ToEntity(this LanguageContract contract)
        {
            if (contract == null)
            {
                return(null);
            }

            var entity = new CD_Language();

            entity.ID          = contract.ID;
            entity.DisplayName = contract.DisplayName;
            entity.EngName     = contract.EngName;
            entity.NativeName  = contract.NativeName;
            entity.Pair        = contract.Pair;
            entity.DateCreated = contract.DateCreated;
            entity.DateChanged = contract.DateChanged;
            entity.DateDeleted = contract.DateDeleted;

            return(entity);
        }
        public static LanguageContract ToContract(this CD_Language entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var contract = new LanguageContract();

            contract.ID          = entity.ID;
            contract.DisplayName = entity.DisplayName;
            contract.EngName     = entity.EngName;
            contract.NativeName  = entity.NativeName;
            contract.Pair        = entity.Pair;
            contract.DateCreated = entity.DateCreated;
            contract.DateChanged = entity.DateChanged;
            contract.DateDeleted = entity.DateDeleted;

            return(contract);
        }