Exemplo n.º 1
0
        public virtual LayoutField UpdateLayoutField(LayoutField entity)
        {
            if (entity.IsTransient())
            {
                return(entity);
            }
            LayoutField other = GetLayoutField(entity.LayoutFieldId);

            if (entity.Equals(other))
            {
                return(entity);
            }
            string sql = @"Update LayoutField set  [LayoutFieldGUID]=@LayoutFieldGUID
							, [LayoutID]=@LayoutID
							, [FieldType]=@FieldType
							, [FieldID]=@FieldID
							, [CreatedOn]=@CreatedOn 
							 where LayoutFieldID=@LayoutFieldID"                            ;

            SqlParameter[] parameterArray = new SqlParameter[] {
                new SqlParameter("@LayoutFieldID", entity.LayoutFieldId)
                , new SqlParameter("@LayoutFieldGUID", entity.LayoutFieldGuid)
                , new SqlParameter("@LayoutID", entity.LayoutId ?? (object)DBNull.Value)
                , new SqlParameter("@FieldType", entity.FieldType ?? (object)DBNull.Value)
                , new SqlParameter("@FieldID", entity.FieldId)
                , new SqlParameter("@CreatedOn", entity.CreatedOn)
            };
            SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray);
            return(GetLayoutField(entity.LayoutFieldId));
        }
Exemplo n.º 2
0
        public virtual LayoutField InsertLayoutField(LayoutField entity)
        {
            LayoutField other = new LayoutField();

            other = entity;
            if (entity.IsTransient())
            {
                string         sql            = @"Insert into LayoutField ( [LayoutFieldGUID]
				,[LayoutID]
				,[FieldType]
				,[FieldID]
				,[CreatedOn] )
				Values
				( @LayoutFieldGUID
				, @LayoutID
				, @FieldType
				, @FieldID
				, @CreatedOn );
				Select scope_identity()"                ;
                SqlParameter[] parameterArray = new SqlParameter[] {
                    new SqlParameter("@LayoutFieldID", entity.LayoutFieldId)
                    , new SqlParameter("@LayoutFieldGUID", entity.LayoutFieldGuid)
                    , new SqlParameter("@LayoutID", entity.LayoutId ?? (object)DBNull.Value)
                    , new SqlParameter("@FieldType", entity.FieldType ?? (object)DBNull.Value)
                    , new SqlParameter("@FieldID", entity.FieldId)
                    , new SqlParameter("@CreatedOn", entity.CreatedOn)
                };
                var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray);
                if (identity == DBNull.Value)
                {
                    throw new DataException("Identity column was null as a result of the insert operation.");
                }
                return(GetLayoutField(Convert.ToInt32(identity)));
            }
            return(entity);
        }