public int SetDataType(DataType entity)
        {
            var result = 0;

             // Load object into context (entity framework)
             var loadedEntity = _dbContext.DataTypes.Where(d => d.FldKey == entity.FldKey).FirstOrDefault();

             // Modify the context
             if (loadedEntity == null)
             { //not found?
            // Add
            this._dbContext.DataTypes.AddObject(entity);
             }
             else
             {
            // Update
            this._dbContext.DataTypes.ApplyCurrentValues(entity);
             }

             // Save in data access (entity framework)
             result = this._dbContext.SaveChanges();

             // 2/25/2012 return entity.Id if add
             //return result;
             return loadedEntity == null ? entity.FldKey : result;
        }
        public static DataType MapViewToEntity(DataTypeView dtv)
        {
            DataType dt = new DataType();

             dt.FldKey = dtv.FldKey;
             dt.FldBigInt = Convert.ToInt64(dtv.FldBigInt);
             dt.FldBit = Boolean.Parse(dtv.FldBit);
             dt.FldChar = dtv.FldChar;
             dt.FldDateTime = Convert.ToDateTime(dtv.FldDateTime);
             dt.FldDecimal = Convert.ToDecimal(dtv.FldDecimal);
             dt.FldInt = Convert.ToInt32(dtv.FldInt);
             dt.FldMoney = Convert.ToDecimal(dtv.FldMoney);
             dt.FldNChar = dtv.FldNChar;
             dt.FldNText = dtv.FldNText;
             dt.FldNumeric = Convert.ToDecimal(dtv.FldNumeric);
             dt.FldNVarChar = dtv.FldNVarChar;
             dt.FldNVarCharMax = dtv.FldNVarCharMax;
             dt.FldSmallDateTime = Convert.ToDateTime(dtv.FldSmallDateTime);
             dt.FldSmallInt = Convert.ToInt16(dtv.FldSmallInt);
             dt.FldSmallMoney = Convert.ToDecimal(dtv.FldSmallMoney);
             dt.FldText = dtv.FldText;
             dt.FldTinyInt = Convert.ToByte(dtv.FldTinyInt);
             dt.FldVarChar = dtv.FldVarChar;
             dt.FldVarCharMax = dtv.FldVarCharMax;

             return dt;
        }
        public static DataTypeView MapEntityToView(DataType dt)
        {
            DataTypeView dtv = new DataTypeView();

             dtv.FldKey = dt.FldKey;
             dtv.FldBigInt = dt.FldBigInt.ToString();
             dtv.FldBit = dt.FldBit.ToString();
             dtv.FldChar = dt.FldChar.Trim();
             dtv.FldDateTime = dt.FldDateTime.ToString();
             dtv.FldDecimal = dt.FldDecimal.ToString();
             dtv.FldInt = dt.FldInt.ToString();
             dtv.FldMoney = dt.FldMoney.ToString();
             dtv.FldNChar = dt.FldNChar.Trim();
             dtv.FldNText = dt.FldNText.Trim();
             dtv.FldNumeric = dt.FldNumeric.ToString();
             dtv.FldNVarChar = dt.FldNVarChar.Trim();
             dtv.FldNVarCharMax = dt.FldNVarCharMax.Trim();
             dtv.FldSmallDateTime = dt.FldSmallDateTime.ToString();
             dtv.FldSmallInt = dt.FldSmallInt.ToString();
             dtv.FldSmallMoney = dt.FldSmallMoney.ToString();
             dtv.FldText = dt.FldText.Trim();
             dtv.FldTinyInt = dt.FldTinyInt.ToString();
             dtv.FldVarChar = dt.FldVarChar.Trim();
             dtv.FldVarCharMax = dt.FldVarCharMax.Trim();

             return dtv;
        }
        public int SaveDataType(string FldKey, DataType addDataType)
        {
            int result = 0;

             DataTypesBusinessEntities.DataTypeView dtv = new DataTypesBusinessEntities.DataTypeView();
             dtv.FldKey = addDataType.FldKey;
             dtv.FldBigInt = addDataType.FldBigInt.Trim();
             dtv.FldBit = addDataType.FldBit.Trim();
             dtv.FldChar = addDataType.FldChar.Trim();
             dtv.FldDateTime = addDataType.FldDateTime.Trim();
             dtv.FldDecimal = addDataType.FldDecimal.Trim();
             dtv.FldInt = addDataType.FldInt.Trim();
             dtv.FldMoney = addDataType.FldMoney.Trim();
             dtv.FldNChar = addDataType.FldNChar.Trim();
             dtv.FldNText = addDataType.FldNText.Trim();
             dtv.FldNumeric = addDataType.FldNumeric.Trim();
             dtv.FldNVarChar = addDataType.FldNVarChar.Trim();
             dtv.FldNVarCharMax = addDataType.FldNVarCharMax.Trim();
             dtv.FldSmallDateTime = addDataType.FldSmallDateTime.Trim();
             dtv.FldSmallInt = addDataType.FldSmallInt.Trim();
             dtv.FldSmallMoney = addDataType.FldSmallMoney.Trim();
             dtv.FldText = addDataType.FldText.Trim();
             dtv.FldTinyInt = addDataType.FldTinyInt.Trim();
             dtv.FldVarChar = addDataType.FldVarChar.Trim();
             dtv.FldVarCharMax = addDataType.FldVarCharMax.Trim();
             result = _dataTypesService.SaveDataType(dtv);

             return result;
        }
 public static DataType GetModel()
 {
     var entity = new DataType();
      return entity;
 }