public Tag GetTag( int id )
        {
            if (id == null)
                return null;

            // ToDo: Extract
            Tag tag = new Tag();

            List<SqlParameter> procedureParameters = new List<SqlParameter>();
            procedureParameters.Add(new SqlParameter(_tagParamId, id));

            // ToDo: The execute query command should implement the Single Row behavior type
            using (IDataReader reader = _sqlConnection.ExecuteQuery(_fetchByUrlProcedureName, procedureParameters, CommandBehavior.SingleRow))
            {
                while (reader.Read())
                {
                    tag = new Tag
                    {
                        Id = (int)reader[0],
                        Title = (string)reader[1],
                        Description = (string)reader[2],
                        Url = (string)reader[3],
                        Img = (string)reader[4],
                        Coords = new Coordinates { x = (int)reader[5], y = (int)reader[6] },
                        Score = (int)reader[7]
                    };
                }
            }

            return tag;
        }
        public Tag AddTag(Tag tag)
        {
            Tag newTag = null;

            List<SqlParameter> procedureParameters = new List<SqlParameter>();
            procedureParameters.Add(new SqlParameter(_tagParamTitle, tag.Title));
            procedureParameters.Add(new SqlParameter(_tagParamDescription, tag.Description));
            procedureParameters.Add(new SqlParameter(_tagParamUrl, tag.Url));
            procedureParameters.Add(new SqlParameter(_tagParamImage, tag.Img));
            procedureParameters.Add(new SqlParameter(_tagParamScore, tag.Score));
            procedureParameters.Add(new SqlParameter(_tagParamCoordinateX, tag.Coords.x));
            procedureParameters.Add(new SqlParameter(_tagParamCoordinateY, tag.Coords.y));

            // ToDo: The execute query command should implement the Single Row behavior type
            using (IDataReader reader = _sqlConnection.ExecuteQuery(_addTagProcedureName, procedureParameters, CommandBehavior.SingleRow))
            {
                while (reader.Read())
                {
                    newTag = new Tag
                    {
                        Id = (int)reader[0],
                        Title = (string)reader[1],
                        Description = (string)reader[2],
                        Url = (string)reader[3],
                        Img = (string)reader[4],
                        Coords = new Coordinates { x = (int)reader[5], y = (int)reader[6] },
                        Score = (int)reader[7]
                    };
                }
            }

            return newTag;
        }
示例#3
0
 public Tag New(Tag newTag)
 {
     return _dal.AddTag(newTag);
 }