public void DeleteEquipment(Domain.Equipment equipment)
        {
            var temp = fakeEquipment.ToList();

            temp.RemoveAll(row => row.EquipmentId == equipment.EquipmentId);
            fakeEquipment = temp;
        }
Exemplo n.º 2
0
 public void DeleteEquipment(Domain.Equipment equipment)
 {
     using (Npgsql.NpgsqlConnection conn = new Npgsql.NpgsqlConnection(Infrastructure.ConfigReader.ConnectionString.ToString()))
     {
         conn.Open();
         using (Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand(EquipmentDeleteQuery, conn))
         {
             command.Parameters.Add(new Npgsql.NpgsqlParameter("equipmentid", NpgsqlTypes.NpgsqlDbType.Integer));
             command.Prepare();
             command.Parameters[0].Value = equipment.EquipmentId;
             int rowsAffected = command.ExecuteNonQuery();
         }
     }
 }
Exemplo n.º 3
0
        public void SaveEquipment(Domain.Equipment equipment)
        {
            string query;
            bool   isUpdate = false;

            // Want to know right off the bat if we're doing a insert or update
            if (equipment.EquipmentId > 0)
            {
                query    = EquipmentUpdateQuery;
                isUpdate = true;
            }
            else
            {
                query = EquipmentInsertQuery;
            }

            using (Npgsql.NpgsqlConnection conn = new Npgsql.NpgsqlConnection(Infrastructure.ConfigReader.ConnectionString.ToString()))
            {
                conn.Open();
                using (Npgsql.NpgsqlCommand command = new Npgsql.NpgsqlCommand(query, conn))
                {
                    command.Parameters.Add(new Npgsql.NpgsqlParameter("name", NpgsqlTypes.NpgsqlDbType.Text));
                    command.Parameters.Add(new Npgsql.NpgsqlParameter("type", NpgsqlTypes.NpgsqlDbType.Text));
                    command.Parameters.Add(new Npgsql.NpgsqlParameter("active", NpgsqlTypes.NpgsqlDbType.Boolean));

                    if (isUpdate)
                    {
                        command.Parameters.Add(new Npgsql.NpgsqlParameter("equipmentid", NpgsqlTypes.NpgsqlDbType.Integer));
                    }

                    command.Prepare();

                    command.Parameters[0].Value = equipment.Name;
                    command.Parameters[1].Value = equipment.Type;
                    command.Parameters[2].Value = equipment.Active;

                    if (isUpdate)
                    {
                        command.Parameters[3].Value = equipment.EquipmentId;
                    }

                    int rowsAffected = command.ExecuteNonQuery();
                }
            }
        }
            public async Task <Result> Handle(Command command)
            {
                var equipment = new Domain.Equipment()
                {
                    Name         = command.Name,
                    DefaultPower = command.DefaultPower
                };

                await db.Equipament.AddAsync(equipment);

                await db.SaveChangesAsync();

                return(new Result()
                {
                    Id = equipment.Id,
                    Name = equipment.Name,
                    DefaultPower = equipment.DefaultPower
                });
            }