Exemplo n.º 1
0
        private CharacterRoster CopyCharacter(CharacterRoster characterRoster)
        {
            var newCharacterRoster = new CharacterRoster();

            newCharacterRoster.Id         = characterRoster.Id;
            newCharacterRoster.Name       = characterRoster.Name;
            newCharacterRoster.Race       = characterRoster.Race;
            newCharacterRoster.Profession = characterRoster.Profession;


            return(newCharacterRoster);
        }
Exemplo n.º 2
0
        protected override CharacterRoster UpdateCore(CharacterRoster existing, CharacterRoster characterRoster)
        {
            //Replace
            existing = FindCharacter(characterRoster.Id);
            _characters.Remove(existing);

            var newCharacterRoster = CopyCharacter(characterRoster);

            _characters.Add(newCharacterRoster);

            return(CopyCharacter(newCharacterRoster));
        }
Exemplo n.º 3
0
        protected override CharacterRoster AddCore(CharacterRoster characterRoster)
        {
            var newCharacterRoster = CopyCharacter(characterRoster);

            _characters.Add(newCharacterRoster);

            if (newCharacterRoster.Id <= 0)
            {
                newCharacterRoster.Id = _nextId++;
            }
            else if (newCharacterRoster.Id >= _nextId)
            {
                _nextId = newCharacterRoster.Id + 1;
            }

            return(CopyCharacter(newCharacterRoster));
        }
Exemplo n.º 4
0
        protected override CharacterRoster AddCore(CharacterRoster character)
        {
            //throw new NotImplementedException();
            using (var connection = OpenConnection())
            {
                //Provider-agnostic way to create command
                var command = connection.CreateCommand();
                command.CommandText = "AddProduct";

                //Add parameters
                //   1. Create parameter and add manually
                var parmName = new SqlParameter("@name", character.Name);
                command.Parameters.Add(parmName);
                command.CommandType = CommandType.StoredProcedure;

                //   2. Create parameter using command
                var parmDescription = command.CreateParameter();
                parmDescription.ParameterName = "@description";
                parmDescription.Value         = character.Description;
                parmDescription.SqlDbType     = SqlDbType.NVarChar;
                command.Parameters.Add(parmDescription);

                //   3. (SQL Server) AddWithValue (PREFERRED when SQL)
                command.Parameters.AddWithValue("@price", character.Price);
                command.Parameters.AddWithValue("@isDiscontinued", product.IsDiscontinued);
                // Execute command
                //  ExecuteNonQuery ::= Returns (or don't care about) nothing - DELETE, UPDATE
                //  ExecuteScalar   ::= Returns the first value of the first row, if any - INSERT
                //  ExecuteReader   ::= Returns results (streaming)
                object result = command.ExecuteScalar();
                var    id     = Convert.ToInt32(result);

                //Finish out method
                product.Id = id;
                return(product);
            };
        }
Exemplo n.º 5
0
 protected abstract CharacterRoster AddCore(CharacterRoster product);
Exemplo n.º 6
0
 protected abstract CharacterRoster UpdateCore(CharacterRoster existing, CharacterRoster newItem);
Exemplo n.º 7
0
        public CharacterRoster Update(CharacterRoster characterRoster)
        {
            var existing = GetCore(characterRoster.Id);

            return(UpdateCore(existing, characterRoster));
        }
Exemplo n.º 8
0
 public CharacterRoster Add(CharacterRoster characterRoster)
 {
     return(AddCore(characterRoster));
 }