Exemplo n.º 1
0
        public virtual PollCategory InsertPollCategory(PollCategory entity)
        {
            PollCategory other = new PollCategory();

            other = entity;
            if (entity.IsTransient())
            {
                string         sql            = @"Insert into PollCategory ( [PollID]
				,[CategoryID]
				,[CreatedOn] )
				Values
				( @PollID
				, @CategoryID
				, @CreatedOn );
				Select scope_identity()"                ;
                SqlParameter[] parameterArray = new SqlParameter[] {
                    new SqlParameter("@PollID", entity.PollId)
                    , new SqlParameter("@CategoryID", entity.CategoryId)
                    , 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(GetPollCategory(Convert.ToInt32(identity)));
            }
            return(entity);
        }
Exemplo n.º 2
0
        public virtual PollCategory UpdatePollCategory(PollCategory entity)
        {
            if (entity.IsTransient())
            {
                return(entity);
            }
            PollCategory other = GetPollCategory(entity.PollId);

            if (entity.Equals(other))
            {
                return(entity);
            }
            string sql = @"Update PollCategory set  [CategoryID]=@CategoryID
							, [CreatedOn]=@CreatedOn 
							 where PollID=@PollID"                            ;

            SqlParameter[] parameterArray = new SqlParameter[] {
                new SqlParameter("@PollID", entity.PollId)
                , new SqlParameter("@CategoryID", entity.CategoryId)
                , new SqlParameter("@CreatedOn", entity.CreatedOn)
            };
            SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray);
            return(GetPollCategory(entity.PollId));
        }